쿠폰 리스트 가져오기 API 수정
AS-IS: 응답값에 전체 개수 없음 TO-BE: 응답값에 전체 개수 추가
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -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> { | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user