From 948cd5263e490c5e522fea071d7a3d56ebe9298d Mon Sep 17 00:00:00 2001 From: zyh Date: Thu, 10 Apr 2025 08:31:32 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AFAPI?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=EF=BC=8C=E8=B0=83=E6=95=B4=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8=E8=8E=B7=E5=8F=96=E7=9A=84?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E7=94=A8=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/routes_messages.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/server/routes_messages.ts b/server/routes_messages.ts index 58a95c3..d2e98c9 100644 --- a/server/routes_messages.ts +++ b/server/routes_messages.ts @@ -9,7 +9,6 @@ export function createMessagesRoutes(withAuth: WithAuth) { // 发送消息 messagesRoutes.post('/', withAuth, async (c) => { try { - const auth = c.get('auth') const apiClient = c.get('apiClient') const { title, content, type, receiver_ids } = await c.req.json() @@ -42,7 +41,10 @@ export function createMessagesRoutes(withAuth: WithAuth) { await apiClient.database.table('user_messages').insert(userMessages) - return c.json({ message: '消息发送成功', id: messageId }, 201) + return c.json({ + message: '消息发送成功', + data: { id: messageId } + }, 201) } catch (error) { console.error('发送消息失败:', error) return c.json({ error: '发送消息失败' }, 500) @@ -74,9 +76,23 @@ export function createMessagesRoutes(withAuth: WithAuth) { if (type) query.where('m.type', type) if (status) query.where('um.status', status) + const countQuery = query.clone() const messages = await query + + // 获取总数用于分页 + const total = await countQuery.count() + const totalCount = Number(total) + const totalPages = Math.ceil(totalCount / pageSize) - return c.json(messages) + return c.json({ + data: messages, + pagination: { + total: totalCount, + current: page, + pageSize, + totalPages + } + }) } catch (error) { console.error('获取消息列表失败:', error) return c.json({ error: '获取消息列表失败' }, 500) @@ -119,7 +135,10 @@ export function createMessagesRoutes(withAuth: WithAuth) { }) } - return c.json(message) + return c.json({ + message: '获取消息成功', + data: message + }) } catch (error) { console.error('获取消息详情失败:', error) return c.json({ error: '获取消息详情失败' }, 500)