diff --git a/src/routes/agents.js b/src/routes/agents.js index 58398ef..9d74ef8 100644 --- a/src/routes/agents.js +++ b/src/routes/agents.js @@ -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 diff --git a/src/services/AgentService.js b/src/services/AgentService.js index 29bc501..d89ef9f 100644 --- a/src/services/AgentService.js +++ b/src/services/AgentService.js @@ -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} 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;