diff --git a/src/nsls2api/api/models/facility_model.py b/src/nsls2api/api/models/facility_model.py index 44de4a0d..5e6b2fb2 100644 --- a/src/nsls2api/api/models/facility_model.py +++ b/src/nsls2api/api/models/facility_model.py @@ -8,4 +8,8 @@ class FacilityName(Enum): class FacilityCyclesResponseModel(pydantic.BaseModel): facility: str - cycles: list[str] \ No newline at end of file + cycles: list[str] + +class FacilityCurrentOperatingCycleResponseModel(pydantic.BaseModel): + facility: str + cycle: str \ No newline at end of file diff --git a/src/nsls2api/api/v1/facility_api.py b/src/nsls2api/api/v1/facility_api.py index 69af667e..59493888 100644 --- a/src/nsls2api/api/v1/facility_api.py +++ b/src/nsls2api/api/v1/facility_api.py @@ -1,6 +1,10 @@ import fastapi -from nsls2api.api.models.facility_model import FacilityName, FacilityCyclesResponseModel +from nsls2api.api.models.facility_model import ( + FacilityName, + FacilityCyclesResponseModel, + FacilityCurrentOperatingCycleResponseModel, +) from nsls2api.services import proposal_service, facility_service router = fastapi.APIRouter() @@ -8,25 +12,36 @@ # TODO: Add back into schema when implemented. @router.get( - "/facility/{facility}/cycles/current", response_model=FacilityCyclesResponseModel, include_in_schema=True + "/facility/{facility}/cycles/current", + response_model=FacilityCurrentOperatingCycleResponseModel, + include_in_schema=True, ) async def get_current_operating_cycle(facility: FacilityName): current_cycle = await facility_service.current_operating_cycle(facility.name) if current_cycle is None: return fastapi.responses.JSONResponse( - {"error": f"No current operating cycle was found for facility {facility.name}"}, + { + "error": f"No current operating cycle was found for facility {facility.name}" + }, status_code=404, ) - + # TODO: Maybe add a health check here # print("Are we healthy ? ") # print(await facility_service.is_healthy(facility.name)) - response_model = FacilityCyclesResponseModel(facility=facility.name, cycles=[current_cycle]) - + response_model = FacilityCurrentOperatingCycleResponseModel( + facility=facility.name, cycle=current_cycle + ) + return response_model -@router.get("/facility/{facility}/cycles", include_in_schema=True) + +@router.get( + "/facility/{facility}/cycles", + response_model=FacilityCyclesResponseModel, + include_in_schema=True, +) async def get_facility_cycles(facility: FacilityName): cycle_list = await facility_service.facility_cycles(facility.name) if cycle_list is None: @@ -34,8 +49,11 @@ async def get_facility_cycles(facility: FacilityName): {"error": f"No cycles were found for facility {facility.name}"}, status_code=404, ) - data = {"facility": facility.name, "cycles": cycle_list} - return data + response_model = FacilityCyclesResponseModel( + facility=facility.name, cycles=cycle_list + ) + return response_model + @router.get("/facility/{facility}/cycle/{cycle}/proposals", include_in_schema=True) async def get_proposals_for_cycle(facility: FacilityName, cycle: str):