2024-10-22 16:46:39 +04:00
|
|
|
from fastapi import APIRouter, HTTPException
|
2024-10-27 23:29:52 +04:00
|
|
|
|
|
|
|
from db.crud import *
|
|
|
|
from db.models import LoadParameters
|
2024-10-22 16:46:39 +04:00
|
|
|
from network.schemas import LoadParametersBody
|
|
|
|
|
2024-10-27 23:29:52 +04:00
|
|
|
|
2024-10-22 16:46:39 +04:00
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
@router.post('/create')
|
2024-10-27 23:29:52 +04:00
|
|
|
async def create_load_parameters(body: LoadParametersBody):
|
2024-10-22 16:46:39 +04:00
|
|
|
try:
|
2024-10-27 23:29:52 +04:00
|
|
|
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
|
|
|
|
)
|
2024-10-22 16:46:39 +04:00
|
|
|
return {"message": "Новая запись <LoadParameters> успешно добавлена"}
|
|
|
|
except Exception as e:
|
|
|
|
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
@router.get('/all')
|
2024-10-22 20:55:30 +04:00
|
|
|
async def get_all_load_parameters():
|
2024-10-22 16:46:39 +04:00
|
|
|
try:
|
2024-10-27 23:29:52 +04:00
|
|
|
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)
|
2024-10-22 16:46:39 +04:00
|
|
|
|
|
|
|
if result is not None:
|
|
|
|
return result
|
|
|
|
else:
|
2024-10-27 23:29:52 +04:00
|
|
|
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> не найдена"}
|
2024-10-22 16:46:39 +04:00
|
|
|
except Exception as e:
|
|
|
|
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|