Skip to content
Snippets Groups Projects
Commit 8ac22a69 authored by ale's avatar ale
Browse files

add method and API to retrieve last uploaded songs

parent a20f1d85
No related branches found
No related tags found
No related merge requests found
...@@ -151,7 +151,16 @@ def more_like_these_json(): ...@@ -151,7 +151,16 @@ def more_like_these_json():
@app.route('/json/most_played', methods=['GET']) @app.route('/json/most_played', methods=['GET'])
@require_auth @require_auth
def most_played_json(): def most_played_json():
n = int(request.args.get('n', 20))
most_played = [{'sha1': sha1, 'count': count} most_played = [{'sha1': sha1, 'count': count}
for sha1, count in PlayLog.most_played(20)] for sha1, count in PlayLog.most_played(n)]
return jsonify(results=most_played) return jsonify(results=most_played)
@app.route('/json/last_uploaded', methods=['GET'])
@require_auth
def last_uploaded_json():
n = int(request.args.get('n', 20))
last_uploaded = [x.to_dict() for x in MP3.last_uploaded(n)]
return jsonify(results=last_uploaded)
...@@ -36,6 +36,11 @@ class MP3(Base): ...@@ -36,6 +36,11 @@ class MP3(Base):
'size': self.size, 'size': self.size,
'uploaded_at': self.uploaded_at} 'uploaded_at': self.uploaded_at}
@classmethod
def last_uploaded(cls, n=10):
"""Return the N last uploaded songs."""
return cls.query.filter_by(ready=True).order_by('desc uploaded_at').limit(n)
class PlayLog(Base): class PlayLog(Base):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment