From cca5584c742829965236dec4fba6b12b63b16805 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Sun, 11 Aug 2024 21:42:07 +0200 Subject: [PATCH] Started work on statistic classes --- src/classes/statistic_classes.py | 5 +++++ src/main.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/classes/statistic_classes.py diff --git a/src/classes/statistic_classes.py b/src/classes/statistic_classes.py new file mode 100644 index 0000000..ed9680c --- /dev/null +++ b/src/classes/statistic_classes.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + +class BaseIntStatistic(BaseModel): + name: str + result: int \ No newline at end of file diff --git a/src/main.py b/src/main.py index 3421b03..238d5ab 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager -from src.classes import boardgame_classes, play_classes +from src.classes import boardgame_classes, play_classes, statistic_classes from src.modules import data_connection @asynccontextmanager @@ -61,4 +61,17 @@ def get_plays(): def get_players_from_play(play_id): requested_players: list[play_classes.PlayPlayer] = data_connection.get_players_from_play(play_id) - return requested_players \ No newline at end of file + return requested_players + + +@app.get('/statistics/amount_of_games', response_model=statistic_classes.BaseIntStatistic) +def get_amount_of_games(): + + statistic_dict = { + "name":"Amount of games in owned collection", + "result":len(data_connection.get_user_owned_collection()) + } + + statistic_to_return = statistic_classes.BaseIntStatistic(**statistic_dict) + + return statistic_to_return \ No newline at end of file