64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
from db.crud import *
|
|
from db.models import LoadParameters
|
|
from network.schemas import ExperimentParametersBody
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post('/create')
|
|
async def create_experiment_parameters(body: ExperimentParametersBody):
|
|
try:
|
|
await create(ExperimentParameters,
|
|
outer_blades_count=body.outer_blades_count,
|
|
outer_blades_length=body.outer_blades_length,
|
|
outer_blades_angle=body.outer_blades_angle,
|
|
middle_blades_count=body.middle_blades_count,
|
|
load_id=body.load_id,
|
|
recycling_id=body.recycling_id,
|
|
experiment_hash=body.experiment_hash
|
|
)
|
|
|
|
return {"message": "Новая запись <ExperimentParameters> успешно добавлена"}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
|
|
|
|
|
@router.get('/all')
|
|
async def get_all_experiment_parameters():
|
|
try:
|
|
result = await get_all(ExperimentParameters)
|
|
|
|
if result is not None:
|
|
return result
|
|
else:
|
|
return {"message": "Нет записей в <ExperimentParameters>"}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
|
|
|
|
|
@router.get('/{id}')
|
|
async def get_by_id_experiment_parameters(id: int):
|
|
try:
|
|
result = await get_by_id(ExperimentParameters, id)
|
|
|
|
if result is not None:
|
|
return result
|
|
else:
|
|
return {"message": "Запись <ExperimentParameters> не найдена"}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
|
|
|
|
|
@router.delete('/{id}/delete')
|
|
async def delete_experiment_parameters(id: int):
|
|
try:
|
|
is_deleted = await delete(LoadParameters, id)
|
|
if is_deleted:
|
|
return {"message": "Запись <ExperimentParameters> успешно удалена"}
|
|
else:
|
|
return {"message": "Запись <ExperimentParameters> не найдена"}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|