Skip to content

feat(api): include creator/assignee/applicationCount in bounty detail#88

Open
automaton365-sys wants to merge 1 commit intodevasignhq:mainfrom
automaton365-sys:fix-bounty-detail-21
Open

feat(api): include creator/assignee/applicationCount in bounty detail#88
automaton365-sys wants to merge 1 commit intodevasignhq:mainfrom
automaton365-sys:fix-bounty-detail-21

Conversation

@automaton365-sys
Copy link

Adds missing fields to GET /api/bounties/:id.\n\n- includes creator relation (id, username, avatarUrl)\n- includes assignee relation (id, username, avatarUrl)\n- computes and returns applicationCount\n- adds tests for success and 404\n\nFixes #21\n/claim #21

@devasign-app
Copy link

devasign-app bot commented Mar 3, 2026

🟢 AI Code Review Results

Status: Ready to Merge
Confidence: 100%


🟢 Merge Score: 85/100

🟢 █████████████████░░░ 85%

Recommendation: ✅ This PR looks great and is ready for merge!

The PR correctly implements the feature and adds comprehensive tests. However, there is a significant performance issue in how the application count is calculated. I've provided a suggestion to optimize the database query to resolve this, which should be addressed before merging.

💡 Code Suggestions (1)

🟡 Medium Priority (1)

  1. packages/api/src/routes/bounties.ts (Line 130)
    ⚡ The current implementation uses two separate database queries: one to fetch the bounty and another to fetch all its applications just to get a count. This is inefficient and can lead to performance issues for bounties with many applicants.

💭 Reasoning: By using a subquery with Drizzle ORM's extras feature, we can retrieve the bounty details and the application count in a single, efficient database call. This reduces database round-trips and minimizes data transfer, improving performance and scalability.

Suggested Code:

bountiesRouter.get('/:id', async (c) => {
    const id = c.req.param('id');
    const bounty = await db.query.bounties.findFirst({
        where: eq(bounties.id, id),
        with: {
            creator: {
                columns: {
                    id: true,
                    username: true,
                    avatarUrl: true,
                },
            },
            assignee: {
                columns: {
                    id: true,
                    username: true,
                    avatarUrl: true,
                },
            },
        },
        extras: {
            applicationCount: sql<number>`(select count(*) from ${applications} where ${applications.bountyId} = ${bounties.id})`.as('applicationCount'),
        },
    });

    if (!bounty) {
        return c.json({ error: 'Bounty not found' }, 404);
    }

    return c.json({
        ...bounty,
        applicationCount: Number(bounty.applicationCount || 0),
    });
});
📊 Review Metadata
  • Processing Time: 170s
  • Analysis Date: 3/3/2026, 10:38:32 AM

🤖 This review was generated by AI. While we strive for accuracy, please use your judgment when applying suggestions.

💬 Questions about this review? Open an issue or contact support.

@automaton365-sys
Copy link
Author

/claim

5 similar comments
@automaton365-sys
Copy link
Author

/claim

@automaton365-sys
Copy link
Author

/claim

@automaton365-sys
Copy link
Author

/claim

@automaton365-sys
Copy link
Author

/claim

@automaton365-sys
Copy link
Author

/claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant