Add endpoint for get_top_N

This commit is contained in:
Corder Guy 2018-04-17 14:24:04 -05:00
parent 5e9098f1e9
commit 0f35b91e8e
2 changed files with 16 additions and 4 deletions

View file

@ -1,6 +1,7 @@
# API endpoints:
| Endpoint | Return |
| ------------------------ | ----------------------- |
| ------------------------ | ------------------------------ |
| `/mocha/users/{user_id}` | row with the given user |
| `/mocha/users/*` | all rows |
| `/mocha/top/{n}` | user with the n highest scores |

View file

@ -104,6 +104,15 @@ def fetch_user(user_id):
return output
def fetch_top_n(n):
output = get_top_N('score', True, n)
if output == '[]':
output = None
return output
def process_request(uri):
"""
Handles the API endpoint.
@ -118,6 +127,8 @@ def process_request(uri):
if parts[1] == 'users':
output = fetch_user(parts[2])
elif parts[1] == 'top':
output = fetch_top_n(parts[2])
return output