feat: patch and get statuses endpoints
This commit is contained in:
25
services/status.py
Normal file
25
services/status.py
Normal file
@ -0,0 +1,25 @@
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from repositories import StatusRepository
|
||||
from schemas.board import UpdateBoardResponse
|
||||
from schemas.status import UpdateStatusRequest, GetStatusesResponse, StatusSchema
|
||||
|
||||
|
||||
class StatusService:
|
||||
def __init__(self, session: AsyncSession):
|
||||
self.repository = StatusRepository(session)
|
||||
|
||||
async def get_statuses(self, board_id: int) -> GetStatusesResponse:
|
||||
statuses = await self.repository.get_all(board_id)
|
||||
return GetStatusesResponse(
|
||||
statuses=[StatusSchema.model_validate(status) for status in statuses]
|
||||
)
|
||||
|
||||
async def update_status(self, status_id: int, request: UpdateStatusRequest):
|
||||
status = await self.repository.get_by_id(status_id)
|
||||
if not status:
|
||||
raise HTTPException(status_code=404, detail="Статус не найден")
|
||||
|
||||
await self.repository.update(status, request.status)
|
||||
return UpdateBoardResponse(message="Статус успешно обновлен")
|
||||
Reference in New Issue
Block a user