Skip to content

[API] Add pagination and filtering to GET /api/loans and GET /api/groups #3

Description

@Mona-i

Problem

GET /api/loans and GET /api/groups return all records with no pagination. When a group has hundreds of contributions or there are thousands of loans, this will cause slow responses, excessive memory usage, and poor client performance.

// loans.service.ts — no limit, no offset
return this.prisma.loan.findMany({
where: { ... },
orderBy: { requestedAt: "desc" },
});

Task

Add cursor-based or offset pagination to both endpoints:

Query Parameters

  • ?page=1&limit=20 (default: page 1, limit 20, max 100)
  • ?status=Pending (existing, keep)
  • ?groupId=xxx (existing, keep)
  • ?sortBy=amount&order=desc for loans

Response Envelope

{
"data": [...],
"meta": {
"page": 1,
"limit": 20,
"total": 143,
"totalPages": 8
}
}

Update:

  • loans.service.ts — add findAll(page, limit, groupId?, status?)
  • loans.controller.ts — add @apiquery decorators for all new params
  • groups.service.ts — add pagination to findAll()
  • groups.controller.ts — Swagger decorators

Acceptance Criteria

  • Both endpoints paginated
  • Response includes meta object with pagination info
  • Default: page 1, limit 20
  • Max limit: 100 (reject > 100 with 400)
  • Swagger docs updated (@apiquery for all params)
  • Unit tests for service layer with page/limit params

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions