aboutsummaryrefslogtreecommitdiff
path: root/api/user
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-15 18:44:13 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-15 18:44:13 +0200
commit60fc420f03ff2a7098080d018e81e49f5722c795 (patch)
treebf31528ef0c270f77f29f8a914887ab3e867f0dd /api/user
parentcc53f217f6122151bcae131a42da8f8887f8560d (diff)
started using doc strings + /api/user/games @one_person decorator
Diffstat (limited to 'api/user')
-rw-r--r--api/user/games.py34
1 files changed, 7 insertions, 27 deletions
diff --git a/api/user/games.py b/api/user/games.py
index 92799bd..da5f422 100644
--- a/api/user/games.py
+++ b/api/user/games.py
@@ -2,10 +2,10 @@ from flask import Blueprint, request
from functools import reduce
from mergedeep import merge
from db import cursor
-from auth.login_token import token_login
from user.info import format_user
from ruleset import resolve_ruleset
from game.info import format_game
+from hierarchy import one_person
import json
@@ -65,32 +65,12 @@ games = Blueprint('games', __name__)
@games.route('/games', methods=['GET', 'POST'])
-def index():
- data_string = request.data or "{}"
- data = json.loads(data_string)
-
- user_id = data.get("id") or ""
- token = request.cookies.get("token") or ""
-
- if not user_id and \
- not token:
- return "", 400
-
- if token and not user_id:
- user_id = token_login(token)
-
- if not cursor.execute(
- "select user_id from users where user_id = ?", [user_id]
- ).fetchone():
- return "", 403
-
- export = {}
- merge(
- export, {"totals": sum_games(user_id)},
- {"games": fetch_games(user_id, 20)}
- )
-
- return export, 200
+@one_person
+def index(user_id, viewer):
+ return {
+ "totals": sum_games(user_id),
+ "games": fetch_games(user_id, 20)
+ }, 200
dynamic_route = ["/user", games]