You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
be-optimumoh/src/api.py

96 lines
2.9 KiB
Python

from typing import List, Optional
from fastapi import APIRouter, Depends
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from src.auth.service import JWTBearer
from src.scope.router import router as scope_router
from src.scope_equipment.router import router as scope_equipment_router
from src.overhaul.router import router as overhaul_router
from src.calculation_time_constrains.router import router as calculation_time_constrains_router
from src.overhaul_history.router import router as overhaul_history_router
from src.scope_equipment_activity.router import router as scope_equipment_activity_router
from src.overhaul_schedule.router import router as ovehaul_schedule_router
from src.scope_equipment_part.router import router as scope_equipment_part_router
from src.calculation_target_reliability.router import router as calculation_target_reliability
class ErrorMessage(BaseModel):
msg: str
class ErrorResponse(BaseModel):
detail: Optional[List[ErrorMessage]]
api_router = APIRouter(
default_response_class=JSONResponse,
responses={
400: {"model": ErrorResponse},
401: {"model": ErrorResponse},
403: {"model": ErrorResponse},
404: {"model": ErrorResponse},
500: {"model": ErrorResponse},
},
)
@api_router.get("/healthcheck", include_in_schema=False)
def healthcheck():
return {"status": "ok"}
authenticated_api_router = APIRouter(dependencies=[Depends(JWTBearer())],
)
# overhaul data
authenticated_api_router.include_router(
overhaul_router, prefix="/overhauls", tags=["overhaul"])
# Scope data
authenticated_api_router.include_router(
scope_router, prefix="/scopes", tags=["scope"])
authenticated_api_router.include_router(
scope_equipment_router, prefix="/scope-equipments", tags=["scope_equipment"]
)
authenticated_api_router.include_router(
overhaul_history_router, prefix="/overhaul-history", tags=["overhaul_history"]
)
authenticated_api_router.include_router(
scope_equipment_activity_router, prefix="/equipment-activities", tags=["scope_equipment_activities"]
)
authenticated_api_router.include_router(
scope_equipment_part_router, prefix="/equipment-parts", tags=["scope_equipment_parts"]
)
authenticated_api_router.include_router(
ovehaul_schedule_router, prefix="/overhaul-schedules", tags=["overhaul_schedules"]
)
# calculation
calculation_router = APIRouter(prefix="/calculation", tags=["calculations"])
# Time constrains
calculation_router.include_router(
calculation_time_constrains_router, prefix="/time-constraint", tags=["calculation", "time_constraint"])
# Target reliability
calculation_router.include_router(
calculation_target_reliability, prefix="/target-reliability", tags=["calculation", "target_reliability"]
)
# Budget Constrain
authenticated_api_router.include_router(
calculation_router
)
api_router.include_router(authenticated_api_router)