@@ -11,6 +11,7 @@ import com.ddd.sonnypolabobe.jooq.polabo.tables.Polaroid
11
11
import org.jooq.DSLContext
12
12
import org.jooq.Record6
13
13
import org.jooq.Record7
14
+ import org.jooq.impl.DSL
14
15
import org.springframework.stereotype.Repository
15
16
import java.time.LocalDateTime
16
17
import java.util.*
@@ -131,7 +132,7 @@ class BoardJooqRepositoryImpl(
131
132
.where(jBoard.USER_ID .eq(userId).and (jBoard.YN .eq(1 )).and (jBoard.ACTIVEYN .eq(1 )))
132
133
.orderBy(jBoard.CREATED_AT .desc())
133
134
.limit(size)
134
- .offset(page * size )
135
+ .offset(page)
135
136
.fetch()
136
137
137
138
return data.map {
@@ -162,7 +163,7 @@ class BoardJooqRepositoryImpl(
162
163
val boardSubQuery =
163
164
this .dslContext.select(jBoard.ID .`as `(" id" ))
164
165
.from(jBoard)
165
- .where(jBoard.USER_ID .eq(userId).and (jPolaroid .YN .eq(1 )).and (jPolaroid .ACTIVEYN .eq(1 )))
166
+ .where(jBoard.USER_ID .eq(userId).and (jBoard .YN .eq(1 )).and (jBoard .ACTIVEYN .eq(1 )))
166
167
.asTable()
167
168
168
169
val data = this .dslContext.select(
@@ -179,26 +180,40 @@ class BoardJooqRepositoryImpl(
179
180
this .dslContext.select(boardSubQuery.field(" id" , ByteArray ::class .java))
180
181
.from(boardSubQuery)
181
182
))
183
+ .orderBy(jBoard.CREATED_AT .desc())
184
+ .limit(size)
185
+ .offset(page)
182
186
183
- return data.map {
187
+ return data
188
+ .map {
184
189
MyBoardDto .Companion .PageListRes (
185
190
id = UuidConverter .byteArrayToUUID(it.get(" id" , ByteArray ::class .java)!! ),
186
191
title = it.get(" title" , String ::class .java)!! ,
187
192
createdAt = it.get(" created_at" , LocalDateTime ::class .java)!! ,
188
193
)
189
- }
194
+ }.distinct()
190
195
}
191
196
192
197
override fun selectTotalCountByParticipant (userId : Long ): Long {
193
198
val jBoard = Board .BOARD
194
199
val jPolaroid = Polaroid .POLAROID
200
+ val boardSubQuery =
201
+ this .dslContext.select(jBoard.ID .`as `(" id" ))
202
+ .from(jBoard)
203
+ .where(jBoard.USER_ID .eq(userId).and (jBoard.YN .eq(1 )).and (jBoard.ACTIVEYN .eq(1 )))
204
+ .asTable()
195
205
return this .dslContext
196
- .selectCount( )
206
+ .select( DSL .countDistinct(jBoard. ID ) )
197
207
.from(jBoard)
198
208
.innerJoin(jPolaroid).on(
199
209
jBoard.ID .eq(jPolaroid.BOARD_ID ).and (jPolaroid.USER_ID .eq(userId))
200
210
.and (jPolaroid.YN .eq(1 )).and (jPolaroid.ACTIVEYN .eq(1 ))
201
211
)
202
- .fetchOne(0 , Long ::class .java) ? : 0L
212
+ .where(jBoard.ID .notIn(
213
+ this .dslContext.select(boardSubQuery.field(" id" , ByteArray ::class .java))
214
+ .from(boardSubQuery)
215
+ ))
216
+ .fetchOne(0 , Long ::class .java)
217
+ ? : 0L
203
218
}
204
219
}
0 commit comments