쿠폰 리스트 가져오기 API 수정
AS-IS: 응답값에 전체 개수 없음 TO-BE: 응답값에 전체 개수 추가
This commit is contained in:
parent
209f1f4bd1
commit
3b97364f24
|
@ -8,11 +8,20 @@ import org.springframework.data.jpa.repository.JpaRepository
|
||||||
interface CanCouponRepository : JpaRepository<CanCoupon, Long>, CanCouponQueryRepository
|
interface CanCouponRepository : JpaRepository<CanCoupon, Long>, CanCouponQueryRepository
|
||||||
|
|
||||||
interface CanCouponQueryRepository {
|
interface CanCouponQueryRepository {
|
||||||
|
fun getCouponTotalCount(): Int
|
||||||
fun getCouponList(offset: Long, limit: Long): List<CanCoupon>
|
fun getCouponList(offset: Long, limit: Long): List<CanCoupon>
|
||||||
fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse>
|
fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanCouponQueryRepository {
|
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> {
|
override fun getCouponList(offset: Long, limit: Long): List<CanCoupon> {
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.selectFrom(canCoupon)
|
.selectFrom(canCoupon)
|
||||||
|
|
|
@ -20,12 +20,14 @@ class CanCouponService(
|
||||||
applicationEventPublisher.publishEvent(SqsEvent(type = SqsEventType.GENERATE_COUPON, message = message))
|
applicationEventPublisher.publishEvent(SqsEvent(type = SqsEventType.GENERATE_COUPON, message = message))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCouponList(offset: Long, limit: Long): List<GetCouponListResponse> {
|
fun getCouponList(offset: Long, limit: Long): GetCouponListResponse {
|
||||||
return repository.getCouponList(offset = offset, limit = limit)
|
val totalCount = repository.getCouponTotalCount()
|
||||||
|
|
||||||
|
val items = repository.getCouponList(offset = offset, limit = limit)
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.map {
|
.map {
|
||||||
val useCouponCount = couponNumberRepository.getUseCouponCount(id = it.id!!)
|
val useCouponCount = couponNumberRepository.getUseCouponCount(id = it.id!!)
|
||||||
GetCouponListResponse(
|
GetCouponListItemResponse(
|
||||||
id = it.id!!,
|
id = it.id!!,
|
||||||
couponName = it.couponName,
|
couponName = it.couponName,
|
||||||
can = "${it.can}캔",
|
can = "${it.can}캔",
|
||||||
|
@ -37,6 +39,8 @@ class CanCouponService(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
|
return GetCouponListResponse(totalCount, items)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse> {
|
fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse> {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package kr.co.vividnext.sodalive.can.coupon
|
package kr.co.vividnext.sodalive.can.coupon
|
||||||
|
|
||||||
data class GetCouponListResponse(
|
data class GetCouponListResponse(
|
||||||
|
val totalCount: Int,
|
||||||
|
val items: List<GetCouponListItemResponse>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GetCouponListItemResponse(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val couponName: String,
|
val couponName: String,
|
||||||
val can: String,
|
val can: String,
|
||||||
|
|
Loading…
Reference in New Issue