diff --git a/lkeep/apps/__init__.py b/lkeep/apps/__init__.py index c30336a..98e016b 100644 --- a/lkeep/apps/__init__.py +++ b/lkeep/apps/__init__.py @@ -5,3 +5,11 @@ Специально для проекта "Код на салфетке" https://pressanybutton.ru/category/servis-na-fastapi/ """ + +from fastapi import APIRouter + +from lkeep.apps.auth.routes import auth_router + +apps_router = APIRouter(prefix="/api/v1") + +apps_router.include_router(router=auth_router) diff --git a/lkeep/apps/auth/routes.py b/lkeep/apps/auth/routes.py new file mode 100644 index 0000000..99f7c4f --- /dev/null +++ b/lkeep/apps/auth/routes.py @@ -0,0 +1,31 @@ +""" +Проект: Lkeep +Автор: Иван Ашихмин +Год: 2025 +Специально для проекта "Код на салфетке" +https://pressanybutton.ru/category/servis-na-fastapi/ +""" + +from fastapi import APIRouter, Depends +from starlette import status + +from lkeep.apps.auth.schemas import RegisterUser, UserReturnData +from lkeep.apps.auth.services import UserService + +auth_router = APIRouter(prefix="/auth", tags=["auth"]) + + +@auth_router.post(path="/register", status_code=status.HTTP_201_CREATED) +async def registration(user: RegisterUser, service: UserService = Depends(UserService)) -> UserReturnData: + """ + Регистрация нового пользователя. + + :param user: Данные нового пользователя, который нужно зарегистрировать. + :type user: RegisterUser + :param service: Сервис для взаимодействия с пользователями. + :type service: UserService + :returns: Данные зарегистрированного пользователя. + :rtype: UserReturnData + :raises HTTPException 400: Если данные пользователя некорректны. + """ + return await service.register_user(user=user) diff --git a/lkeep/main.py b/lkeep/main.py index c939461..1aeec25 100644 --- a/lkeep/main.py +++ b/lkeep/main.py @@ -9,8 +9,12 @@ https://pressanybutton.ru/category/servis-na-fastapi/ import uvicorn from fastapi import FastAPI +from lkeep.apps import apps_router + app = FastAPI() +app.include_router(router=apps_router) + def start(): uvicorn.run(app="lkeep.main:app", reload=True)