geovisualisierung/projects/project-3/backend/routers/accidents.py

44 lines
873 B
Python
Raw Normal View History

2020-12-20 01:36:36 +01:00
import logging
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()
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
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)