Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package upbrella.be.rent.dto.request

data class HistoryFilterRequest(
val refunded: Boolean? = null
val refunded: Boolean? = null,
val storeId: Long? = null,
val paid: Boolean? = null
)
34 changes: 31 additions & 3 deletions src/main/kotlin/upbrella/be/rent/repository/RentRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class RentRepositoryImpl(
.join(history.umbrella, umbrella).fetchJoin()
.join(history.rentStoreMeta, storeMeta).fetchJoin()
.leftJoin(history.returnStoreMeta, storeMeta).fetchJoin()
.where(filterRefunded(filter))
.where(
filterRefunded(filter),
filterPaid(filter),
filterStore(filter)
)
.orderBy(history.id.desc())
.offset(pageable.offset)
.limit(pageable.pageSize.toLong())
Expand Down Expand Up @@ -57,7 +61,11 @@ class RentRepositoryImpl(
.join(history.umbrella, umbrella)
.join(history.rentStoreMeta, storeMeta)
.leftJoin(history.returnStoreMeta, storeMeta)
.where(filterRefunded(filter))
.where(
filterRefunded(filter),
filterPaid(filter),
filterStore(filter)
)
.orderBy(history.id.desc())
.offset(pageable.offset)
.limit(pageable.pageSize.toLong())
Expand All @@ -67,7 +75,11 @@ class RentRepositoryImpl(
override fun countAll(filter: HistoryFilterRequest, pageable: Pageable): Long {
return queryFactory
.selectFrom(history)
.where(filterRefunded(filter))
.where(
filterRefunded(filter),
filterPaid(filter),
filterStore(filter)
)
.fetch()
.size.toLong()
}
Expand Down Expand Up @@ -96,4 +108,20 @@ class RentRepositoryImpl(

return history.refundedAt.isNull
}

private fun filterPaid(filter: HistoryFilterRequest): BooleanExpression? {
if (filter.paid == null) {
return null
}

return if (filter.paid == true) {
history.paidAt.isNotNull
} else {
history.paidAt.isNull
}
}

private fun filterStore(filter: HistoryFilterRequest): BooleanExpression? {
return filter.storeId?.let { history.rentStoreMeta.id.eq(it) }
}
}