From 3150753e44834091965cc88dff0e0fbba0bcfcfd Mon Sep 17 00:00:00 2001 From: Ana Rute Mendes Date: Tue, 10 Oct 2023 17:37:53 +0200 Subject: [PATCH] Add users/me endpoint It will be used to get more information about the current user --- api/main.py | 3 ++- api/routers/v1/users.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 api/routers/v1/users.py diff --git a/api/main.py b/api/main.py index be0ae12b8..d95962c90 100644 --- a/api/main.py +++ b/api/main.py @@ -1,6 +1,6 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware -from routers.v1 import projects, timelog +from routers.v1 import projects, timelog, users from db.db_connection import engine from db.base_class import Base @@ -30,6 +30,7 @@ app.include_router(projects.router, prefix="/v1") app.include_router(timelog.router, prefix="/v1") +app.include_router(users.router, prefix="/v1") @app.get("/") diff --git a/api/routers/v1/users.py b/api/routers/v1/users.py new file mode 100644 index 000000000..d7665ca5c --- /dev/null +++ b/api/routers/v1/users.py @@ -0,0 +1,19 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.orm import Session + +from db.db_connection import get_db +from auth.auth_bearer import BearerToken +from dependencies import get_current_user +from schemas.user import AppUser + +router = APIRouter( + prefix="/users", + tags=["users"], + responses={403: {"description": "Forbidden"}, 404: {"description": "Not found"}}, + dependencies=[Depends(BearerToken())], +) + + +@router.get("/users/me", response_model=AppUser) +async def get_current_user_profile(current_user=Depends(get_current_user), db: Session = Depends(get_db)): + return current_user