-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from hanghae-0001/feature/order-cancel
Feature/order cancel
- Loading branch information
Showing
61 changed files
with
921 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
commerce-api/src/main/kotlin/com/hanghae/commerce/claim/application/OrderCancelFacade.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.hanghae.commerce.claim.application | ||
|
||
import com.hanghae.commerce.claim.domain.OrderCancelService | ||
import com.hanghae.commerce.claim.domain.OrderCancelValidator | ||
import com.hanghae.commerce.claim.domain.command.OrderCancelCommand | ||
import com.hanghae.commerce.order.domain.OrderReader | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class OrderCancelFacade( | ||
private val orderCancelValidator: OrderCancelValidator, | ||
private val orderCancelService: OrderCancelService, | ||
private val orderReader: OrderReader, | ||
) { | ||
fun cancel(command: OrderCancelCommand) { | ||
val order = orderReader.read(command.orderId) | ||
orderCancelValidator.validate(command.bankAccount) | ||
orderCancelService.cancel(command, order) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
commerce-api/src/main/kotlin/com/hanghae/commerce/claim/domain/OrderCancelCompletedEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.hanghae.commerce.claim.domain | ||
|
||
import com.hanghae.commerce.event.Event | ||
import com.hanghae.commerce.payment.domain.BankAccount | ||
|
||
data class OrderCancelCompletedEvent( | ||
val orderId: String, | ||
val bankAccount: BankAccount?, | ||
) : Event |
24 changes: 24 additions & 0 deletions
24
commerce-api/src/main/kotlin/com/hanghae/commerce/claim/domain/OrderCancelService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.hanghae.commerce.claim.domain | ||
|
||
import com.hanghae.commerce.claim.domain.command.OrderCancelCommand | ||
import com.hanghae.commerce.event.CommerceEventPublisher | ||
import com.hanghae.commerce.order.domain.OrderWriter | ||
import com.hanghae.commerce.order.domain.Order | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class OrderCancelService( | ||
private val orderWriter: OrderWriter, | ||
private val eventPublisher: CommerceEventPublisher, | ||
) { | ||
fun cancel(command: OrderCancelCommand, order: Order) { | ||
order.cancel(command.reason) | ||
orderWriter.write(order) | ||
eventPublisher.publish( | ||
OrderCancelCompletedEvent( | ||
orderId = command.orderId, | ||
bankAccount = command.bankAccount, | ||
), | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
commerce-api/src/main/kotlin/com/hanghae/commerce/claim/domain/OrderCancelValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.hanghae.commerce.claim.domain | ||
|
||
import com.hanghae.commerce.payment.domain.BankAccount | ||
import com.hanghae.commerce.payment.domain.BankAccountValidator | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class OrderCancelValidator( | ||
private val bankAccountValidator: BankAccountValidator, | ||
) { | ||
fun validate(command: BankAccount?) { | ||
validateRefundableBankAccount(command) | ||
} | ||
|
||
private fun validateRefundableBankAccount(command: BankAccount?) { | ||
if (command == null) { | ||
return | ||
} | ||
require(bankAccountValidator.validate(command)) { "Invalid bank account" } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
commerce-api/src/main/kotlin/com/hanghae/commerce/claim/domain/command/OrderCancelCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.hanghae.commerce.claim.domain.command | ||
|
||
import com.hanghae.commerce.payment.domain.BankAccount | ||
data class OrderCancelCommand( | ||
val orderId: String, | ||
val userId: String, | ||
val reason: String, | ||
val bankAccount: BankAccount? = null, | ||
) |
24 changes: 24 additions & 0 deletions
24
commerce-api/src/main/kotlin/com/hanghae/commerce/claim/presentation/ClaimController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.hanghae.commerce.claim.presentation | ||
|
||
import com.hanghae.commerce.claim.application.OrderCancelFacade | ||
import com.hanghae.commerce.claim.presentation.dto.OrderCancelRequest | ||
import com.hanghae.commerce.claim.presentation.dto.toCommand | ||
import org.springframework.http.ResponseEntity | ||
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.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/claims") | ||
class ClaimController( | ||
private val claimFacade: OrderCancelFacade, | ||
) { | ||
@PostMapping("/cancel") | ||
fun cancel( | ||
@RequestBody request: OrderCancelRequest, | ||
): ResponseEntity<String> { | ||
claimFacade.cancel(request.toCommand()) | ||
return ResponseEntity.ok("ok") | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...i/src/main/kotlin/com/hanghae/commerce/claim/presentation/dto/OrderCancelCommandMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.hanghae.commerce.claim.presentation.dto | ||
|
||
import com.hanghae.commerce.claim.domain.command.OrderCancelCommand | ||
|
||
fun OrderCancelRequest.toCommand(): OrderCancelCommand { | ||
return OrderCancelCommand( | ||
orderId = this.orderId, | ||
userId = this.userId, | ||
reason = this.reason, | ||
bankAccount = this.bankAccount, | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
...rce-api/src/main/kotlin/com/hanghae/commerce/claim/presentation/dto/OrderCancelRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.hanghae.commerce.claim.presentation.dto | ||
|
||
import com.hanghae.commerce.payment.domain.BankAccount | ||
|
||
data class OrderCancelRequest( | ||
val orderId: String, | ||
val userId: String, | ||
val reason: String, | ||
val bankAccount: BankAccount, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
commerce-api/src/main/kotlin/com/hanghae/commerce/item/domain/ItemStockEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.hanghae.commerce.item.domain | ||
|
||
import com.hanghae.commerce.claim.domain.OrderCancelCompletedEvent | ||
import com.hanghae.commerce.item.application.ItemStockService | ||
import com.hanghae.commerce.order.domain.OrderReader | ||
import com.hanghae.commerce.order.domain.OrderItem | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ItemStockEventListener( | ||
private val orderReader: OrderReader, | ||
private val itemStockService: ItemStockService, | ||
) { | ||
@EventListener | ||
fun onOrderCanceled(event: OrderCancelCompletedEvent) { | ||
val orderItemList = orderReader.read(event.orderId).orderItemList | ||
restoreItemStock(orderItemList) | ||
} | ||
|
||
private fun restoreItemStock(orderItemList: List<OrderItem>) { | ||
orderItemList.forEach(itemStockService::restore) | ||
} | ||
} |
58 changes: 0 additions & 58 deletions
58
commerce-api/src/main/kotlin/com/hanghae/commerce/order/application/OrderCreateFacade.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
commerce-api/src/main/kotlin/com/hanghae/commerce/order/application/OrderFacade.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.hanghae.commerce.order.application | ||
|
||
import com.hanghae.commerce.item.application.ItemStockService | ||
import com.hanghae.commerce.order.domain.OrderService | ||
import com.hanghae.commerce.order.domain.command.OrderCommand | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class OrderFacade( | ||
private val orderService: OrderService, | ||
private val itemStockService: ItemStockService, | ||
) { | ||
fun order(command: OrderCommand): String { | ||
verifyStockRemains(command.orderItemList) | ||
return orderService.create(command) | ||
} | ||
|
||
private fun verifyStockRemains(orderItems: List<OrderCommand.OrderItem>) { | ||
orderItems.forEach { | ||
itemStockService.verifyStockRemains(it) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
commerce-api/src/main/kotlin/com/hanghae/commerce/order/domain/OrderCreateService.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.