Skip to content

Commit f93b01a

Browse files
committed
2 parents e364c13 + 3ef114e commit f93b01a

File tree

3 files changed

+35
-165
lines changed

3 files changed

+35
-165
lines changed

src/post/dtos/get-post.dto.ts

-151
This file was deleted.

src/post/dtos/post.response.ts

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiProperty } from '@nestjs/swagger';
1+
import { ApiProperty, OmitType } from '@nestjs/swagger';
22
import { Type } from 'class-transformer';
33

44
class PostImageDto {
@@ -15,6 +15,26 @@ class PostImageDto {
1515
orderNum: number;
1616
}
1717

18+
class UserDto {
19+
@ApiProperty({
20+
example: '작성자 번호',
21+
description: 'userId',
22+
})
23+
userId: number;
24+
25+
@ApiProperty({
26+
example: 'nickname',
27+
description: '사용자의 닉네임',
28+
})
29+
nickname: string;
30+
31+
@ApiProperty({
32+
example: 'http://example.com/image.jpg',
33+
description: '사용자의 프로필 사진 URL',
34+
})
35+
profilePictureUrl: string;
36+
}
37+
1838
class PostClothingDto {
1939
@ApiProperty({
2040
example: 'http://example.com/clothing.jpg',
@@ -88,7 +108,9 @@ export class PostResponse {
88108
isRepresentative: boolean;
89109
}
90110

91-
export class PostDetailResponse extends PostResponse {
111+
class PostDetailDto extends OmitType(PostResponse, ['userId']) {}
112+
113+
export class PostDetailResponse extends PostDetailDto {
92114
@ApiProperty({
93115
example: '2024-10-11T09:00:00.000Z',
94116
description: '생성 시각',
@@ -102,16 +124,11 @@ export class PostDetailResponse extends PostResponse {
102124
updatedAt: string;
103125

104126
@ApiProperty({
105-
example: 'nickname',
106-
description: '사용자의 닉네임',
107-
})
108-
userNickname: string;
109-
110-
@ApiProperty({
111-
example: 'http://example.com/image.jpg',
112-
description: '사용자의 프로필 사진 URL',
127+
type: UserDto,
128+
description: '게시물 작성자 정보입니다.',
113129
})
114-
userProfilePictureUrl: string;
130+
@Type(() => UserDto)
131+
user: UserDto;
115132

116133
@ApiProperty({
117134
example: 10,

src/post/post.service.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ export class PostService {
410410
)
411411
.leftJoinAndSelect('post.user', 'user')
412412
.leftJoinAndSelect('post.postLikes', 'postLike')
413+
.leftJoinAndSelect('postLike.user', 'postLikeUser')
413414
.leftJoinAndSelect('post.postComments', 'postComment')
415+
.leftJoinAndSelect('postComment.user', 'postCommentUser')
414416
.leftJoinAndSelect(
415417
'post.postClothings',
416418
'postClothing',
@@ -442,7 +444,11 @@ export class PostService {
442444
): PostDetailResponse {
443445
return {
444446
postId: post.id,
445-
userId: post.user.id,
447+
user: {
448+
userId: post.user.id,
449+
nickname: post.user.nickname,
450+
profilePictureUrl: post.user.profilePictureUrl,
451+
},
446452
content: post.content,
447453
isRepresentative: post.isRepresentative,
448454
postStyletags: post.postStyletags?.map((tag) => tag.styletag.tag),
@@ -460,8 +466,6 @@ export class PostService {
460466
postLikesCount: post.postLikes.length,
461467
postCommentsCount: post.postComments.length,
462468
isPostLike: this.checkIsPostLiked(post, currentUserId),
463-
userNickname: post.user.nickname,
464-
userProfilePictureUrl: post.user.profilePictureUrl,
465469
createdAt: dayjs(post.createdAt).format('YYYY-MM-DDTHH:mm:ssZ'),
466470
updatedAt: dayjs(post.updatedAt).format('YYYY-MM-DDTHH:mm:ssZ'),
467471
};

0 commit comments

Comments
 (0)