@@ -23,13 +23,15 @@ import {
23
23
PatchIsRepresentativeSwagger ,
24
24
PatchPostSwagger ,
25
25
} from './post.swagger' ;
26
- import { ApiBearerAuth , ApiParam , ApiTags } from '@nestjs/swagger' ;
26
+ import { ApiBearerAuth , ApiQuery , ApiTags } from '@nestjs/swagger' ;
27
27
import { CreatePostDto } from './dtos/create-post.dto' ;
28
28
import { BaseResponse } from 'src/common/response/dto' ;
29
29
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard' ;
30
30
import { Request } from 'express' ;
31
31
import { GetPostResponse } from './dtos/get-post.dto' ;
32
32
import { PatchPostDto } from './dtos/patch-Post.dto' ;
33
+ import { PageOptionsDto } from './dtos/page-options.dto' ;
34
+ import { PageDto } from './dtos/page.dto' ;
33
35
34
36
@Controller ( 'post' )
35
37
@ApiBearerAuth ( )
@@ -40,21 +42,48 @@ export class PostController {
40
42
41
43
@Get ( '/' )
42
44
@GetPostsSwagger ( '게시글 리스트 조회 API' )
43
- @ApiParam ( { name : 'userId' , required : false , description : 'User ID' } )
45
+ @ApiQuery ( {
46
+ name : 'userId' ,
47
+ required : false ,
48
+ description : 'User ID' ,
49
+ type : Number ,
50
+ } )
51
+ @ApiQuery ( {
52
+ name : 'page' ,
53
+ required : false ,
54
+ description : '페이지 번호' ,
55
+ type : Number ,
56
+ } )
57
+ @ApiQuery ( {
58
+ name : 'take' ,
59
+ required : false ,
60
+ description : '한 페이지에 불러올 데이터 개수' ,
61
+ } )
44
62
async getPosts (
45
63
@Req ( ) req : Request ,
64
+ @Query ( ) pageOptionsDto ?: PageOptionsDto ,
46
65
@Query ( 'userId' ) userId ?: number ,
47
66
) : Promise <
48
- BaseResponse < GetPostsResponse | GetMyPostsResponse | GetOtherPostsResponse >
67
+ BaseResponse <
68
+ PageDto < GetPostsResponse | GetMyPostsResponse | GetOtherPostsResponse >
69
+ >
49
70
> {
50
71
const currentUserId = req . user . id ;
51
72
73
+ const options = pageOptionsDto
74
+ ? {
75
+ ...new PageOptionsDto ( ) ,
76
+ ...pageOptionsDto , // Dto에 전달된 기본값
77
+ }
78
+ : new PageOptionsDto ( ) ;
79
+
52
80
const postsResponse = await this . postService . getPosts (
81
+ options ,
53
82
userId ,
54
83
currentUserId ,
55
84
) ;
56
85
57
- return new BaseResponse ( true , 'SUCCESS ' , postsResponse ) ;
86
+ return new BaseResponse ( true , '게시글 리스트 조회 성공 ' , postsResponse ) ;
58
87
}
59
88
60
89
@Get ( ':postId' )
0 commit comments