From 01e587b254f8bc1df8a6ab04857ab5c50b2a4998 Mon Sep 17 00:00:00 2001 From: Felipe Allegretti Date: Sun, 17 Nov 2024 19:27:06 +0100 Subject: [PATCH] refactor: implement schemas in endpoints --- app/api/endpoints/clubs.py | 7 ++++--- app/api/endpoints/competitions.py | 9 +++++---- app/api/endpoints/players.py | 17 +++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/api/endpoints/clubs.py b/app/api/endpoints/clubs.py index 642a461..274fea9 100644 --- a/app/api/endpoints/clubs.py +++ b/app/api/endpoints/clubs.py @@ -2,6 +2,7 @@ from fastapi import APIRouter +from app.schemas import clubs as schemas from app.services.clubs.players import TransfermarktClubPlayers from app.services.clubs.profile import TransfermarktClubProfile from app.services.clubs.search import TransfermarktClubSearch @@ -9,21 +10,21 @@ router = APIRouter() -@router.get("/search/{club_name}") +@router.get("/search/{club_name}", response_model=schemas.ClubSearch, response_model_exclude_none=True) def search_clubs(club_name: str, page_number: Optional[int] = 1) -> dict: tfmkt = TransfermarktClubSearch(query=club_name, page_number=page_number) found_clubs = tfmkt.search_clubs() return found_clubs -@router.get("/{club_id}/profile") +@router.get("/{club_id}/profile", response_model=schemas.ClubProfile, response_model_exclude_defaults=True) def get_club_profile(club_id: str) -> dict: tfmkt = TransfermarktClubProfile(club_id=club_id) club_profile = tfmkt.get_club_profile() return club_profile -@router.get("/{club_id}/players") +@router.get("/{club_id}/players", response_model=schemas.ClubPlayers, response_model_exclude_defaults=True) def get_club_players(club_id: str, season_id: Optional[str] = None) -> dict: tfmkt = TransfermarktClubPlayers(club_id=club_id, season_id=season_id) club_players = tfmkt.get_club_players() diff --git a/app/api/endpoints/competitions.py b/app/api/endpoints/competitions.py index abdd1fb..7832d58 100644 --- a/app/api/endpoints/competitions.py +++ b/app/api/endpoints/competitions.py @@ -2,21 +2,22 @@ from fastapi import APIRouter +from app.schemas import competitions as schemas from app.services.competitions.clubs import TransfermarktCompetitionClubs from app.services.competitions.search import TransfermarktCompetitionSearch router = APIRouter() -@router.get("/search/{competition_name}") -def search_competitions(competition_name: str, page_number: Optional[int] = 1) -> dict: +@router.get("/search/{competition_name}", response_model=schemas.CompetitionSearch) +def search_competitions(competition_name: str, page_number: Optional[int] = 1): tfmkt = TransfermarktCompetitionSearch(query=competition_name, page_number=page_number) competitions = tfmkt.search_competitions() return competitions -@router.get("/{competition_id}/clubs") -def get_competition_clubs(competition_id: str, season_id: Optional[str] = None) -> dict: +@router.get("/{competition_id}/clubs", response_model=schemas.CompetitionClubs) +def get_competition_clubs(competition_id: str, season_id: Optional[str] = None): tfmkt = TransfermarktCompetitionClubs(competition_id=competition_id, season_id=season_id) competition_clubs = tfmkt.get_competition_clubs() return competition_clubs diff --git a/app/api/endpoints/players.py b/app/api/endpoints/players.py index 22bfad3..f0bd581 100644 --- a/app/api/endpoints/players.py +++ b/app/api/endpoints/players.py @@ -2,6 +2,7 @@ from fastapi import APIRouter +from app.schemas import players as schemas from app.services.players.achievements import TransfermarktPlayerAchievements from app.services.players.injuries import TransfermarktPlayerInjuries from app.services.players.jersey_numbers import TransfermarktPlayerJerseyNumbers @@ -14,56 +15,56 @@ router = APIRouter() -@router.get("/search/{player_name}") +@router.get("/search/{player_name}", response_model=schemas.PlayerSearch, response_model_exclude_none=True) def search_players(player_name: str, page_number: Optional[int] = 1): tfmkt = TransfermarktPlayerSearch(query=player_name, page_number=page_number) found_players = tfmkt.search_players() return found_players -@router.get("/{player_id}/profile") +@router.get("/{player_id}/profile", response_model=schemas.PlayerProfile, response_model_exclude_none=True) def get_player_profile(player_id: str): tfmkt = TransfermarktPlayerProfile(player_id=player_id) player_info = tfmkt.get_player_profile() return player_info -@router.get("/{player_id}/market_value") +@router.get("/{player_id}/market_value", response_model=schemas.PlayerMarketValue, response_model_exclude_none=True) def get_player_market_value(player_id: str): tfmkt = TransfermarktPlayerMarketValue(player_id=player_id) player_market_value = tfmkt.get_player_market_value() return player_market_value -@router.get("/{player_id}/transfers") +@router.get("/{player_id}/transfers", response_model=schemas.PlayerTransfers, response_model_exclude_none=True) def get_player_transfers(player_id: str): tfmkt = TransfermarktPlayerTransfers(player_id=player_id) player_market_value = tfmkt.get_player_transfers() return player_market_value -@router.get("/{player_id}/jersey_numbers") +@router.get("/{player_id}/jersey_numbers", response_model=schemas.PlayerJerseyNumbers, response_model_exclude_none=True) def get_player_jersey_numbers(player_id: str): tfmkt = TransfermarktPlayerJerseyNumbers(player_id=player_id) player_jerseynumbers = tfmkt.get_player_jersey_numbers() return player_jerseynumbers -@router.get("/{player_id}/stats") +@router.get("/{player_id}/stats", response_model=schemas.PlayerStats, response_model_exclude_none=True) def get_player_stats(player_id: str): tfmkt = TransfermarktPlayerStats(player_id=player_id) player_stats = tfmkt.get_player_stats() return player_stats -@router.get("/{player_id}/injuries") +@router.get("/{player_id}/injuries", response_model=schemas.PlayerInjuries, response_model_exclude_none=True) def get_player_injuries(player_id: str, page_number: Optional[int] = 1): tfmkt = TransfermarktPlayerInjuries(player_id=player_id, page_number=page_number) players_injuries = tfmkt.get_player_injuries() return players_injuries -@router.get("/{player_id}/achievements") +@router.get("/{player_id}/achievements", response_model=schemas.PlayerAchievements, response_model_exclude_none=True) def get_player_achievements(player_id: str): tfmkt = TransfermarktPlayerAchievements(player_id=player_id) player_achievements = tfmkt.get_player_achievements()