Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracks #114

Merged
merged 69 commits into from
May 15, 2017
Merged
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
49a752c
Add missing track attributes
aibarbetta May 3, 2017
fcbb2ef
Complete track schema
aibarbetta May 3, 2017
826fade
Add track endpoint
aibarbetta May 3, 2017
7e1888b
Update tests
aibarbetta May 3, 2017
c8e7e37
Format get tracks and add track responses
aibarbetta May 3, 2017
b54b0cd
Add endpoints to get and delete a track
aibarbetta May 3, 2017
9946478
Update track endpoint
aibarbetta May 3, 2017
772b74a
Update routes index
aibarbetta May 3, 2017
52b92e0
Track creation tests
aibarbetta May 3, 2017
2650387
Track deletion tests
aibarbetta May 3, 2017
7b32edc
Track fetch tests
aibarbetta May 3, 2017
bca41a4
Track update tests (2 test failing due to empty implementation)
aibarbetta May 3, 2017
a80a39b
xtreme pair programming
aibarbetta May 4, 2017
2a0885c
Track like and dislike
aibarbetta May 4, 2017
eca6b99
Get track popularity endpoint
aibarbetta May 4, 2017
35da267
Half of track rating
aibarbetta May 4, 2017
78e0840
Typo
aibarbetta May 5, 2017
d086916
Merge branch 'develop' of https://github.com/tallerify/shared-server …
aibarbetta May 5, 2017
58e810a
Add track like endpoint tests
aibarbetta May 9, 2017
39f2894
Add track dislike endpoint tests
aibarbetta May 9, 2017
7b743e9
Move jwt payload to constants json
aibarbetta May 9, 2017
c45002e
Add test for dislike on non liked track with 204 return code
aibarbetta May 9, 2017
3f6afd9
Add tests for track popularity fetch
aibarbetta May 9, 2017
64fa455
Change popularity attribute to rating and add votes to save how many …
aibarbetta May 9, 2017
3692675
Changed my mind, add new table for track ratings (link every rating w…
aibarbetta May 9, 2017
1330c05
Complete track rate endpoint
aibarbetta May 9, 2017
df727df
Add tests for track rate
aibarbetta May 9, 2017
92e1b22
Add test with non cero rating query
aibarbetta May 9, 2017
b737db3
The start of user track faves :sleeping:
aibarbetta May 9, 2017
e14fec3
Complete user track faves fetch
aibarbetta May 10, 2017
2ee1a00
Cleanup
aibarbetta May 10, 2017
d539df1
Add new select function
miporto May 10, 2017
5db3125
Add findAllWithAttributes selector
miporto May 10, 2017
be462b6
Add getTrackInfo selector
miporto May 10, 2017
ea2f835
Tests for user track faves endpoint
aibarbetta May 10, 2017
3fa3ff5
Add artist information to get track by id
miporto May 10, 2017
0f20519
Test existence of artists key in response object
miporto May 10, 2017
17ecf51
Don't repeat like entry when like request is duplicated
aibarbetta May 10, 2017
2d93d69
findEntryWithId now returns only one entry
miporto May 10, 2017
904396e
Refactor in get track endpoint
miporto May 10, 2017
50d0976
Merge pull request #110 from tallerify/SS-108
miporto May 10, 2017
d7ea525
Add artist information to GET track endpoint (#112)
miporto May 10, 2017
957f9a5
Delete unused function
aibarbetta May 12, 2017
fb41592
Delete debug comments
aibarbetta May 12, 2017
bfac0f6
Add entry and table info to logging message
miporto May 12, 2017
4356f7f
Add ids to test artists
miporto May 12, 2017
44c5bbc
Add ids to tests tracks and use valid artists ids
miporto May 12, 2017
231e873
Move db functions to handler
aibarbetta May 12, 2017
f99eb32
Add real artists before adding a track
miporto May 12, 2017
1f1c1b0
Check req body key: tracks length in get
miporto May 12, 2017
5b7be04
Add artists short body
miporto May 12, 2017
f7a7998
Test existence of artists in get track by id
miporto May 12, 2017
0c04bc1
Use findWithUsernameAndPassword
aibarbetta May 12, 2017
072109a
Change Album and Artists response formatters
miporto May 12, 2017
999c42f
Typo
miporto May 12, 2017
c202c29
Check that artists exist before creating the track
miporto May 12, 2017
be221b6
Set logging of tables creation to debug
miporto May 12, 2017
1d33461
Unify response formatter of track endpoint.
miporto May 12, 2017
b1c03b3
Use valid artists ids in test.
miporto May 12, 2017
8970fbd
Ensure artist are created before tracks
miporto May 12, 2017
1466f34
Add return to promise inside promise's then
miporto May 12, 2017
de60743
Only map artists if they exist.
miporto May 12, 2017
eaae7dd
Fix indentation
miporto May 12, 2017
c208f40
Create valid test artists before creating test track
miporto May 12, 2017
16aeaac
Separate artist and album find functions to run them in parallel
miporto May 12, 2017
688548b
Merge pull request #120 from tallerify/SS-113
aibarbetta May 15, 2017
7209fbc
Add error module and NonExistentIdError
aibarbetta May 15, 2017
13deef8
Add specific response for non existent artist id on track creation
aibarbetta May 15, 2017
e7671d5
Add test for track creation with non existent artist id
aibarbetta May 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Complete user track faves fetch
aibarbetta committed May 10, 2017
commit e14fec32b76ec5c762af0cc661abe9f97609d482
14 changes: 10 additions & 4 deletions src/handlers/db/trackHandler.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ const createNewTrackEntry = (body) => {
};

const updateTrackEntry = (body, id) => {
logger.info(`Updating track ${id}`);
let track = {
name: body.name,
albumId: body.albumId,
@@ -33,42 +34,47 @@ const updateTrackEntry = (body, id) => {
};

const like = (userId, trackId) => {
logger.info(`User ${userId} liking track ${trackId}`);
return generalHandler.createNewEntry(tables.users_tracks, {
user_id: userId,
track_id: trackId,
});
};

const dislike = (userId, trackId) => {
logger.info(`User ${userId} disliking track ${trackId}`);
return db(tables.users_tracks).where({
user_id: userId,
track_id: trackId,
}).del();
};

const findUserFavorites = (userId) => {
logger.info('Searching for track favorites');
return db(tables.users_tracks).select('track_id').where({
user_id: userId,
})
.then((tracks) => {
db(tables.users_tracks).where({
id: tracks.map(track => track.track_id), // FIXME check if it works with arrays ¿?¿?¿
});
const track_ids = tracks.map(track => track.track_id);
logger.info(`Liked track ids for user ${userId}: ${JSON.stringify(track_ids, null, 4)}`);
return db(tables.tracks).whereIn('id', track_ids);
});
};

const calculateRate = (trackId) => {
logger.info(`Calculating rating for track ${trackId}`);
return db(tables.tracks_rating).select('rating').where({
track_id: trackId,
})
.then((ratings) => {
logger.info(`Ratings for track ${trackId}: ${JSON.stringify(ratings, null, 4)}`);
if (!ratings.length) return 0;
return math.mean(ratings.map((rating) => rating.rating));
return math.mean(ratings.map(rating => rating.rating));
});
};

const rate = (trackId, userId, rating) => {
logger.info(`User ${userId} rating track ${trackId} with rate: ${rating}`);
return db(tables.tracks_rating).where({
user_id: userId,
track_id: trackId,