parent
38cf9e453d
commit
209f1f4bd1
|
@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping
|
|||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
|
@ -36,4 +37,22 @@ class CanCouponController(private val service: CanCouponService) {
|
|||
|
||||
ApiResponse.ok(service.getCouponList(offset = pageable.offset, limit = pageable.pageSize.toLong()))
|
||||
}
|
||||
|
||||
@GetMapping("/number-list")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
fun getCouponNumberList(
|
||||
@RequestParam couponId: Long,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(
|
||||
service.getCouponNumberList(
|
||||
couponId = couponId,
|
||||
offset = pageable.offset,
|
||||
limit = pageable.pageSize.toLong()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package kr.co.vividnext.sodalive.can.coupon
|
|||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.can.coupon.QCanCoupon.canCoupon
|
||||
import kr.co.vividnext.sodalive.can.coupon.QCanCouponNumber.canCouponNumber
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface CanCouponRepository : JpaRepository<CanCoupon, Long>, CanCouponQueryRepository
|
||||
|
||||
interface CanCouponQueryRepository {
|
||||
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 {
|
||||
|
@ -19,4 +21,18 @@ class CanCouponQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) :
|
|||
.limit(limit)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
override fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse> {
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetCouponNumberListResponse(
|
||||
canCouponNumber.id,
|
||||
canCouponNumber.couponNumber,
|
||||
canCouponNumber.member.isNotNull
|
||||
)
|
||||
)
|
||||
.from(canCouponNumber)
|
||||
.where(canCouponNumber.canCoupon.id.eq(couponId))
|
||||
.fetch()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,4 +38,8 @@ class CanCouponService(
|
|||
}
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun getCouponNumberList(couponId: Long, offset: Long, limit: Long): List<GetCouponNumberListResponse> {
|
||||
return repository.getCouponNumberList(couponId = couponId, offset = offset, limit = limit)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package kr.co.vividnext.sodalive.can.coupon
|
||||
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
|
||||
data class GetCouponNumberListResponse @QueryProjection constructor(
|
||||
val couponNumberId: Long,
|
||||
val couponNumber: String,
|
||||
val isUsed: Boolean
|
||||
)
|
Loading…
Reference in New Issue