26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
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="Статус успешно обновлен")
|