from fastapi import APIRouter, HTTPException, status from src.maximo.service import MaximoService from .model import OverhaulHistory from .schema import OverhaulHistoryCreate, OverhaulHistoryRead, OverhaulHistoryUpdate, OverhaulHistoryPagination from .service import get, get_all, start_overhaul from src.database.service import CommonParameters, search_filter_sort_paginate from src.database.core import DbSession from src.auth.service import CurrentUser from src.models import StandardResponse router = APIRouter() @router.get("", response_model=StandardResponse[OverhaulHistoryPagination]) async def get_histories(common: CommonParameters): """Get all scope pagination.""" # return return StandardResponse( data=await search_filter_sort_paginate(model=OverhaulHistory, **common), message="Data retrieved successfully", ) @router.get("/{overhaul_history_id}", response_model=StandardResponse[OverhaulHistoryRead]) async def get_history(db_session: DbSession, overhaul_history_id: str): overhaul_history = await get(db_session=db_session, overhaul_history_id=overhaul_history_id) if not overhaul_history: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail="A data with this id does not exist.", ) return StandardResponse(data=overhaul_history, message="Data retrieved successfully") @router.post("", response_model=StandardResponse[OverhaulHistoryRead]) async def create_history(db_session: DbSession, scope_in: OverhaulHistoryCreate): try: maximo_service = MaximoService() maximo_data = await maximo_service.get_recent_overhaul() overhaul = await start_overhaul(db_session=db_session, maximo_data=maximo_data) except HTTPException as he: raise he return StandardResponse(data=overhaul, message="Data created successfully")