Better api and README
This commit is contained in:
parent
0ce0da78d2
commit
bafda3862d
4 changed files with 56 additions and 9 deletions
42
README.md
42
README.md
|
@ -2,16 +2,16 @@
|
|||
|
||||
Zoals besproken op de eerste bestuursvergadering.
|
||||
|
||||
! Work in progress, dingen zijn nog shit en moeten nog gefixed worden, beware
|
||||
! Beware: ux is nog verschrikkelijk lelijk, functioneel werkt het wel
|
||||
|
||||
## Endpoints
|
||||
|
||||
### Geen authenticatie
|
||||
|
||||
- `/users`: Alle users en hun achievements, volledig
|
||||
- `/users/<username>`: Alle data over de user `username`
|
||||
- `/users`: Overzicht van alle users (default)
|
||||
- `/users/<username>`: Achievements van de user `username`
|
||||
- `/login` en `/logout`: Laat de user aan- en afmelden
|
||||
- `/achievement/<id>`: Alle data over die specifieke achievement
|
||||
- `/achievement/<id>`: Een specifieke achievement
|
||||
|
||||
### Enkel bereikbaar na aanmelden
|
||||
|
||||
|
@ -37,4 +37,36 @@ Zoals besproken op de eerste bestuursvergadering.
|
|||
|
||||
### Endorses
|
||||
|
||||
Relatie tussen `User` en `Achievement`
|
||||
Relatie tussen `User` en `Achievement`
|
||||
|
||||
## API
|
||||
|
||||
### /api/users
|
||||
|
||||
Returnt een lijst van strings (usernames)
|
||||
|
||||
### /api/achievements
|
||||
|
||||
Return een lijst van Achievement-objecten
|
||||
|
||||
Achievement-object:
|
||||
```JSON
|
||||
{
|
||||
id: number -> Unieke id
|
||||
name: String -> Naam van het achievement
|
||||
endorsed_by: [String] -> Lijst van User-ids die deze achievement endorsen
|
||||
achieved_by: String -> User-id van de persoon die dit achievement gehaald heeft
|
||||
}
|
||||
```
|
||||
|
||||
### /api/all
|
||||
|
||||
Returnt een lijst van User-objecten
|
||||
|
||||
User-object
|
||||
```JSON
|
||||
{
|
||||
id: String -> Username
|
||||
achievement: [Achievement] -> Lijst met achievements van deze persoon
|
||||
}
|
||||
```
|
||||
|
|
17
api.py
Normal file
17
api.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from app import app, db
|
||||
from models import User, Achievement
|
||||
|
||||
import json
|
||||
|
||||
@app.route("/api")
|
||||
@app.route("/api/all")
|
||||
def api_all():
|
||||
return json.dumps([user.to_obj() for user in User.query.all()])
|
||||
|
||||
@app.route("/api/users")
|
||||
def api_all_users():
|
||||
return json.dumps([user.id for user in User.query.all()])
|
||||
|
||||
@app.route("/api/achievements")
|
||||
def api_all_achievements():
|
||||
return json.dumps([achievement.to_obj() for achievement in Achievement.query.all()])
|
|
@ -3,4 +3,5 @@ from models import User, Achievement
|
|||
|
||||
from login import *
|
||||
from user import *
|
||||
from achievements import *
|
||||
from achievements import *
|
||||
from api import *
|
||||
|
|
3
user.py
3
user.py
|
@ -36,6 +36,3 @@ def get_user(id):
|
|||
def all_users():
|
||||
return render_template("allusers.html", data=[user.to_obj() for user in User.query.all()])
|
||||
|
||||
@app.route("/all")
|
||||
def all_users_json():
|
||||
return json.dumps([user.to_obj() for user in User.query.all()])
|
||||
|
|
Loading…
Reference in a new issue