|
1 | 1 | from app.db import get_db |
2 | 2 | from app.utils import serialize |
3 | 3 | from sqlalchemy.orm import Session |
4 | | -from fastapi.responses import JSONResponse |
5 | 4 | from fastapi import Depends, APIRouter |
6 | | -from app.models import SeasonEntrantConstructor, SeasonEntrantDriver, SeasonEntrantChassis, SeasonEntrant, SeasonConstructor, SeasonDriver, SeasonTyreManufacturer, SeasonEngineManufacturer, SeasonConstructorStanding, SeasonDriverStanding, Race |
| 5 | +from fastapi.responses import JSONResponse |
| 6 | +from app.models import SeasonEntrantConstructor, SeasonEntrantDriver, SeasonEntrantChassis, SeasonEntrant, SeasonConstructor, SeasonDriver, SeasonTyreManufacturer, SeasonEngineManufacturer, SeasonConstructorStanding, SeasonDriverStanding, Race, GrandPrix |
7 | 7 |
|
8 | 8 | router = APIRouter() |
9 | 9 |
|
10 | | -@router.get("/{year}/races") |
11 | | -async def get_season_races_by_year(year:int, db: Session = Depends(get_db)) -> JSONResponse: |
12 | | - """Obtiene todas las carreras de la temporada""" |
13 | | - season_races_year = db.query( |
| 10 | +@router.get("/{year}/grand_prix") |
| 11 | +async def get_season_grand_prix_by_year(year:int, db: Session = Depends(get_db)) -> JSONResponse: |
| 12 | + """Obtiene todos los grand prix de la temporada""" |
| 13 | + season_grand_prix_year = db.query( |
14 | 14 | Race.id, |
15 | 15 | Race.year, |
16 | 16 | Race.round, |
17 | 17 | Race.grand_prix_id, |
18 | 18 | Race.circuit_id |
19 | 19 | ) \ |
20 | 20 | .filter(Race.year == year).all() |
21 | | - season_races_year_json = serialize(season_races_year) |
22 | | - return JSONResponse(content=season_races_year_json) |
| 21 | + season_grand_prix_year_json = serialize(season_grand_prix_year) |
| 22 | + return JSONResponse(content=season_grand_prix_year_json) |
| 23 | + |
| 24 | +@router.get("/{year}/{round}") |
| 25 | +async def get_grand_prix_by_year_and_round(year: int, round: int, db: Session = Depends(get_db)) -> JSONResponse: |
| 26 | + """Obtener un grand prix por el año y la ronda""" |
| 27 | + gp = db.query(Race)\ |
| 28 | + .filter( |
| 29 | + Race.year == year, |
| 30 | + Race.round == round |
| 31 | + ) \ |
| 32 | + .first() |
| 33 | + gp_json = serialize(gp) |
| 34 | + return JSONResponse(content=gp_json) |
23 | 35 |
|
24 | 36 | @router.get("/{year}/entrants") |
25 | 37 | async def get_season_entrants_by_year(year:int, db: Session = Depends(get_db)) -> JSONResponse: |
|
0 commit comments