캔 쿠폰 시스템 #107

Merged
klaus merged 12 commits from test into main 2024-01-03 11:28:48 +00:00
3 changed files with 21 additions and 3 deletions
Showing only changes of commit 3b97364f24 - Show all commits

View File

@ -8,11 +8,20 @@ import org.springframework.data.jpa.repository.JpaRepository
interface CanCouponRepository : JpaRepository<CanCoupon, Long>, CanCouponQueryRepository
interface CanCouponQueryRepository {
fun getCouponTotalCount(): Int
fun getCouponList(offset: Long, limit: Long): List<CanCoupon>
fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse>
}
class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanCouponQueryRepository {
override fun getCouponTotalCount(): Int {
return queryFactory
.select(canCoupon.id)
.from(canCoupon)
.fetch()
.size
}
override fun getCouponList(offset: Long, limit: Long): List<CanCoupon> {
return queryFactory
.selectFrom(canCoupon)

View File

@ -20,12 +20,14 @@ class CanCouponService(
applicationEventPublisher.publishEvent(SqsEvent(type = SqsEventType.GENERATE_COUPON, message = message))
}
fun getCouponList(offset: Long, limit: Long): List<GetCouponListResponse> {
return repository.getCouponList(offset = offset, limit = limit)
fun getCouponList(offset: Long, limit: Long): GetCouponListResponse {
val totalCount = repository.getCouponTotalCount()
val items = repository.getCouponList(offset = offset, limit = limit)
.asSequence()
.map {
val useCouponCount = couponNumberRepository.getUseCouponCount(id = it.id!!)
GetCouponListResponse(
GetCouponListItemResponse(
id = it.id!!,
couponName = it.couponName,
can = "${it.can}",
@ -37,6 +39,8 @@ class CanCouponService(
)
}
.toList()
return GetCouponListResponse(totalCount, items)
}
fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse> {

View File

@ -1,6 +1,11 @@
package kr.co.vividnext.sodalive.can.coupon
data class GetCouponListResponse(
val totalCount: Int,
val items: List<GetCouponListItemResponse>
)
data class GetCouponListItemResponse(
val id: Long,
val couponName: String,
val can: String,