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

29 lines
1.1 KiB
Python

from fastapi import APIRouter, HTTPException
from db.repositories.ch_experimentdb_experiment_data_repos import ChExperimentDBExperimentDataRepository
from network.schemas import ChExperimentDBExperimentDataBody
router = APIRouter()
@router.post('/create')
async def test(data: ChExperimentDBExperimentDataBody):
try:
await ChExperimentDBExperimentDataRepository.create_from_pydantic(data)
return {"message": "Новая запись <ChExperimentDBExperimentData> успешно добавлена"}
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 ChExperimentDBExperimentDataRepository.get_all()
if result is not None:
return result
else:
return {"message": "Нет записей в <ChExperimentDBExperimentData>, либо произошла непредвиденная ошибка"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")