Merge pull request '캔 쿠폰 조회 로직 수정' (#110) from test into main
Reviewed-on: #110
This commit is contained in:
		| @@ -1,14 +1,18 @@ | |||||||
| package kr.co.vividnext.sodalive.can.coupon | package kr.co.vividnext.sodalive.can.coupon | ||||||
|  |  | ||||||
|  | import com.querydsl.core.types.dsl.DateTimePath | ||||||
|  | import com.querydsl.core.types.dsl.Expressions | ||||||
|  | import com.querydsl.core.types.dsl.StringTemplate | ||||||
| import com.querydsl.jpa.impl.JPAQueryFactory | import com.querydsl.jpa.impl.JPAQueryFactory | ||||||
| import kr.co.vividnext.sodalive.can.coupon.QCanCoupon.canCoupon | import kr.co.vividnext.sodalive.can.coupon.QCanCoupon.canCoupon | ||||||
| import org.springframework.data.jpa.repository.JpaRepository | import org.springframework.data.jpa.repository.JpaRepository | ||||||
|  | import java.time.LocalDateTime | ||||||
|  |  | ||||||
| interface CanCouponRepository : JpaRepository<CanCoupon, Long>, CanCouponQueryRepository | interface CanCouponRepository : JpaRepository<CanCoupon, Long>, CanCouponQueryRepository | ||||||
|  |  | ||||||
| interface CanCouponQueryRepository { | interface CanCouponQueryRepository { | ||||||
|     fun getCouponTotalCount(): Int |     fun getCouponTotalCount(): Int | ||||||
|     fun getCouponList(offset: Long, limit: Long): List<CanCoupon> |     fun getCouponList(offset: Long, limit: Long): List<GetCouponListItemResponse> | ||||||
| } | } | ||||||
|  |  | ||||||
| class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanCouponQueryRepository { | class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanCouponQueryRepository { | ||||||
| @@ -20,12 +24,38 @@ class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : | |||||||
|             .size |             .size | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun getCouponList(offset: Long, limit: Long): List<CanCoupon> { |     override fun getCouponList(offset: Long, limit: Long): List<GetCouponListItemResponse> { | ||||||
|         return queryFactory |         return queryFactory | ||||||
|             .selectFrom(canCoupon) |             .select( | ||||||
|  |                 QGetCouponListItemResponse( | ||||||
|  |                     canCoupon.id, | ||||||
|  |                     canCoupon.couponName, | ||||||
|  |                     canCoupon.can, | ||||||
|  |                     canCoupon.couponCount, | ||||||
|  |                     Expressions.ZERO, | ||||||
|  |                     getFormattedDate(canCoupon.validity), | ||||||
|  |                     canCoupon.isMultipleUse, | ||||||
|  |                     canCoupon.isActive | ||||||
|  |                 ) | ||||||
|  |             ) | ||||||
|  |             .from(canCoupon) | ||||||
|             .orderBy(canCoupon.id.desc()) |             .orderBy(canCoupon.id.desc()) | ||||||
|             .offset(offset) |             .offset(offset) | ||||||
|             .limit(limit) |             .limit(limit) | ||||||
|             .fetch() |             .fetch() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private fun getFormattedDate(dateTimePath: DateTimePath<LocalDateTime>): StringTemplate { | ||||||
|  |         return Expressions.stringTemplate( | ||||||
|  |             "DATE_FORMAT({0}, {1})", | ||||||
|  |             Expressions.dateTimeTemplate( | ||||||
|  |                 LocalDateTime::class.java, | ||||||
|  |                 "CONVERT_TZ({0},{1},{2})", | ||||||
|  |                 dateTimePath, | ||||||
|  |                 "UTC", | ||||||
|  |                 "Asia/Seoul" | ||||||
|  |             ), | ||||||
|  |             "%Y-%m-%d" | ||||||
|  |         ) | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -72,17 +72,9 @@ class CanCouponService( | |||||||
|         val items = repository.getCouponList(offset = offset, limit = limit) |         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) | ||||||
|                 GetCouponListItemResponse( |                 it.useCouponCount = useCouponCount | ||||||
|                     id = it.id!!, |                 it | ||||||
|                     couponName = it.couponName, |  | ||||||
|                     can = it.can, |  | ||||||
|                     couponCount = it.couponCount, |  | ||||||
|                     useCouponCount = useCouponCount, |  | ||||||
|                     validity = it.validity.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), |  | ||||||
|                     isMultipleUse = it.isMultipleUse, |  | ||||||
|                     isActive = it.isActive |  | ||||||
|                 ) |  | ||||||
|             } |             } | ||||||
|             .toList() |             .toList() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,16 +1,18 @@ | |||||||
| package kr.co.vividnext.sodalive.can.coupon | package kr.co.vividnext.sodalive.can.coupon | ||||||
|  |  | ||||||
|  | import com.querydsl.core.annotations.QueryProjection | ||||||
|  |  | ||||||
| data class GetCouponListResponse( | data class GetCouponListResponse( | ||||||
|     val totalCount: Int, |     val totalCount: Int, | ||||||
|     val items: List<GetCouponListItemResponse> |     val items: List<GetCouponListItemResponse> | ||||||
| ) | ) | ||||||
|  |  | ||||||
| data class GetCouponListItemResponse( | data class GetCouponListItemResponse @QueryProjection constructor( | ||||||
|     val id: Long, |     val id: Long, | ||||||
|     val couponName: String, |     val couponName: String, | ||||||
|     val can: Int, |     val can: Int, | ||||||
|     val couponCount: Int, |     val couponCount: Int, | ||||||
|     val useCouponCount: Int, |     var useCouponCount: Int, | ||||||
|     val validity: String, |     val validity: String, | ||||||
|     val isMultipleUse: Boolean, |     val isMultipleUse: Boolean, | ||||||
|     val isActive: Boolean |     val isActive: Boolean | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user