Skip to content

Commit

Permalink
fix: add pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Valimp committed May 14, 2024
1 parent 4d607df commit 0de4d8d
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,28 +359,36 @@ def create_ticket(ticket: TicketCreate) -> Ticket:
return _create_ticket(ticket)


def _get_ticket(status: TicketStatus | None, type_: IssueType | None):
"""Get tickets with optional filters."""
query = TicketModel.select()
# def _get_ticket(status: TicketStatus | None, type_: IssueType | None):
# """Get tickets with optional filters."""
# query = TicketModel.select()

if status is not None:
query = query.where(TicketModel.status == status)
# if status is not None:
# query = query.where(TicketModel.status == status)

if type_ is not None:
query = query.where(TicketModel.type == type_)
# if type_ is not None:
# query = query.where(TicketModel.type == type_)

with db:
return list(query.dicts())
# with db:
# return list(query.dicts())


@api_v1_router.get("/tickets")
def get_tickets(status: TicketStatus | None = None, type_: IssueType | None = None):
def get_tickets(status: TicketStatus | None = None, type_: IssueType | None = None, page: int = 1, page_size: int = 10):
"""Get all tickets.
This function is used to get all tickets with status open.
"""
with db:
return _get_ticket(status, type_)
offset = (page - 1) * page_size
return list(
TicketModel.select()
.where(TicketModel.status == status)
.where(TicketModel.type == type_)
.offset(offset)
.limit(page_size)
.dicts()
)


@api_v1_router.get("/tickets/{ticket_id}")
Expand Down

0 comments on commit 0de4d8d

Please sign in to comment.