Skip to content

Commit 9309007

Browse files
authored
Merge pull request #337 from PromptPlace/feat/#335
Feat: 좋아요 프롬프트 목록 응답 DTO 및 조회 로직 업데이트
2 parents af3be77 + d07052d commit 9309007

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

src/prompts/dtos/prompt.like.dto.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ export interface LikePromptResponse {
66
export interface LikedPrompt {
77
prompt_id: number;
88
title: string;
9+
nickname: string;
910
models: string[];
10-
tags: string[];
11+
price: number;
12+
promptContent: string;
13+
imageUrls: string[];
14+
views: number;
15+
downloads: number;
16+
created_at: Date;
1117
}
1218

1319
export interface GetLikedPromptsResponse {

src/prompts/repositories/prompt.like.repository.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,26 @@ export const getLikedPromptsByUser = async (userId: number) => {
3535
select: {
3636
prompt_id: true,
3737
title: true,
38-
models: {
39-
include: {
40-
model: {
41-
select: { name: true },
42-
},
38+
views: true,
39+
downloads: true,
40+
price: true,
41+
prompt: true,
42+
created_at: true,
43+
user: {
44+
select: {
45+
nickname: true,
4346
},
4447
},
45-
categories: {
48+
models: {
4649
include: {
47-
category: {
50+
model: {
4851
select: { name: true },
4952
},
5053
},
5154
},
5255
images: {
5356
select: { image_url: true },
5457
orderBy: { order_index: 'asc' },
55-
take: 1,
5658
},
5759
},
5860
},

src/prompts/services/prompt.like.service.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as promptLikeRepo from '../repositories/prompt.like.repository';
2+
import { GetLikedPromptsResponse, LikedPrompt } from '../dtos/prompt.like.dto';
23
import { AppError } from '../../errors/AppError';
34

45
export const PromptLikeService = {
@@ -16,21 +17,32 @@ export const PromptLikeService = {
1617
await promptLikeRepo.addPromptLike(userId, promptId);
1718
},
1819

19-
async getLikedPrompts(userId: number) {
20+
async getLikedPrompts(userId: number): Promise<GetLikedPromptsResponse> {
2021
const likes = await promptLikeRepo.getLikedPromptsByUser(userId);
21-
22-
return likes.map((like) => {
22+
const likedPromptsData: LikedPrompt[] = likes.map((like) => {
2323
const prompt = like.prompt;
2424
if (!prompt) return null;
2525

26+
const imageUrls = prompt.images.map(img => img.image_url);
27+
2628
return {
2729
prompt_id: prompt.prompt_id,
2830
title: prompt.title,
29-
image_url: prompt.images?.[0]?.image_url || null,
31+
nickname: prompt.user.nickname,
32+
price: prompt.price,
3033
models: prompt.models.map((m: any) => m.model.name),
31-
categories: prompt.categories.map((c: any) => c.category.name),
34+
promptContent: prompt.prompt,
35+
imageUrls: imageUrls,
36+
views: prompt.views,
37+
downloads: prompt.downloads,
38+
created_at: prompt.created_at,
3239
};
33-
});
40+
}).filter((p): p is LikedPrompt => p !== null);
41+
return {
42+
message: "좋아요 누른 프롬프트 목록 조회 성공",
43+
statusCode: 200,
44+
data: likedPromptsData,
45+
};
3446
},
3547

3648
async unlikePrompt(userId: number, promptId: number): Promise<void> {

0 commit comments

Comments
 (0)