1+ import { useQuery } from '@tanstack/react-query' ;
2+
13import { newRequest } from '@apis/core' ;
24
35import type { EmptySuccessResponse } from '@apis/core/dto' ;
@@ -17,8 +19,15 @@ export const createPostApi = (data: CreatePostRequest) => newRequest.post<Create
1719
1820// 게시글 리스트 조회
1921// 전체 게시글 리스트
20- export const getPostListApi = ( page : number = 1 , take : number = 10 ) =>
21- newRequest . get < GetPostListResponse > ( `/post` , { params : { page, take } } ) ;
22+ export const getPostListApi = async ( { pageParam = 1 } ) => {
23+ const response = await newRequest . get < GetPostListResponse > ( '/post' , {
24+ params : { page : pageParam , take : 10 } ,
25+ } ) ;
26+ return {
27+ posts : response . data . post ,
28+ nextPage : response . data . post . length > 0 ? pageParam + 1 : undefined , // 다음 페이지 여부 확인
29+ } ;
30+ } ;
2231// 유저 게시글 리스트
2332export const getUserPostListApi = ( page : number = 1 , take : number = 10 , userId : number ) =>
2433 newRequest . get < GetUserPostListResponse > ( `/post` , { params : { page, take, userId } } ) ;
@@ -36,3 +45,11 @@ export const deletePostApi = (postId: number) => newRequest.delete<EmptySuccessR
3645// 대표 게시글 지정
3746export const modifyPostRepresentativeStatusApi = ( postId : number ) =>
3847 newRequest . patch < EmptySuccessResponse > ( `/post/${ postId } /is-representative` ) ;
48+
49+ export const usePostDetail = ( postId : number ) => {
50+ return useQuery ( {
51+ queryKey : [ 'postDetail' , postId ] ,
52+ queryFn : ( ) => getPostDetailApi ( postId ) ,
53+ enabled : ! ! postId , // postId가 존재할 때만 요청 수행
54+ } ) ;
55+ } ;
0 commit comments