Skip to content

Commit

Permalink
refactor: implement schemas in endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeall committed Dec 8, 2024
1 parent fe7cba0 commit 4fedef1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
7 changes: 4 additions & 3 deletions app/api/endpoints/clubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@

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

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()
Expand Down
9 changes: 5 additions & 4 deletions app/api/endpoints/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 9 additions & 8 deletions app/api/endpoints/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 4fedef1

Please sign in to comment.