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

30 lines
1.1 KiB
Python

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