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

26 lines
1.0 KiB
Python
Raw Normal View History

from fastapi import APIRouter, HTTPException
from db.repositories.recycling_parameters_repos import RecyclingParametersRepository
from network.schemas import RecyclingParametersBody
router = APIRouter()
@router.post('/create')
async def create_recycling_parameters(data: RecyclingParametersBody):
try:
await RecyclingParametersRepository.create_from_pydantic(data)
return {"message": "Новая запись <RecyclingParameters> успешно добавлена"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@router.get('/all')
async def get_all_recycling_parameters():
try:
result = await RecyclingParametersRepository.get_all()
if result:
return result
else:
return {"message": "Нет записей в <RecyclingParameters>, либо произошла непредвиденная ошибка"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")