feat: pagination and query params for a deal end-point
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import math
|
||||
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from repositories import DealRepository
|
||||
from schemas.base import PaginationSchema
|
||||
from schemas.deal import *
|
||||
|
||||
|
||||
@ -9,10 +12,25 @@ class DealService:
|
||||
def __init__(self, session: AsyncSession):
|
||||
self.repository = DealRepository(session)
|
||||
|
||||
async def get_deals(self, board_id: int) -> GetDealsResponse:
|
||||
deals = await self.repository.get_all(board_id)
|
||||
async def get_deals(
|
||||
self,
|
||||
pagination: PaginationSchema,
|
||||
board_id: Optional[int],
|
||||
project_id: Optional[int],
|
||||
) -> GetDealsResponse:
|
||||
deals, total_items = await self.repository.get_all(
|
||||
board_id, project_id, pagination.page, pagination.items_per_page
|
||||
)
|
||||
|
||||
total_pages = 1
|
||||
if pagination.items_per_page:
|
||||
total_pages = math.ceil(total_items / pagination.items_per_page)
|
||||
|
||||
return GetDealsResponse(
|
||||
deals=[DealSchema.model_validate(deal) for deal in deals]
|
||||
deals=[DealSchema.model_validate(deal) for deal in deals],
|
||||
pagination_info=PaginationInfoSchema(
|
||||
total_pages=total_pages, total_items=total_items
|
||||
),
|
||||
)
|
||||
|
||||
async def create_deal(self, request: CreateDealRequest) -> CreateDealResponse:
|
||||
|
||||
Reference in New Issue
Block a user