Compare commits
No commits in common. "ec022b74d12becd75e499e6ddd3e4b2550409d5d" and "dc42c09ce3d0f92e0aec717266f90fd989cfd67d" have entirely different histories.
ec022b74d1
...
dc42c09ce3
|
@ -1,18 +1,14 @@
|
||||||
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<GetCouponListItemResponse>
|
fun getCouponList(offset: Long, limit: Long): List<CanCoupon>
|
||||||
}
|
}
|
||||||
|
|
||||||
class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanCouponQueryRepository {
|
class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanCouponQueryRepository {
|
||||||
|
@ -24,38 +20,12 @@ class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) :
|
||||||
.size
|
.size
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCouponList(offset: Long, limit: Long): List<GetCouponListItemResponse> {
|
override fun getCouponList(offset: Long, limit: Long): List<CanCoupon> {
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.select(
|
.selectFrom(canCoupon)
|
||||||
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,9 +72,17 @@ 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!!)
|
||||||
it.useCouponCount = useCouponCount
|
GetCouponListItemResponse(
|
||||||
it
|
id = it.id!!,
|
||||||
|
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,18 +1,16 @@
|
||||||
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 @QueryProjection constructor(
|
data class GetCouponListItemResponse(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val couponName: String,
|
val couponName: String,
|
||||||
val can: Int,
|
val can: Int,
|
||||||
val couponCount: Int,
|
val couponCount: Int,
|
||||||
var useCouponCount: Int,
|
val useCouponCount: Int,
|
||||||
val validity: String,
|
val validity: String,
|
||||||
val isMultipleUse: Boolean,
|
val isMultipleUse: Boolean,
|
||||||
val isActive: Boolean
|
val isActive: Boolean
|
||||||
|
|
Loading…
Reference in New Issue