/** * @file 样例控制器 * @author hotok * @date 2025-06-29 * @lastEditor hotok * @lastEditTime 2025-06-29 * @description 样例接口控制器,演示完整的接口开发流程 */ import { Elysia } from 'elysia'; import { jwtAuthPlugin } from '@/plugins/jwt/jwt.plugins'; import { GetUserByUsernameSchema } from './example.schema'; import { GetUserByUsernameResponses } from './example.response'; import { tags } from '@/modules/tags'; import { exampleService } from './example.service'; /** * 样例控制器 * @description 提供样例接口的路由定义和请求处理逻辑 * @modification hotok 2025-06-29 实现根据用户名查询用户接口 */ export const exampleController = new Elysia() // 使用JWT认证插件 .use(jwtAuthPlugin) /** * 根据用户名查询用户信息 * @route GET /api/example/user/:username * @description 通过用户名查询用户的详细信息,需要JWT认证 * @param username 用户名,路径参数,长度2-50字符 * @returns 用户信息对象或错误响应 * @modification hotok 2025-06-29 初始实现 */ .get( '/user/:username', ({ params, user }) => { return exampleService.findUserByUsername({ params, user }); }, { // 路径参数验证 params: GetUserByUsernameSchema, // API文档配置 detail: { summary: '根据用户名查询用户信息', description: '通过用户名查询用户的详细信息,需要JWT身份认证。返回用户的基本信息,不包含敏感数据如密码。', tags: [tags.user, tags.example], security: [{ bearerAuth: [] }], }, // 响应格式定义 response: GetUserByUsernameResponses, }, );