2020-12-20 01:36:36 +01:00
|
|
|
import logging
|
2020-12-22 02:25:56 +01:00
|
|
|
from enum import Enum
|
2020-12-20 01:36:36 +01:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2020-12-22 02:25:56 +01:00
|
|
|
class Severity(str, Enum):
|
|
|
|
slight = "Slight"
|
|
|
|
serious = "Serious"
|
|
|
|
fatal = "Fatal"
|
|
|
|
|
|
|
|
|
2020-12-20 01:36:36 +01:00
|
|
|
class Accident(BaseModel):
|
|
|
|
lat: float
|
|
|
|
lon: float
|
2020-12-22 02:25:56 +01:00
|
|
|
severity: Severity
|
2020-12-20 01:36:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
@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)
|