|
|
@@ -0,0 +1,70 @@
|
|
|
+import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
|
+import { ErrorSchema } from '@/server/utils/errorHandler';
|
|
|
+import { AuthContext } from '@/server/types/context';
|
|
|
+import z from 'zod';
|
|
|
+import { Handler } from 'hono';
|
|
|
+
|
|
|
+const GetParams = z.object({
|
|
|
+ id: z.string().openapi({
|
|
|
+ param: { name: 'id', in: 'path' },
|
|
|
+ example: '1',
|
|
|
+ description: '群组ID'
|
|
|
+ })
|
|
|
+});
|
|
|
+
|
|
|
+const BelieverSchema = z.object({
|
|
|
+ id: z.number().openapi({ example: 1, description: '信徒ID' }),
|
|
|
+ name: z.string().openapi({ example: '张三', description: '信徒姓名' }),
|
|
|
+ joinTime: z.date().openapi({ example: '2023-01-01T00:00:00Z', description: '加入时间' })
|
|
|
+});
|
|
|
+
|
|
|
+const ListResponseSchema = z.object({
|
|
|
+ data: z.array(BelieverSchema),
|
|
|
+ pagination: z.object({
|
|
|
+ total: z.number().openapi({ example: 100, description: '总记录数' }),
|
|
|
+ current: z.number().openapi({ example: 1, description: '当前页码' }),
|
|
|
+ pageSize: z.number().openapi({ example: 10, description: '每页数量' })
|
|
|
+ })
|
|
|
+});
|
|
|
+
|
|
|
+const routeDef = createRoute({
|
|
|
+ method: 'get',
|
|
|
+ path: '/',
|
|
|
+ request: {
|
|
|
+ params: GetParams,
|
|
|
+ query: z.object({
|
|
|
+ page: z.coerce.number().int().positive().default(1).openapi({
|
|
|
+ example: 1,
|
|
|
+ description: '页码'
|
|
|
+ }),
|
|
|
+ pageSize: z.coerce.number().int().positive().default(10).openapi({
|
|
|
+ example: 10,
|
|
|
+ description: '每页条数'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ responses: {
|
|
|
+ 200: {
|
|
|
+ description: '获取群组信徒列表成功',
|
|
|
+ content: { 'application/json': { schema: ListResponseSchema } }
|
|
|
+ },
|
|
|
+ 400: { description: '请求参数错误', content: { 'application/json': { schema: ErrorSchema } } },
|
|
|
+ 500: { description: '服务器错误', content: { 'application/json': { schema: ErrorSchema } } }
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
|
|
|
+ try {
|
|
|
+ const { id } = c.req.valid('param');
|
|
|
+ const { page, pageSize } = c.req.valid('query');
|
|
|
+ // TODO: 实现获取群组信徒列表的业务逻辑
|
|
|
+ return c.json({
|
|
|
+ data: [],
|
|
|
+ pagination: { total: 0, current: page, pageSize }
|
|
|
+ }, 200);
|
|
|
+ } catch (error) {
|
|
|
+ return c.json({ code: 500, message: error instanceof Error ? error.message : '操作失败' }, 500);
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+export default app;
|