Skip to content

feat: GET /cards endpoint has no pagination β€” a user with 50+ cards receives all cards in a single response, causing excessive payload sizes and slow mobile load timesΒ #664

Description

@divyanshim27

πŸš€ Problem Statement

The README documents GET / as: "List all cards for the authenticated user." The current endpoint returns ALL cards in a single array with no limit, offset, or cursor-based pagination.

While the typical user may have 3-5 Context Cards (Professional, Hackathon, Community), the README documents: "Context Cards β€” Different cards for different situations." Power users can create many cards, and there is no enforced card limit documented in the API.

More importantly, each card response includes links[] β€” an array of all platform URLs. A user with 20 cards Γ— 15 links each = 300 link objects returned on every single GET /cards call. This is significant unnecessary payload for a mobile app (React Native) on a cellular connection.

Proposed Fix

Add page and limit query parameters with sensible defaults:

// apps/backend/src/routes/cards.ts β€” update GET / handler

const schema = z.object({
  page:  z.coerce.number().int().min(1).default(1),
  limit: z.coerce.number().int().min(1).max(50).default(20),
});

fastify.get('/', { preHandler: [authenticate] }, async (request, reply) => {
  const { page, limit } = schema.parse(request.query);
  const skip = (page - 1) * limit;

  const [cards, total] = await Promise.all([
    prisma.card.findMany({
      where: { userId: request.user.id },
      include: { links: true },
      orderBy: [{ isDefault: 'desc' }, { createdAt: 'desc' }],
      skip,
      take: limit,
    }),
    prisma.card.count({ where: { userId: request.user.id } }),
  ]);

  return reply.send({
    data: cards,
    pagination: {
      page,
      limit,
      total,
      totalPages: Math.ceil(total / limit),
      hasNextPage: page * limit < total,
    },
  });
});

Update the README API docs to document the new query parameters and response shape.

Files to Modify

File Change
apps/backend/src/routes/cards.ts Add page/limit query params, paginated Prisma query, pagination response field
README.md Document pagination in the GET / endpoint section
apps/mobile/ (cards list screen) Implement infinite scroll / load more using hasNextPage

Suggested labels: enhancement, backend, performance, level: intermediate

I would like to work on this. Could you please assign it to me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions