Add endpoint for get_top_N
This commit is contained in:
parent
5e9098f1e9
commit
0f35b91e8e
2 changed files with 16 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
# API endpoints:
|
# API endpoints:
|
||||||
|
|
||||||
| Endpoint | Return |
|
| Endpoint | Return |
|
||||||
| ------------------------ | ----------------------- |
|
| ------------------------ | ------------------------------ |
|
||||||
| `/mocha/users/{user_id}` | row with the given user |
|
| `/mocha/users/{user_id}` | row with the given user |
|
||||||
| `/mocha/users/*` | all rows |
|
| `/mocha/users/*` | all rows |
|
||||||
|
| `/mocha/top/{n}` | user with the n highest scores |
|
||||||
|
|
|
@ -104,6 +104,15 @@ def fetch_user(user_id):
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_top_n(n):
|
||||||
|
output = get_top_N('score', True, n)
|
||||||
|
|
||||||
|
if output == '[]':
|
||||||
|
output = None
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
def process_request(uri):
|
def process_request(uri):
|
||||||
"""
|
"""
|
||||||
Handles the API endpoint.
|
Handles the API endpoint.
|
||||||
|
@ -118,6 +127,8 @@ def process_request(uri):
|
||||||
|
|
||||||
if parts[1] == 'users':
|
if parts[1] == 'users':
|
||||||
output = fetch_user(parts[2])
|
output = fetch_user(parts[2])
|
||||||
|
elif parts[1] == 'top':
|
||||||
|
output = fetch_top_n(parts[2])
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
Reference in a new issue