feat(gift): 선물 받을 주소 관리자 서비스를 추가한다
This commit is contained in:
@@ -4,6 +4,8 @@ import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftCategory
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftCategoryRepository
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftDeliveryRepository
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftMailbox
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftMailboxRepository
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftRepository
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftSizePrice
|
||||
import kr.co.vividnext.sodalive.v2.gift.adapter.out.persistence.GiftSizePriceRepository
|
||||
@@ -41,6 +43,14 @@ data class GiftSizePriceCommand(
|
||||
val isActive: Boolean
|
||||
)
|
||||
|
||||
data class GiftMailboxCommand(
|
||||
val name: String,
|
||||
val phoneNumber: String,
|
||||
val zipCode: String,
|
||||
val address: String,
|
||||
val addressDetail: String?
|
||||
)
|
||||
|
||||
data class GiftSizePriceResult(
|
||||
val sizeCode: GiftSize,
|
||||
val sizeName: String,
|
||||
@@ -62,8 +72,31 @@ class GiftAdminService(
|
||||
private val sizePriceRepository: GiftSizePriceRepository,
|
||||
private val giftRepository: GiftRepository,
|
||||
private val giftDeliveryRepository: GiftDeliveryRepository,
|
||||
private val giftMailboxRepository: GiftMailboxRepository,
|
||||
private val giftPushService: GiftPushService
|
||||
) {
|
||||
@Transactional(readOnly = true)
|
||||
fun getMailbox(): GiftMailboxResult? = giftMailboxRepository.findByIdOrNull(GiftMailbox.SINGLETON_ID)?.toResult()
|
||||
|
||||
@Transactional
|
||||
fun updateMailbox(command: GiftMailboxCommand): GiftMailboxResult {
|
||||
validateMailbox(command)
|
||||
val mailbox = giftMailboxRepository.findByIdOrNull(GiftMailbox.SINGLETON_ID)
|
||||
?: GiftMailbox(
|
||||
name = command.name,
|
||||
phoneNumber = command.phoneNumber,
|
||||
zipCode = command.zipCode,
|
||||
address = command.address,
|
||||
addressDetail = command.addressDetail?.takeIf { it.isNotBlank() }
|
||||
)
|
||||
mailbox.name = command.name
|
||||
mailbox.phoneNumber = command.phoneNumber
|
||||
mailbox.zipCode = command.zipCode
|
||||
mailbox.address = command.address
|
||||
mailbox.addressDetail = command.addressDetail?.takeIf { it.isNotBlank() }
|
||||
return giftMailboxRepository.save(mailbox).toResult()
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
fun getCategories(): List<GiftCategoryResult> = categoryRepository.findAll().map { it.toResult() }
|
||||
|
||||
@@ -198,6 +231,22 @@ class GiftAdminService(
|
||||
if (command.salePriceCan <= 0 || command.salePriceCan > command.basePriceCan) throw invalidRequest()
|
||||
}
|
||||
|
||||
private fun validateMailbox(command: GiftMailboxCommand) {
|
||||
if (
|
||||
command.name.isBlank() ||
|
||||
command.name.length > 50 ||
|
||||
command.phoneNumber.isBlank() ||
|
||||
command.phoneNumber.length > 30 ||
|
||||
command.zipCode.isBlank() ||
|
||||
command.zipCode.length > 20 ||
|
||||
command.address.isBlank() ||
|
||||
command.address.length > 255 ||
|
||||
(command.addressDetail?.length ?: 0) > 255
|
||||
) {
|
||||
throw invalidRequest()
|
||||
}
|
||||
}
|
||||
|
||||
private fun GiftCategory.toResult() = GiftCategoryResult(
|
||||
categoryId = id ?: throw invalidRequest(),
|
||||
classificationNumber = classificationNumber,
|
||||
@@ -217,6 +266,15 @@ class GiftAdminService(
|
||||
isActive = isActive
|
||||
)
|
||||
|
||||
private fun GiftMailbox.toResult() = GiftMailboxResult(
|
||||
name = name,
|
||||
address = formatAddress(zipCode, address, addressDetail),
|
||||
phoneNumber = phoneNumber
|
||||
)
|
||||
|
||||
private fun formatAddress(zipCode: String, address: String, detail: String?) =
|
||||
"($zipCode) $address" + if (detail.isNullOrBlank()) "" else ", $detail"
|
||||
|
||||
private fun invalidRequest() = SodaException(messageKey = "common.error.invalid_request")
|
||||
|
||||
private companion object {
|
||||
|
||||
Reference in New Issue
Block a user