37 lines
751 B
Python
37 lines
751 B
Python
|
import logging
|
||
|
from typing import List
|
||
|
|
||
|
from fastapi import APIRouter
|
||
|
from pydantic.main import BaseModel
|
||
|
|
||
|
import api_database
|
||
|
|
||
|
router = APIRouter(prefix="/accidents", tags=["accidents", "local"])
|
||
|
LOG = logging.getLogger()
|
||
|
|
||
|
|
||
|
class Accident(BaseModel):
|
||
|
lat: float
|
||
|
lon: float
|
||
|
severity: str
|
||
|
|
||
|
|
||
|
@router.get(
|
||
|
"/",
|
||
|
name="Get all accidents",
|
||
|
description="Get all bike accidents in London.",
|
||
|
response_model=List[Accident]
|
||
|
)
|
||
|
def get_accidents():
|
||
|
return api_database.get_all_accidents()
|
||
|
|
||
|
|
||
|
@router.get(
|
||
|
"/{year}",
|
||
|
name="Get accidents by year",
|
||
|
description="Get bike accidents in London for a specific year.",
|
||
|
response_model=List[Accident]
|
||
|
)
|
||
|
def get_accidents(year: str):
|
||
|
return api_database.get_accidents(year)
|