Skip to content

Commit fd54eb5

Browse files
authored
Merge pull request #33 from DDD-Community/feature/POLABO-108
fix(POLABO-128): 내가 참여한 보드 목록 조건절 수정
2 parents 4160a99 + cd96a8e commit fd54eb5

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/main/kotlin/com/ddd/sonnypolabobe/domain/board/repository/BoardJooqRepositoryImpl.kt

+21-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.ddd.sonnypolabobe.jooq.polabo.tables.Polaroid
1111
import org.jooq.DSLContext
1212
import org.jooq.Record6
1313
import org.jooq.Record7
14+
import org.jooq.impl.DSL
1415
import org.springframework.stereotype.Repository
1516
import java.time.LocalDateTime
1617
import java.util.*
@@ -131,7 +132,7 @@ class BoardJooqRepositoryImpl(
131132
.where(jBoard.USER_ID.eq(userId).and(jBoard.YN.eq(1)).and(jBoard.ACTIVEYN.eq(1)))
132133
.orderBy(jBoard.CREATED_AT.desc())
133134
.limit(size)
134-
.offset(page * size)
135+
.offset(page)
135136
.fetch()
136137

137138
return data.map {
@@ -162,7 +163,7 @@ class BoardJooqRepositoryImpl(
162163
val boardSubQuery =
163164
this.dslContext.select(jBoard.ID.`as`("id"))
164165
.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)))
166167
.asTable()
167168

168169
val data = this.dslContext.select(
@@ -179,26 +180,40 @@ class BoardJooqRepositoryImpl(
179180
this.dslContext.select(boardSubQuery.field("id", ByteArray::class.java))
180181
.from(boardSubQuery)
181182
))
183+
.orderBy(jBoard.CREATED_AT.desc())
184+
.limit(size)
185+
.offset(page)
182186

183-
return data.map {
187+
return data
188+
.map {
184189
MyBoardDto.Companion.PageListRes(
185190
id = UuidConverter.byteArrayToUUID(it.get("id", ByteArray::class.java)!!),
186191
title = it.get("title", String::class.java)!!,
187192
createdAt = it.get("created_at", LocalDateTime::class.java)!!,
188193
)
189-
}
194+
}.distinct()
190195
}
191196

192197
override fun selectTotalCountByParticipant(userId: Long): Long {
193198
val jBoard = Board.BOARD
194199
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()
195205
return this.dslContext
196-
.selectCount()
206+
.select(DSL.countDistinct(jBoard.ID))
197207
.from(jBoard)
198208
.innerJoin(jPolaroid).on(
199209
jBoard.ID.eq(jPolaroid.BOARD_ID).and(jPolaroid.USER_ID.eq(userId))
200210
.and(jPolaroid.YN.eq(1)).and(jPolaroid.ACTIVEYN.eq(1))
201211
)
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
203218
}
204219
}

0 commit comments

Comments
 (0)