Skip to content
Snippets Groups Projects
Commit e1c17bc6 authored by jamie's avatar jamie
Browse files

feedMicroservice returns the feed sorted by date

Chanegd all_ratings function from musicMicroservice to now return
updated_at time, which is used by feedMicroservice to sort feed by date
parent 2df291d4
No related branches found
No related tags found
2 merge requests!23Merging current work on feedMicroservice,!22feedMicroservice now producing list of ratings
......@@ -27,7 +27,7 @@ def getFeed():
for i in range (len(followings)):
followingsID.append(followings[i]['userID'])
ratingsFeed = [] # array containing an array for each person you follow which contains an array with song info, rating,
ratingsFeed = [] # array containing an array for each person you follow which contains an array with song info, rating, datetime for rating,
# user who rated for every song they have rated
for i in range (len(followingsID)):
......@@ -40,10 +40,11 @@ def getFeed():
for j in range (len(followerRatings)):
song = (requests.get(f'http://localhost:5050/search_id/{followerRatings[j][0]}')).json()
song.append(followerRatings[j][1])
song.append(followerRatings[j][2])
song.append(name)
ratingsFeed.append(song)
return ratingsFeed
sortedFeed = sorted(ratingsFeed, key=lambda x: x[2], reverse=True)
return sortedFeed
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5051)
\ No newline at end of file
No preview for this file type
......@@ -120,7 +120,7 @@ def all_ratings():
userID = request.args.get('userID')
conn = sqlite3.connect('best_listens.db')
cursor = conn.cursor()
cursor.execute("SELECT track_id, rating FROM ratings WHERE user_id=? ", (userID))
cursor.execute("SELECT track_id, rating, updated_at FROM ratings WHERE user_id=? ", (userID))
ratings = cursor.fetchall()
conn.close()
return ratings
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment