parent
538d4288bb
commit
c65bad63ca
|
@ -9,7 +9,7 @@ data class CanCoupon(
|
|||
val couponName: String,
|
||||
val can: Int,
|
||||
val couponCount: Int,
|
||||
val validity: LocalDateTime,
|
||||
val isActive: Boolean,
|
||||
val isMultipleUse: Boolean
|
||||
var validity: LocalDateTime,
|
||||
var isActive: Boolean,
|
||||
var isMultipleUse: Boolean
|
||||
) : BaseEntity()
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.springframework.security.access.prepost.PreAuthorize
|
|||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.PutMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
|
@ -33,6 +34,17 @@ class CanCouponController(private val service: CanCouponService) {
|
|||
ApiResponse.ok(service.generateCoupon(request))
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
fun modifyCoupon(
|
||||
@RequestBody request: ModifyCanCouponRequest,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.modifyCoupon(request))
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
fun getCouponList(
|
||||
|
|
|
@ -28,4 +28,10 @@ class CanCouponIssueService(private val couponNumberRepository: CanCouponNumberR
|
|||
}
|
||||
|
||||
private fun isMultipleUse(canCouponNumber: CanCouponNumber) = canCouponNumber.canCoupon!!.isMultipleUse
|
||||
|
||||
fun checkAnyChanges(request: ModifyCanCouponRequest) {
|
||||
if (request.isMultipleUse == null && request.isActive == null && request.validity == null) {
|
||||
throw SodaException("변경사항이 없습니다.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,12 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
|||
import org.springframework.context.ApplicationEventPublisher
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
@Service
|
||||
|
@ -33,6 +36,36 @@ class CanCouponService(
|
|||
applicationEventPublisher.publishEvent(SqsEvent(type = SqsEventType.GENERATE_COUPON, message = message))
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun modifyCoupon(request: ModifyCanCouponRequest) {
|
||||
issueService.checkAnyChanges(request)
|
||||
|
||||
val canCoupon = repository.findByIdOrNull(id = request.couponId)
|
||||
?: throw SodaException("잘못된 쿠폰번호입니다.\n고객센터로 문의해 주시기 바랍니다.")
|
||||
|
||||
if (request.validity != null) {
|
||||
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")
|
||||
val validity = LocalDateTime.parse(request.validity, dateTimeFormatter)
|
||||
.atZone(ZoneId.of("Asia/Seoul"))
|
||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||
.toLocalDateTime()
|
||||
|
||||
if (validity <= canCoupon.validity) {
|
||||
throw SodaException("유효기간은 기존 유효기간 이후 날짜로 설정하실 수 있습니다.")
|
||||
}
|
||||
|
||||
canCoupon.validity = validity
|
||||
}
|
||||
|
||||
if (request.isActive != null) {
|
||||
canCoupon.isActive = request.isActive
|
||||
}
|
||||
|
||||
if (request.isMultipleUse != null) {
|
||||
canCoupon.isMultipleUse = request.isMultipleUse
|
||||
}
|
||||
}
|
||||
|
||||
fun getCouponList(offset: Long, limit: Long): GetCouponListResponse {
|
||||
val totalCount = repository.getCouponTotalCount()
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package kr.co.vividnext.sodalive.can.coupon
|
||||
|
||||
data class ModifyCanCouponRequest(
|
||||
val couponId: Long,
|
||||
val validity: String?,
|
||||
val isMultipleUse: Boolean?,
|
||||
val isActive: Boolean?
|
||||
)
|
Loading…
Reference in New Issue