@@ -70,60 +70,36 @@ export const BookmarkRepository = {
7070 } ,
7171
7272 /**
73- * 사용자의 북마크 목록 조회 (커서 기반 페이징)
73+ * 사용자의 북마크 목록 조회
7474 */
7575 async findBookmarksByUserId ( userId , dto ) {
76- const { sort, limit , cursor , excludeFullSlots = false } = dto ;
76+ const { sort, page , limit , excludeFullSlots = false } = dto ;
7777
7878 const baseCondition = {
79- userId : BigInt ( userId )
79+ userId : BigInt ( userId )
8080 } ;
8181
8282 let whereCondition = { ...baseCondition } ;
8383 let orderBy = [ ] ;
8484
85- if ( cursor ) {
86- const decodedCursor = JSON . parse ( Buffer . from ( cursor , 'base64' ) . toString ( ) ) ;
87- switch ( sort ) {
88- case 'latest' : // 최신순 정렬
89- whereCondition . createdAt = { lt : new Date ( decodedCursor . created_at ) } ;
90- orderBy = [ { createdAt : 'desc' } , { id : 'desc' } ] ;
91- break ;
92- case 'price_low' : // 저가순 정렬
93- whereCondition . OR = [
94- { commission : { minPrice : { gt : decodedCursor . min_price } } } ,
95- {
96- commission : { minPrice : decodedCursor . min_price } ,
97- createdAt : { lt : new Date ( decodedCursor . created_at ) }
98- }
99- ] ;
100- orderBy = [ { commission : { minPrice : 'asc' } } , { createdAt : 'desc' } ] ;
101- break ;
102- case 'price_high' : // 고가순 정렬
103- whereCondition . OR = [
104- { commission : { minPrice : { lt : decodedCursor . min_price } } } ,
105- {
106- commission : { minPrice : decodedCursor . min_price } ,
107- createdAt : { lt : new Date ( decodedCursor . created_at ) }
108- }
109- ] ;
110- orderBy = [ { commission : { minPrice : 'desc' } } , { createdAt : 'desc' } ] ;
111- break ;
112- }
113- } else {
114- switch ( sort ) {
115- case 'latest' :
116- orderBy = [ { createdAt : 'desc' } , { id : 'desc' } ] ;
117- break ;
118- case 'price_low' :
119- orderBy = [ { commission : { minPrice : 'asc' } } , { createdAt : 'desc' } ] ;
120- break ;
121- case 'price_high' :
122- orderBy = [ { commission : { minPrice : 'desc' } } , { createdAt : 'desc' } ] ;
123- break ;
124- }
85+ // 정렬 조건 설정
86+ switch ( sort ) {
87+ case 'latest' :
88+ orderBy = [ { createdAt : 'desc' } , { id : 'desc' } ] ;
89+ break ;
90+ case 'price_low' :
91+ orderBy = [ { commission : { minPrice : 'asc' } } , { createdAt : 'desc' } ] ;
92+ break ;
93+ case 'price_high' :
94+ orderBy = [ { commission : { minPrice : 'desc' } } , { createdAt : 'desc' } ] ;
95+ break ;
96+ default :
97+ orderBy = [ { createdAt : 'desc' } , { id : 'desc' } ] ;
12598 }
12699
100+ // 페이지네이션 계산
101+ const skip = ( page - 1 ) * limit ;
102+
127103 return await prisma . bookmark . findMany ( {
128104 where : whereCondition ,
129105 include : {
@@ -165,7 +141,8 @@ export const BookmarkRepository = {
165141 }
166142 } ,
167143 orderBy,
168- take : excludeFullSlots ? 100 : limit + 1 , // hasNext 확인용
144+ skip,
145+ take : limit
169146 } ) ;
170147 } ,
171148
0 commit comments