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

62 lines
2.0 KiB
Python

from fastapi import APIRouter, HTTPException
from db.crud import *
from db.models import RecyclingParameters
from network.schemas import RecyclingParametersBody
router = APIRouter()
@router.post('/create')
async def create_recycling_parameters(body: RecyclingParametersBody):
try:
await create(RecyclingParameters,
load_id=body.load_id,
recycling_level=body.recycling_level,
co2=body.co2,
n2=body.n2,
h2o=body.h2o,
o2=body.o2
)
return {"message": "Новая запись <RecyclingParameters> успешно добавлена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.get('/all')
async def get_all_recycling_parameters():
try:
result = await get_all(RecyclingParameters)
if result is not None:
return result
else:
return {"message": "Нет записей в <RecyclingParameters>"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.get('/{id}')
async def get_by_id_recycling_parameters(id: int):
try:
result = await get_by_id(RecyclingParameters, id)
if result is not None:
return result
else:
return {"message": "Запись <RecyclingParameters> не найдена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.delete('/{id}/delete')
async def delete_recycling_parameters(id: int):
try:
is_deleted = await delete(RecyclingParameters, id)
if is_deleted:
return {"message": "Запись <RecyclingParameters> успешно удалена"}
else:
return {"message": "Запись <RecyclingParameters> не найдена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")