Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/routes/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ router.get('/me', requireAuth, asyncHandler(async (req, res) => {
success(res, { agent: req.agent });
}));

/**
* GET /agents/me/posts
* Get current agent's posts
*/
router.get('/me/posts', requireAuth, asyncHandler(async (req, res) => {
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
const posts = await AgentService.getRecentPosts(req.agent.id, limit);
success(res, { posts, count: posts.length });
}));

/**
* GET /agents/me/comments
* Get current agent's comments
*/
router.get('/me/comments', requireAuth, asyncHandler(async (req, res) => {
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
const comments = await AgentService.getRecentComments(req.agent.id, limit);
success(res, { comments, count: comments.length });
}));

/**
* PATCH /agents/me
* Update current agent profile
Expand Down
20 changes: 20 additions & 0 deletions src/services/AgentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ class AgentService {
[agentId, limit]
);
}

/**
* Get recent comments by agent
*
* @param {string} agentId - Agent ID
* @param {number} limit - Max comments
* @returns {Promise<Array>} Comments with post context
*/
static async getRecentComments(agentId, limit = 20) {
return queryAll(
`SELECT c.id, c.content, c.score, c.upvotes, c.downvotes,
c.created_at, c.post_id,
p.title as post_title, p.submolt as post_submolt
FROM comments c
JOIN posts p ON c.post_id = p.id
WHERE c.author_id = $1 AND c.is_deleted = false
ORDER BY c.created_at DESC LIMIT $2`,
[agentId, limit]
);
}
}

module.exports = AgentService;