From 79711f1423c7f5b59ea81e3fc5c64717950595d2 Mon Sep 17 00:00:00 2001 From: Robbe Van Herck Date: Fri, 13 Jul 2018 10:58:30 +0200 Subject: [PATCH] Added Endpoints and DB model to README.md --- README.md | 37 ++++++++++++++++++++++++++++++++++++- models.py | 3 ++- user.py | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b04132f..b86a5b2 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,39 @@ Zoals besproken op de eerste bestuursvergadering. -! Work in progress, dingen zijn nog shit en moeten nog gefixed worden, beware \ No newline at end of file +! Work in progress, dingen zijn nog shit en moeten nog gefixed worden, beware + +## Endpoints + +### Geen authenticatie + +- `/users`: Alle users en hun achievements, volledig +- `/users/`: Alle data over de user `username` +- `/login` en `/logout`: Laat de user aan- en afmelden +- `/achievement/`: Alle data over die specifieke achievement + +### Enkel bereikbaar na aanmelden + +- `/users//addachievement?name=XYZ`: Maakt een nieuw achievement aan bij `username` met naam `XYZ` en laat de ingelogde persoon endorsen +- `/achievement//endorse`: Voegt de ingelogde persoon toe aan `endorsed_by` van achievement `id` +- `/achievement//unendorse`: Verwijdert de ingelogde persoon van `endorsed_by` van achievement `id` + +## DB model + +### User + +| name | type | nullable | uniek | beschrijving | +|--------|------------|----------|-------|--------------| +| **id** | String(80) | False | True | de username | + +### Achievement + +| name | type | nullable | uniek | beschrijving | +|-------------|---------------|----------|-------|----------------------------------| +| **id** | Integer | False | True | unieke id | +| name | String(128) | False | False | beschrijving van de achievement | +| achieved_by | FK -> user.id | False | False | wie de achievement gehaald heeft | + +### Endorses + +Relatie tussen `User` en `Achievement` \ No newline at end of file diff --git a/models.py b/models.py index bfd7ead..c11d736 100644 --- a/models.py +++ b/models.py @@ -41,7 +41,8 @@ class Achievement(db.Model): return { "id": self.id, "name": self.name, - "endorsed_by": [x.id for x in self.endorsed_by], # Don't show full user object to avoid infinite loops + "endorsed_by": ([x.id for x in self.endorsed_by]), # Don't show full user object to avoid infinite loops + "achieved_by": self.achieved_by } def __repr__(self): diff --git a/user.py b/user.py index 1abe809..dd20c2c 100644 --- a/user.py +++ b/user.py @@ -6,7 +6,7 @@ from flask_login import current_user, login_required import json -@app.route("/users//add_achievement") +@app.route("/users//addachievement") @login_required def add_achievement(id): name = request.args.get("name")