"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const router_1 = __importDefault(require("@koa/router"));
const comments_service_1 = require("./comments.service");
const router = new router_1.default({ prefix: '/api/comments' });
// 测试用户ID
const TEST_USER_ID = 1;
/**
 * 获取章节评论
 * GET /api/comments/:chapterId
 */
router.get('/:chapterId', async (ctx) => {
    try {
        const chapterId = parseInt(ctx.params.chapterId);
        const comments = await comments_service_1.commentsService.getCommentsByChapterId(chapterId);
        ctx.body = {
            code: 0,
            message: 'success',
            data: comments,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '获取评论失败',
        };
    }
});
/**
 * 添加评论
 * POST /api/comments
 */
router.post('/', async (ctx) => {
    try {
        const { chapterId, content, rating } = ctx.request.body;
        const comment = await comments_service_1.commentsService.addComment(TEST_USER_ID, chapterId, content, rating);
        ctx.body = {
            code: 0,
            message: '评论成功',
            data: comment,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '评论失败',
        };
    }
});
exports.default = router;
