diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c929933..0eca298 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -122,7 +122,7 @@ model Room { messages RoomMessage[] participants RoomParticipant[] host User @relation("HostUser", fields: [hostId], references: [userId], onDelete: Cascade) - video YoutubeVideo @relation("VideoOnRoom", fields: [videoId], references: [videoId]) + youtube_videos YoutubeVideo @relation(fields: [videoId], references: [videoId]) @@index([hostId], map: "rooms_host_id_fkey") @@index([videoId], map: "rooms_video_id_fkey") @@ -306,7 +306,7 @@ model YoutubeVideo { duration String? @db.VarChar(20) uploadedAt DateTime? @map("uploaded_at") createdAt DateTime @default(now()) @map("created_at") - rooms Room[] @relation("VideoOnRoom") + rooms Room[] @@map("youtube_videos") } diff --git a/src/routes/collectionRoutes.ts b/src/routes/collectionRoutes.ts index 0dc437c..a1e705e 100644 --- a/src/routes/collectionRoutes.ts +++ b/src/routes/collectionRoutes.ts @@ -104,6 +104,51 @@ router.get('/', requireAuth, collectionController.getCollections); */ router.get('/:collectionId', requireAuth, collectionController.getCollectionDetail); +/** + * @swagger + * /api/collections/order: + * put: + * summary: 컬렉션 순서 변경 + * tags: [Collections] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/ReorderCollectionsDto' + * example: + * collectionOrders: + * - collectionId: 123 + * order: 1 + * - collectionId: 124 + * order: 2 + * responses: + * 200: + * description: 컬렉션 순서 변경 성공 + * + * components: + * schemas: + * ReorderCollectionsDto: + * type: object + * properties: + * collectionOrders: + * type: array + * items: + * type: object + * properties: + * collectionId: + * type: integer + * example: 123 + * order: + * type: integer + * example: 1 + * required: + * - collectionOrders + */ +router.put('/order', requireAuth, collectionController.updateCollectionOrder); + /** * @swagger * /api/collections/{collectionId}: @@ -154,32 +199,6 @@ router.put('/:collectionId', requireAuth, collectionController.updateCollection) */ router.delete('/:collectionId', requireAuth, collectionController.deleteCollection); -/** - * @swagger - * /api/collections/order: - * put: - * summary: 컬렉션 순서 변경 - * tags: [Collections] - * security: - * - bearerAuth: [] - * requestBody: - * required: true - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/ReorderCollectionsDto' - * example: - * collectionOrders: - * - collectionId: 123 - * order: 1 - * - collectionId: 124 - * order: 2 - * responses: - * 200: - * description: 컬렉션 순서 변경 성공 - */ -router.put('/order', requireAuth, collectionController.updateCollectionOrder); - /** * 컬렉션 공유하기 */ diff --git a/src/services/bookmarkService.ts b/src/services/bookmarkService.ts index e30a964..a8b91ea 100644 --- a/src/services/bookmarkService.ts +++ b/src/services/bookmarkService.ts @@ -43,7 +43,7 @@ type BookmarkWithRelations = Prisma.BookmarkGetPayload<{ include: { room: { include: { - video: true; // Room.video (YoutubeVideo) + youtube_videos: true; // Room.video (YoutubeVideo) }; }; collection: { @@ -71,7 +71,7 @@ export const getBookmarks = async (userId: number, options: GetBookmarksOptions) const rows: BookmarkWithRelations[] = await prisma.bookmark.findMany({ where: baseWhere, include: { - room: { include: { video: true } }, + room: { include: { youtube_videos: true } }, collection: { select: { title: true } }, }, orderBy: { createdAt: 'desc' }, @@ -108,8 +108,8 @@ export const getBookmarks = async (userId: number, options: GetBookmarksOptions) for (const b of list) { const roomId = b.roomId; const roomName = b.room?.roomName ?? null; - const videoTitle = b.room?.video?.title ?? null; - const videoThumbnail = b.room?.video?.thumbnail ?? null; + const videoTitle = b.room?.youtube_videos?.title ?? null; + const videoThumbnail = b.room?.youtube_videos?.thumbnail ?? null; const bookmarkCollectionTitle = b.collection?.title ?? null; let idx = map.get(roomId); @@ -246,7 +246,7 @@ export const createRoomFromBookmark = async ( include: { room: { include: { - video: true, + youtube_videos: true, }, }, }, @@ -256,7 +256,7 @@ export const createRoomFromBookmark = async ( throw new Error('해당 북마크에 대한 권한이 없습니다.'); } - const videoThumbnail = bookmark.room?.video?.thumbnail ?? ''; + const videoThumbnail = bookmark.room?.youtube_videos?.thumbnail ?? ''; const startTime = startFrom === 'BOOKMARK' ? (bookmark?.timeline ?? 0) : 0; if (!bookmark.room?.videoId) { diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index b0b3b53..938ee6f 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -63,7 +63,7 @@ export const getCollectionDetailById = async ( include: { room: { include: { - video: true, + youtube_videos: true, }, }, }, @@ -107,8 +107,8 @@ export const getCollectionDetailById = async ( acc[room.roomId] = { roomId: room.roomId, roomTitle: room.roomName, - videoTitle: room.video.title, - videoThumbnail: room.video.thumbnail || '', + videoTitle: room.youtube_videos.title, + videoThumbnail: room.youtube_videos.thumbnail || '', bookmarks: [], }; }