This repository has been archived by the owner on Dec 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acb09d8
commit 677befa
Showing
6 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |