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

30 lines
1.1 KiB
Python

from fastapi import APIRouter, HTTPException
from db.repositories.experiment_data_repos import ExperimentDataRepository
from network.schemas import ExperimentDataBody
router = APIRouter()
@router.post('/create')
async def test(data: ExperimentDataBody):
try:
await ExperimentDataRepository.create_from_pydantic(data)
return {"message": "Новая запись <ExperimentData> успешно добавлена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.get('/all')
async def get_all():
try:
result = await ExperimentDataRepository.get_all()
if result is not None:
# return {"status": "success", "data": [LoadParametersBody.model_validate(param) for param in result]}
return result
else:
return {"message": "Нет записей в <ExperimentData>, либо произошла непредвиденная ошибка"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")