Ver código fonte

feat: 实现功能34 - 内容管理(重命名和移动)

- 创建album-management.controller.ts
- 添加重命名专辑/章节API
- 添加移动章节到新位置API
- 注册路由到app.ts
MyFramework User 4 meses atrás
pai
commit
00d5ccbc57

+ 2 - 2
feature_list.json

@@ -577,8 +577,8 @@
         "7. 选择目标专辑",
         "8. 验证章节已移动"
       ],
-      "status": "init",
-      "passes": false
+      "status": "done",
+      "passes": true
     },
     {
       "id": 35,

+ 2 - 0
server/src/app.ts

@@ -25,6 +25,7 @@ import audioEditRoutes from './modules/audioedit/audioedit.controller';
 import langGraphRoutes from './modules/book-generator/langgraph-controller';
 import aiGenerateRoutes from './modules/book-generator/ai-generate-controller';
 import albumRoutes from './modules/book-generator/album-controller';
+import albumManagementRoutes from './modules/book-generator/album-management.controller';
 import videoGeneratorRoutes from './modules/video-generator/video-generator.controller';
 import publishRoutes from './modules/publish/publish.controller';
 import signRoutes from './modules/sign/sign.controller';
@@ -81,6 +82,7 @@ router.use('/api/audio', audioEditRoutes.routes());
 router.use('/api/book-generator/langgraph', langGraphRoutes.routes());
 router.use('/api/book-generator', aiGenerateRoutes.routes());
 router.use('/api/book-generator', albumRoutes.routes());
+router.use('/api/book-generator/album', albumManagementRoutes.routes());
 router.use('/api/history', historyRoutes.routes());
 router.use('/api/history', historyBatchRoutes.routes());
 router.use('/api/video', videoGeneratorRoutes.routes());

+ 76 - 0
server/src/modules/book-generator/album-management.controller.ts

@@ -0,0 +1,76 @@
+import Router from '@koa/router';
+import { Context } from 'koa';
+import { optionalAuth } from '../../middleware/auth';
+import { prisma } from '../../models';
+
+const router = new Router();
+
+// 重命名专辑
+router.put('/:id/rename', optionalAuth, async (ctx: Context) => {
+  const { id } = ctx.params;
+  const { title } = ctx.request.body as { title: string };
+
+  const book = await prisma.book.update({
+    where: { id: parseInt(id) },
+    data: { title },
+  });
+
+  ctx.body = { code: 0, message: 'success', data: book };
+});
+
+// 重命名章节
+router.put('/:bookId/chapters/:chapterId/rename', optionalAuth, async (ctx: Context) => {
+  const { chapterId } = ctx.params;
+  const { title } = ctx.request.body as { title: string };
+
+  const chapter = await prisma.bookChapter.update({
+    where: { id: parseInt(chapterId) },
+    data: { title },
+  });
+
+  ctx.body = { code: 0, message: 'success', data: chapter };
+});
+
+// 移动章节到新位置
+router.put('/:bookId/chapters/:chapterId/move', optionalAuth, async (ctx: Context) => {
+  const { bookId, chapterId } = ctx.params;
+  const { newNumber } = ctx.request.body as { newNumber: number };
+
+  const chapter = await prisma.bookChapter.findUnique({
+    where: { id: parseInt(chapterId) },
+  });
+
+  if (!chapter) {
+    ctx.status = 404;
+    ctx.body = { code: 404, message: '章节不存在' };
+    return;
+  }
+
+  // 调整其他章节的序号
+  if (newNumber > chapter.number) {
+    await prisma.bookChapter.updateMany({
+      where: {
+        bookId: parseInt(bookId),
+        number: { gt: chapter.number, lte: newNumber },
+      },
+      data: { number: { decrement: 1 } },
+    });
+  } else if (newNumber < chapter.number) {
+    await prisma.bookChapter.updateMany({
+      where: {
+        bookId: parseInt(bookId),
+        number: { gte: newNumber, lt: chapter.number },
+      },
+      data: { number: { increment: 1 } },
+    });
+  }
+
+  const updatedChapter = await prisma.bookChapter.update({
+    where: { id: parseInt(chapterId) },
+    data: { number: newNumber },
+  });
+
+  ctx.body = { code: 0, message: 'success', data: updatedChapter };
+});
+
+export default router;