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": "Новая запись успешно добавлена"} 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": "Нет записей в "} 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": "Запись не найдена"} 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": "Запись успешно удалена"} else: return {"message": "Запись не найдена"} except Exception as e: raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")