"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 categories_service_1 = require("./categories.service");
const router = new router_1.default();
/**
 * 获取分类列表
 * GET /api/categories
 */
router.get('/', async (ctx) => {
    try {
        const categories = await categories_service_1.categoriesService.getCategories();
        ctx.body = {
            code: 0,
            message: 'success',
            data: categories,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '获取分类失败',
        };
    }
});
/**
 * 按分类获取音频
 * GET /api/categories/:id
 */
router.get('/:id', async (ctx) => {
    try {
        const { id } = ctx.params;
        const { page, pageSize } = ctx.query;
        const result = await categories_service_1.categoriesService.getAudiosByCategory(parseInt(id), parseInt(page || '1'), parseInt(pageSize || '20'));
        ctx.body = {
            code: 0,
            message: 'success',
            data: result,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '获取分类音频失败',
        };
    }
});
exports.default = router;
