PIbd-42_SSPR/network/routes/load_parameters_router.py

61 lines
1.9 KiB
Python
Raw Normal View History

from fastapi import APIRouter, HTTPException
from db.crud import *
from db.models import LoadParameters
from network.schemas import LoadParametersBody
router = APIRouter()
@router.post('/create')
async def create_load_parameters(body: LoadParametersBody):
try:
await create(LoadParameters,
load=body.load,
primary_air_consumption=body.primary_air_consumption,
secondary_air_consumption=body.secondary_air_consumption,
gas_inlet_consumption=body.gas_inlet_consumption
)
return {"message": "Новая запись <LoadParameters> успешно добавлена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.get('/all')
async def get_all_load_parameters():
try:
result = await get_all(LoadParameters)
if result is not None:
return result
else:
return {"message": "Нет записей в <LoadParameters>"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.get('/{id}')
async def get_by_id_load_parameters(id: int):
try:
result = await get_by_id(LoadParameters, id)
if result is not None:
return result
else:
return {"message": "Запись <LoadParameters> не найдена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.delete('/{id}/delete')
async def delete_load_parameters(id: int):
try:
is_deleted = await delete(LoadParameters, id)
if is_deleted:
return {"message": "Запись <LoadParameters> успешно удалена"}
else:
return {"message": "Запись <LoadParameters> не найдена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")