Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
feat: add sports
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Nov 22, 2024
1 parent acb09d8 commit 677befa
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def generate_unique_operation_id(route: APIRoute) -> str:
)

from src.modules.events.routes import router as router_events # noqa: E402
from src.modules.sports.routes import router as router_sports # noqa: E402
from src.modules.users.routes import router as router_users # noqa: E402

app.include_router(router_users)
app.include_router(router_events)
app.include_router(router_sports)
Empty file.
19 changes: 19 additions & 0 deletions backend/src/modules/sports/repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
__all__ = ["sports_repository"]

from src.storages.mongo.sports import Sport


# noinspection PyMethodMayBeStatic
class SportsRepository:
async def read_one(self, id: str) -> Sport | None:
return await Sport.get(id)

async def read_all(self) -> list[Sport] | None:
return await Sport.all().to_list()

async def create_many(self, events: list[Sport]) -> bool:
res = await Sport.insert_many(events)
return res.acknowledged


sports_repository: SportsRepository = SportsRepository()
37 changes: 37 additions & 0 deletions backend/src/modules/sports/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from fastapi import APIRouter

from src.api.exceptions import IncorrectCredentialsException
from src.modules.sports.repository import sports_repository
from src.storages.mongo import Sport

router = APIRouter(
prefix="/sports",
tags=["Sports"],
responses={
**IncorrectCredentialsException.responses,
},
)


@router.get("/", responses={200: {"description": "Info about all sports"}})
async def get_all_sports() -> list[Sport]:
"""
Get info about all sports.
"""
return await sports_repository.read_all()


@router.get("/{id}", responses={200: {"description": "Info about sport"}})
async def get_sport(id: str) -> Sport:
"""
Get info about one sport.
"""
return await sports_repository.read_one(id)


@router.post("/", responses={200: {"description": "Create many sports"}})
async def create_many_sports(sports: list[Sport]) -> bool:
"""
Create multiple sports.
"""
return await sports_repository.create_many(sports)
3 changes: 2 additions & 1 deletion backend/src/storages/mongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from beanie import Document, View

from src.storages.mongo.events import Event
from src.storages.mongo.sports import Sport
from src.storages.mongo.users import User

document_models = cast(
list[type[Document] | type[View] | str],
[User, Event],
[User, Event, Sport],
)
16 changes: 16 additions & 0 deletions backend/src/storages/mongo/sports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__all__ = ["Sport", "SportSchema"]

from src.pydantic_base import BaseSchema
from src.storages.mongo.__base__ import CustomDocument


class SportSchema(BaseSchema):
sport: str
"Название вида спорта"
disciplines: list[str]
"Названия дисциплин"


class Sport(SportSchema, CustomDocument):
class Settings:
pass

0 comments on commit 677befa

Please sign in to comment.