@@ -27,6 +27,7 @@ import { CreatePostDto } from './dtos/create-post.dto';
27
27
import { BaseResponse } from 'src/common/response/dto' ;
28
28
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard' ;
29
29
import { Request } from 'express' ;
30
+ import { GetPostResponse } from './dtos/get-post.dto' ;
30
31
import { PatchPostDto } from './dtos/patch-Post.dto' ;
31
32
32
33
@Controller ( 'post' )
@@ -54,10 +55,50 @@ export class PostController {
54
55
return new BaseResponse ( true , 'SUCCESS' , postsResponse ) ;
55
56
}
56
57
57
- @Get ( )
58
+ @Get ( ':postId' )
58
59
@GetPostSwagger ( '게시글 상세 조회 API' )
59
- getPost ( ) {
60
- // return this.userService.getHello();
60
+ async getPost (
61
+ @Param ( 'postId' ) postId : number ,
62
+ @Req ( ) req : Request ,
63
+ ) : Promise < BaseResponse < GetPostResponse > > {
64
+ const currentUserId = req . user . userId ;
65
+
66
+ await this . postService . validatePost ( postId ) ;
67
+
68
+ const post = await this . postService . getPost ( postId ) ;
69
+
70
+ const postResponse : GetPostResponse = {
71
+ post : {
72
+ content : post . content ,
73
+ createdAt : post . createdAt ,
74
+ postImages : post . postImages
75
+ . filter ( ( image ) => image . status === 'activated' )
76
+ . map ( ( image ) => ( {
77
+ url : image . url ,
78
+ orderNum : image . orderNum ,
79
+ } ) ) ,
80
+ postClothings : post . postClothings
81
+ . filter ( ( postClothing ) => postClothing . status === 'activated' )
82
+ . map ( ( postClothing ) => ( {
83
+ imageUrl : postClothing . clothing . imageUrl ,
84
+ brandName : postClothing . clothing . brandName ,
85
+ modelName : postClothing . clothing . modelName ,
86
+ modelNumber : postClothing . clothing . modelNumber ,
87
+ url : postClothing . clothing . url ,
88
+ } ) ) ,
89
+ likeCount : post . postLikes . length ,
90
+ commentCount : post . postComments . length ,
91
+ isPostLike : this . postService . checkIsPostLiked ( post , currentUserId ) ,
92
+ user : {
93
+ userId : post . user . id ,
94
+ nickname : post . user . nickname ,
95
+ profilePictureUrl : post . user . profilePictureUrl ,
96
+ } ,
97
+ isPostWriter : post . user . id === currentUserId ,
98
+ } ,
99
+ } ;
100
+
101
+ return new BaseResponse ( true , '게시글 조회 성공' , postResponse ) ;
61
102
}
62
103
63
104
@Post ( )
0 commit comments