From 85da6de857beb0e0cf579e91bb790cbb4ee60d05 Mon Sep 17 00:00:00 2001 From: Ferrariic Date: Wed, 16 Nov 2022 11:37:55 -0600 Subject: [PATCH] template --- api/app.py | 5 +- api/database/functions.py | 5 +- api/database/tables.sql | 16 +++++ api/routers/general.py | 146 ++++++++++++++++++++++++++++++++++++++ notes.md | 14 ++++ 5 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 api/database/tables.sql create mode 100644 api/routers/general.py diff --git a/api/app.py b/api/app.py index e32c68d..b8e3f29 100644 --- a/api/app.py +++ b/api/app.py @@ -1,10 +1,9 @@ import api.middleware from api.config import app -from api.routers import ( - registration, -) +from api.routers import registration, general app.include_router(registration.router) +app.include_router(general.router) @app.get("/") diff --git a/api/database/functions.py b/api/database/functions.py index 53cd79b..06716ac 100644 --- a/api/database/functions.py +++ b/api/database/functions.py @@ -8,12 +8,13 @@ from asyncio.tasks import create_task from collections import namedtuple -from api.config import salt -from api.database.database import USERDATA_ENGINE, Engine from sqlalchemy import Text, text from sqlalchemy.exc import InternalError, OperationalError from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession +from api.config import salt +from api.database.database import USERDATA_ENGINE, Engine + logger = logging.getLogger(__name__) diff --git a/api/database/tables.sql b/api/database/tables.sql new file mode 100644 index 0000000..f0eba9e --- /dev/null +++ b/api/database/tables.sql @@ -0,0 +1,16 @@ +CREATE TABLE `registration` ( + `user_id` int NOT NULL AUTO_INCREMENT, + `email` varchar(320) NOT NULL, + `password` tinytext NOT NULL, + `timestamp_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `timestamp_edited` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE `tokens` ( + `token_id` int NOT NULL AUTO_INCREMENT, + `token` tinytext NOT NULL, + `user_id` int NOT NULL, + `auth_level` int NOT NULL, + PRIMARY KEY (`token_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; \ No newline at end of file diff --git a/api/routers/general.py b/api/routers/general.py new file mode 100644 index 0000000..46d0185 --- /dev/null +++ b/api/routers/general.py @@ -0,0 +1,146 @@ +import json + +from fastapi import APIRouter +from pydantic import BaseModel +from typing import List, Optional +from pymysql import Timestamp +import datetime + +from api.database.functions import hashbrown, sqlalchemy_result +from api.database.models import Registration, Tokens +from sqlalchemy.sql.expression import select, update +from api.database.database import USERDATA_ENGINE +from fastapi import APIRouter, HTTPException, Request +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession +from sqlalchemy.sql.expression import select, update + +router = APIRouter() + + +@router.get("/v1/profiles/{token}", tags=["profile"]) +async def get_profile_information(token: str) -> json: + """returns profile picture string, and user id""" + + +@router.get("/v1/trainers/{token}", tags=["trainers"]) +async def get_trainer_information(token: str) -> json: + """ + Background image: string, + Title: string, + Number of exercises: number, + Difficulty: string + """ + + +@router.get("/v1/events/{token}", tags=["events"]) +async def get_event_information(token: str) -> json: + """ + Params: token:string + { + Background image: string, + Title: string, + Number of exercises: number, + Difficulty: string, + } + """ + pass + + +@router.get("/v1/dashboard/{token}/{user_id}", tags=["dashboard"]) +async def get_dashboard_information(token: str, user_id: str) -> json: + """ + Params: + { + token:string, + User id: number, + } + Returns: + Wallet balance: number, + Earnings total: number, + Taxes total: number, + Hours worked: number, + Sessions worked: number, + Categories assigned: number, + Clients count: number, + Clients profiles: array:string, + Steps: number, + Distance: number, + } + """ + pass + + +@router.get("/v1/workout/{token}/{user_id}", tags=["workout"]) +async def get_workout_plan(token: str, user_id: str) -> json: + """ + Params: + { + Token: string, + User id: number, + } + Returns: + { + Name: string, + Rating: number, + Number of workouts completed: number, + Fitness level: string, + Global stats: array: { title: string, stat: number }, + Workout plan: array: array: {workout: string, repts: string, weight: number} + } + """ + pass + + +@router.get("/v1/profile-details/{token}/{user_id}", tags=["profile"]) +async def get_profile_details(token: str, user_id: str) -> json: + """ + Get Profile Details + Params: + { + Token: string, + User id: number, + } + + Returns + { + Name: string, + Type: string, + Rating: number, + Rate: number, + About: string, + Goals: array:string, + Number of photos: number, + Partners: number, + Trainers: number, + Gallery: array:string + } + """ + pass + + +@router.get("/v1/challenge/{token}/{challenge_id}", tags=["challenge"]) +async def get_challenge_details(token: str, challenge_id: str) -> json: + """ + Get Challenge Details + Params: + { + Challenge id: number, + Token: string, + } + + Returns: + { + Name: string, + Background: string, + Profile picture: string, + Description: string, + Start date: string, + End date: string, + Distance: number, + Reward: string, + Organization: { name: string, image: string, distance: number} + Leaderboard: array: {name: string, pace: number, distance: number} + } + """ + pass diff --git a/notes.md b/notes.md index 7dcd254..805b885 100644 --- a/notes.md +++ b/notes.md @@ -6,6 +6,20 @@ python -m pip install --upgrade pip pip install -r requirements.txt ``` +## setup if you have multiple versions of python installed +``` +pip install virtualenv +# py -m virtualenv -p="C:\Users\thear\AppData\Local\Programs\Python\Python310\python.exe" venv +py -m virtualenv -p="" venv +venv\Scripts\activate +python -m pip install --upgrade pip +pip install -r requirements.txt +``` + +# if the interpreter does not recognize imports, for some reason, use: +ctrl + shift + P > select python interpreter +strl + shift + ` > should work now + # for saving & upgrading ``` venv\Scripts\activate