Browse Source

统一了字段命名:将date/title/content改为code/note_date/note,已从routes_date_notes.ts中移除所有user_id相关引用

yourname 6 months ago
parent
commit
b1da2d0e84
2 changed files with 16 additions and 19 deletions
  1. 2 0
      server/router.ts
  2. 14 19
      server/routes_date_notes.ts

+ 2 - 0
server/router.ts

@@ -22,6 +22,7 @@ import { createClassRoomRoutes } from "./routes_classroom.ts"
 import { createStockRoutes } from "./routes_stock.ts";
 import { createClassroomDataRoutes } from "./routes_classroom_data.ts";
 import { createSubmissionRoutes } from "./routes_submission_records.ts";
+import { createDateNotesRoutes } from "./routes_date_notes.ts";
 
 export function createRouter(apiClient: APIClient, moduleDir: string , auth: Auth) {
   const router = new Hono()
@@ -53,6 +54,7 @@ export function createRouter(apiClient: APIClient, moduleDir: string , auth: Aut
   api.route('/stock', createStockRoutes(withAuth));
   api.route('/classroom-datas', createClassroomDataRoutes(withAuth));
   api.route('/submission-records', createSubmissionRoutes(withAuth));
+  api.route('/date-notes', createDateNotesRoutes(withAuth));
   
 
   // 注册API路由到主路由器

+ 14 - 19
server/routes_date_notes.ts

@@ -8,9 +8,9 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
   dateNotesRoutes.post('/', withAuth, async (c) => {
     try {
       const apiClient = c.get('apiClient')
-      const { date, title, content } = await c.req.json()
+      const { code, note_date, note } = await c.req.json()
 
-      if (!date || !title || !content) {
+      if (!code || !note_date || !note) {
         return c.json({ error: '缺少必要参数' }, 400)
       }
 
@@ -18,10 +18,9 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
       if (!user) return c.json({ error: '未授权访问' }, 401)
       
       const [noteId] = await apiClient.database.table('date_notes').insert({
-        date,
-        title,
-        content,
-        user_id: user.id,
+        code,
+        note_date,
+        note,
         created_at: apiClient.database.fn.now(),
         updated_at: apiClient.database.fn.now()
       })
@@ -50,14 +49,13 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
       if (!user) return c.json({ error: '未授权访问' }, 401)
       
       const query = apiClient.database.table('date_notes')
-        .where('user_id', user.id)
-        .orderBy('date', 'desc')
+        .orderBy('note_date', 'desc')
         .limit(pageSize)
         .offset((page - 1) * pageSize)
 
       // 日期范围查询
-      if (startDate) query.where('date', '>=', startDate)
-      if (endDate) query.where('date', '<=', endDate)
+      if (startDate) query.where('note_date', '>=', startDate)
+      if (endDate) query.where('note_date', '<=', endDate)
 
       const countQuery = query.clone()
       const notes = await query
@@ -78,7 +76,7 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
       })
     } catch (error) {
       console.error('获取日期笔记列表失败:', error)
-      return c.json({ error: '获取日期笔记列表失败' }, 500)
+      return c.json({ error: '获取日期笔记列表失败',message: error }, 500)
     }
   })
 
@@ -94,7 +92,6 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
       
       const note = await apiClient.database.table('date_notes')
         .where('id', noteId)
-        .where('user_id', user.id)
         .first()
 
       if (!note) {
@@ -115,9 +112,9 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
   dateNotesRoutes.put('/:id', withAuth, async (c) => {
     try {
       const apiClient = c.get('apiClient')
-      const { date, title, content } = await c.req.json()
+      const { code, note_date, note } = await c.req.json()
 
-      if (!date || !title || !content) {
+      if (!code || !note_date || !note) {
         return c.json({ error: '缺少必要参数' }, 400)
       }
 
@@ -128,11 +125,10 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
 
       await apiClient.database.table('date_notes')
         .where('id', noteId)
-        .where('user_id', user.id)
         .update({
-          date,
-          title,
-          content,
+          code,
+          note_date,
+          note,
           updated_at: apiClient.database.fn.now()
         })
 
@@ -154,7 +150,6 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
 
       await apiClient.database.table('date_notes')
         .where('id', noteId)
-        .where('user_id', user.id)
         .delete()
 
       return c.json({ message: '日期笔记已删除' })