diff --git a/src/main/kotlin/com/fiap/order/OrderApiApp.kt b/src/main/kotlin/com/fiap/order/OrderApiApp.kt index 2e96a71..064b110 100644 --- a/src/main/kotlin/com/fiap/order/OrderApiApp.kt +++ b/src/main/kotlin/com/fiap/order/OrderApiApp.kt @@ -14,13 +14,10 @@ import org.springframework.cloud.openfeign.FeignAutoConfiguration @OpenAPIDefinition( info = Info( - title = "Self-Order Management API", + title = "Orders API", version = "1.0.0", - description = - "API de autoatendimento em restaurante como implementação do Tech Challenge" + - " referente à primeira fase do curso de pós-graduação em Arquitetura de Software pela FIAP.", - contact = - Contact( + description = "Microsserviço de pedidos", + contact = Contact( name = "Grupo 15", url = "http://fiap-3soat-g15.s3-website-us-east-1.amazonaws.com", ), diff --git a/src/main/kotlin/com/fiap/order/adapter/client/MercadoPagoClient.kt b/src/main/kotlin/com/fiap/order/adapter/client/MercadoPagoClient.kt deleted file mode 100644 index 11fcf41..0000000 --- a/src/main/kotlin/com/fiap/order/adapter/client/MercadoPagoClient.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.fiap.order.adapter.client - -import com.fasterxml.jackson.annotation.JsonProperty -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.http.* -import org.springframework.stereotype.Component -import org.springframework.web.client.RestTemplate -import java.math.BigDecimal - -@Component -@ConditionalOnProperty("payment-provider.mock", havingValue = "false") -class MercadoPagoClient( - private val restTemplate: RestTemplate, - @Value("\${mercadopago.api.url}") private val apiUrl: String, - @Value("\${mercadopago.api.token}") private val apiToken: String, - @Value("\${mercadopago.api.userId}") private val userId: String, - @Value("\${mercadopago.integration.posId}") private val posId: String, -) { - - fun submitMerchantOrder(request: MercadoPagoQRCodeOrderRequest): MercadoPagoQRCodeOrderResponse { - val headers = createHeaders() - val entity = HttpEntity(request, headers) - val url = "$apiUrl/instore/orders/qr/seller/collectors/$userId/pos/$posId/qrs" - val response = executeRequest(url, HttpMethod.POST, entity, MercadoPagoQRCodeOrderResponse::class.java) - return response.body ?: throw IllegalStateException("No response from Mercado Pago") - } - - fun fetchMerchantOrder(externalOrderGlobalId: String): MercadoPagoMerchantOrderResponse { - val headers = createHeaders() - val entity = HttpEntity(headers) - val url = "$apiUrl/merchant_orders/$externalOrderGlobalId" - val response = executeRequest(url, HttpMethod.GET, entity, MercadoPagoMerchantOrderResponse::class.java) - return response.body ?: throw IllegalStateException("No response from Mercado Pago") - } - - private fun createHeaders(): HttpHeaders { - val headers = HttpHeaders() - headers.contentType = MediaType.APPLICATION_JSON - headers.setBearerAuth(apiToken) - return headers - } - - private fun executeRequest( - url: String, - method: HttpMethod, - entity: HttpEntity, - responseType: Class, - ): ResponseEntity { - return try { - restTemplate.exchange(url, method, entity, responseType) - } catch (e: Exception) { - throw IllegalStateException("Error while communicating with Mercado Pago API: ${e.message}", e) - } - } -} - -data class MercadoPagoQRCodeOrderRequest( - val title: String, - val description: String, - @JsonProperty(value = "external_reference") val externalReference: String, - @JsonProperty(value = "notification_url") val notificationUrl: String, - @JsonProperty(value = "total_amount") val totalAmount: BigDecimal, - val items: List, -) - -data class MercadoPagoQRCodeOrderRequestItem( - val title: String, - @JsonProperty(value = "unit_price") val unitPrice: BigDecimal, - val quantity: Long, - @JsonProperty(value = "unit_measure") val unitMeasure: String, - @JsonProperty(value = "total_amount") val totalAmount: BigDecimal, -) - -data class MercadoPagoQRCodeOrderResponse( - @JsonProperty(value = "qr_data") val qrData: String, - @JsonProperty(value = "in_store_order_id") val inStoreOrderId: String, -) - -data class MercadoPagoMerchantOrderResponse( - val id: String, - @JsonProperty(value = "external_reference") val externalReference: String, - @JsonProperty(value = "order_status") val orderStatus: String, -) diff --git a/src/main/kotlin/com/fiap/order/adapter/client/PaymentsApiClient.kt b/src/main/kotlin/com/fiap/order/adapter/client/PaymentsApiClient.kt index d79a2c2..e5c5982 100644 --- a/src/main/kotlin/com/fiap/order/adapter/client/PaymentsApiClient.kt +++ b/src/main/kotlin/com/fiap/order/adapter/client/PaymentsApiClient.kt @@ -1,36 +1,27 @@ package com.fiap.order.adapter.client -import com.fiap.order.domain.entities.Order -import com.fiap.order.domain.entities.Payment -import com.fiap.order.driver.web.request.PaymentRequest +import com.fiap.order.driver.web.response.PaymentResponse +import com.fiap.order.driver.web.request.PaymentHTTPRequest import org.springframework.cloud.openfeign.FeignClient import org.springframework.web.bind.annotation.* -@FeignClient(name = "payments-client", url = "\${clients.payments-api.url}") +@FeignClient( + name = "payments-client", + url = "\${clients.payments-api.url}" +) interface PaymentsApiClient { @RequestMapping( method = [RequestMethod.GET], - value = ["/payments/{orderNumber}"], + value = ["/payments/{paymentId}"], consumes = ["application/json"] ) - fun getByOrderNumber(@PathVariable orderNumber: Long): Payment + fun getByPaymentId(@PathVariable paymentId: String): PaymentResponse @RequestMapping( method = [RequestMethod.POST], - value = ["/payments/notifications/{orderNumber}"], + value = ["/payments"], consumes = ["application/json"] ) - fun notify( - @PathVariable orderNumber: Long, - @RequestParam(value = "id") resourceId: String, - @RequestParam topic: String - ): Any - - @RequestMapping( - method = [RequestMethod.POST], - value = ["/payments/create"], - consumes = ["application/json"] - ) - fun create(@RequestBody order: Order): PaymentRequest + fun create(@RequestBody paymentHTTPRequest: PaymentHTTPRequest): PaymentResponse } diff --git a/src/main/kotlin/com/fiap/order/adapter/client/StockApiClient.kt b/src/main/kotlin/com/fiap/order/adapter/client/StockApiClient.kt index aeba69b..023f29a 100644 --- a/src/main/kotlin/com/fiap/order/adapter/client/StockApiClient.kt +++ b/src/main/kotlin/com/fiap/order/adapter/client/StockApiClient.kt @@ -10,7 +10,11 @@ import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMethod -@FeignClient(name = "stock-client", url = "\${clients.stock-api.url}", configuration = [StockApiInterceptor::class]) +@FeignClient( + name = "stock-client", + url = "\${clients.stock-api.url}", + configuration = [StockApiInterceptor::class] +) interface StockApiClient { @RequestMapping( @@ -38,4 +42,4 @@ interface StockApiClient { ) fun getByProductNumber(@PathVariable("productNumber") productNumber: Long): Product -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/fiap/order/adapter/client/config/StockApiInterceptor.kt b/src/main/kotlin/com/fiap/order/adapter/client/config/StockApiInterceptor.kt index 07ba790..93bf92e 100644 --- a/src/main/kotlin/com/fiap/order/adapter/client/config/StockApiInterceptor.kt +++ b/src/main/kotlin/com/fiap/order/adapter/client/config/StockApiInterceptor.kt @@ -6,9 +6,10 @@ import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.request.ServletRequestAttributes class StockApiInterceptor: RequestInterceptor { + override fun apply(template: RequestTemplate?) { val requestAttr = (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes) val apiToken = requestAttr.request.getHeader("authorization") template?.header("authorization", apiToken) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/fiap/order/adapter/controller/CustomerController.kt b/src/main/kotlin/com/fiap/order/adapter/controller/CustomerController.kt index 278ec3f..a3386c6 100644 --- a/src/main/kotlin/com/fiap/order/adapter/controller/CustomerController.kt +++ b/src/main/kotlin/com/fiap/order/adapter/controller/CustomerController.kt @@ -1,6 +1,5 @@ package com.fiap.order.adapter.controller - import com.fiap.order.domain.entities.Customer import com.fiap.order.driver.web.CustomersAPI import com.fiap.order.driver.web.request.CustomerRequest diff --git a/src/main/kotlin/com/fiap/order/adapter/controller/OrderController.kt b/src/main/kotlin/com/fiap/order/adapter/controller/OrderController.kt index 52bb14e..0b03039 100644 --- a/src/main/kotlin/com/fiap/order/adapter/controller/OrderController.kt +++ b/src/main/kotlin/com/fiap/order/adapter/controller/OrderController.kt @@ -4,8 +4,11 @@ import com.fiap.order.domain.entities.Order import com.fiap.order.domain.valueobjects.OrderStatus import com.fiap.order.driver.web.OrdersAPI import com.fiap.order.driver.web.request.OrderRequest -import com.fiap.order.driver.web.response.OrderToPayResponse -import com.fiap.order.usecases.* +import com.fiap.order.driver.web.response.PendingOrderResponse +import com.fiap.order.usecases.ChangeOrderStatusUseCase +import com.fiap.order.usecases.LoadOrderUseCase +import com.fiap.order.usecases.CreateOrderUseCase +import org.slf4j.LoggerFactory import org.springframework.http.ResponseEntity import org.springframework.security.core.context.SecurityContextHolder import org.springframework.security.oauth2.core.ClaimAccessor @@ -15,13 +18,12 @@ import java.util.* @RestController class OrderController( private val loadOrdersUseCase: LoadOrderUseCase, - private val createOrderUseCase: PlaceOrderUseCase, - private val loadPaymentUseCase: LoadPaymentUseCase, - private val prepareOrderUseCase: PrepareOrderUseCase, - private val completeOrderUseCase: CompleteOrderUseCase, - private val cancelOrderStatusUseCase: CancelOrderStatusUseCase, - private val confirmOrderUseCase: ConfirmOrderUseCase -) : OrdersAPI { + private val createOrderUseCase: CreateOrderUseCase, + private val changeOrderStatusUseCase: ChangeOrderStatusUseCase, +) : OrdersAPI +{ + private val log = LoggerFactory.getLogger(javaClass) + override fun getByOrderNumber(orderNumber: Long): ResponseEntity { return ResponseEntity.ok(loadOrdersUseCase.getByOrderNumber(orderNumber)) } @@ -54,47 +56,39 @@ class OrderController( .run { return ResponseEntity.ok(this) } } - override fun create(orderRequest: OrderRequest): ResponseEntity { + override fun create(orderRequest: OrderRequest): ResponseEntity { var customerId: UUID? = null try { customerId = UUID.fromString( - (SecurityContextHolder.getContext().authentication.credentials as ClaimAccessor).getClaim("custom:CUSTOMER_ID") + (SecurityContextHolder.getContext().authentication.credentials as ClaimAccessor) + .getClaim("custom:CUSTOMER_ID") ) - } catch (_: Exception) { + } catch (ex: Exception) { + log.error(ex.message, ex.cause) } - val order = - createOrderUseCase.create( - customerId, - orderRequest.toOrderItemDomain(), - ) - val payment = loadPaymentUseCase.getByOrderNumber(order.number!!) + val orderToPayResponse = createOrderUseCase.create(customerId, orderRequest.toOrderItemsDomain()) - return ResponseEntity.ok( - OrderToPayResponse( - order = order, - paymentInfo = payment.paymentInfo, - ), - ) + return ResponseEntity.ok(orderToPayResponse) } override fun start(orderNumber: Long): ResponseEntity { - return ResponseEntity.ok(prepareOrderUseCase.startOrderPreparation(orderNumber)) + return ResponseEntity.ok(changeOrderStatusUseCase.startOrderPreparation(orderNumber)) } override fun finish(orderNumber: Long): ResponseEntity { - return ResponseEntity.ok(prepareOrderUseCase.finishOrderPreparation(orderNumber)) + return ResponseEntity.ok(changeOrderStatusUseCase.finishOrderPreparation(orderNumber)) } override fun complete(orderNumber: Long): ResponseEntity { - return ResponseEntity.ok(completeOrderUseCase.completeOrder(orderNumber)) + return ResponseEntity.ok(changeOrderStatusUseCase.completeOrder(orderNumber)) } override fun cancel(orderNumber: Long): ResponseEntity { - return ResponseEntity.ok(cancelOrderStatusUseCase.cancelOrder(orderNumber)) + return ResponseEntity.ok(changeOrderStatusUseCase.cancelOrder(orderNumber)) } override fun confirm(orderNumber: Long): ResponseEntity { - return ResponseEntity.ok(confirmOrderUseCase.confirmOrder(orderNumber)) + return ResponseEntity.ok(changeOrderStatusUseCase.confirmOrder(orderNumber)) } } diff --git a/src/main/kotlin/com/fiap/order/adapter/controller/configuration/ServiceConfig.kt b/src/main/kotlin/com/fiap/order/adapter/controller/configuration/ServiceConfig.kt index ef9bce7..ed672e2 100644 --- a/src/main/kotlin/com/fiap/order/adapter/controller/configuration/ServiceConfig.kt +++ b/src/main/kotlin/com/fiap/order/adapter/controller/configuration/ServiceConfig.kt @@ -1,29 +1,47 @@ package com.fiap.order.adapter.controller.configuration import com.fiap.order.OrderApiApp -import com.fiap.order.adapter.gateway.* -import com.fiap.order.usecases.* +import com.fiap.order.adapter.gateway.CustomerGateway +import com.fiap.order.adapter.gateway.OrderGateway +import com.fiap.order.adapter.gateway.PaymentGateway +import com.fiap.order.adapter.gateway.ProductGateway +import com.fiap.order.adapter.gateway.StockGateway +import com.fiap.order.adapter.gateway.TransactionalGateway +import com.fiap.order.usecases.AdjustStockUseCase +import com.fiap.order.usecases.LoadCustomerUseCase +import com.fiap.order.usecases.LoadProductUseCase +import com.fiap.order.usecases.RequestPaymentUseCase import com.fiap.order.usecases.services.CustomerService import com.fiap.order.usecases.services.OrderService +import com.fiap.order.usecases.services.PaymentService import com.fiap.order.usecases.services.ProductService import com.fiap.order.usecases.services.StockService import org.springframework.context.annotation.Bean import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration -import com.fiap.order.usecases.services.PaymentService @Configuration @ComponentScan(basePackageClasses = [OrderApiApp::class]) class ServiceConfig { + @Bean + fun createProductService(productRepository: ProductGateway): ProductService { + return ProductService(productRepository) + } @Bean - fun createProductService( - productRepository: ProductGateway, - ): ProductService { - return ProductService( - productRepository, - ) + fun createStockService(stockRepository: StockGateway): StockService { + return StockService(stockRepository) + } + + @Bean + fun createCustomerService(customerRepository: CustomerGateway): CustomerService { + return CustomerService(customerRepository) + } + + @Bean + fun createPaymentService(paymentRepository: PaymentGateway): PaymentService { + return PaymentService(paymentRepository) } @Bean @@ -32,7 +50,7 @@ class ServiceConfig { loadCustomerUseCase: LoadCustomerUseCase, loadProductsUseCase: LoadProductUseCase, adjustInventoryUseCase: AdjustStockUseCase, - providePaymentRequestUseCase: ProvidePaymentRequestUseCase, + providePaymentRequestUseCase: RequestPaymentUseCase, transactionalRepository: TransactionalGateway, ): OrderService { return OrderService( @@ -44,23 +62,4 @@ class ServiceConfig { transactionalRepository, ) } - - @Bean - fun createStockService(stockRepository: StockGateway): StockService { - return StockService(stockRepository) - } - - @Bean - fun createCustomerService(customerRepository: CustomerGateway): CustomerService { - return CustomerService(customerRepository) - } - - @Bean - fun createPaymentService( - paymentRepository: PaymentGateway, - ): PaymentService { - return PaymentService( - paymentRepository, - ) - } } diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/CustomerGateway.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/CustomerGateway.kt index 84fc546..90dc2e0 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/CustomerGateway.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/CustomerGateway.kt @@ -4,7 +4,6 @@ import com.fiap.order.domain.entities.Customer import java.util.* interface CustomerGateway { - fun findAll(): List fun findById(customerId: UUID): Customer? diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/OrderGateway.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/OrderGateway.kt index 59963d0..a231c89 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/OrderGateway.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/OrderGateway.kt @@ -13,10 +13,7 @@ interface OrderGateway { fun findByCustomerId(customerId: UUID): List - fun findByCustomerIdAndStatus( - customerId: UUID, - status: OrderStatus, - ): List + fun findByCustomerIdAndStatus(customerId: UUID, status: OrderStatus): List fun upsert(order: Order): Order diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/PaymentGateway.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/PaymentGateway.kt index 1fc4ab4..074ed7b 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/PaymentGateway.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/PaymentGateway.kt @@ -1,14 +1,10 @@ package com.fiap.order.adapter.gateway import com.fiap.order.domain.entities.Order -import com.fiap.order.domain.entities.Payment -import com.fiap.order.driver.web.request.PaymentRequest - +import com.fiap.order.driver.web.response.PaymentResponse interface PaymentGateway { - fun findByOrderNumber(orderNumber: Long): Payment? - - fun create(payment: Payment): Payment + fun findByPaymentId(paymentId: String): PaymentResponse? - fun createFromOrder(order: Order): PaymentRequest + fun requestPayment(order: Order): PaymentResponse } diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/PaymentProviderGateway.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/PaymentProviderGateway.kt deleted file mode 100644 index e6cd5c6..0000000 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/PaymentProviderGateway.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.fiap.order.adapter.gateway - -import com.fiap.order.domain.entities.Order -import com.fiap.order.driver.web.request.PaymentRequest - -interface PaymentProviderGateway { - fun createExternalOrder(order: Order): PaymentRequest -} diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/StockGateway.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/StockGateway.kt index 7c69009..040bdda 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/StockGateway.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/StockGateway.kt @@ -2,16 +2,8 @@ package com.fiap.order.adapter.gateway import com.fiap.order.domain.entities.Stock - interface StockGateway { + fun increment(componentNumber: Long, quantity: Long): Stock - fun increment( - componentNumber: Long, - quantity: Long, - ): Stock - - fun decrement( - componentNumber: Long, - quantity: Long, - ): Stock + fun decrement(componentNumber: Long, quantity: Long): Stock } diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/OrderGatewayImpl.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/OrderGatewayImpl.kt index ad01d05..8c94a59 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/OrderGatewayImpl.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/OrderGatewayImpl.kt @@ -50,7 +50,8 @@ class OrderGatewayImpl( } override fun upsert(order: Order): Order { - val currentOrder = order.number?.let { findByOrderNumber(number = order.number) } ?: order.copy(number = null) + val currentOrder = order.number?.let { findByOrderNumber(number = order.number) } + ?: order.copy(number = null) val orderUpdated = currentOrder .copy( @@ -60,13 +61,16 @@ class OrderGatewayImpl( items = order.items, total = order.total, ) - return orderUpdated - .let(mapper::toEntity) - .let(orderJpaRepository::save) - .let(mapper::toDomain) + return persist(orderUpdated) } override fun deleteAll() { orderJpaRepository.deleteAll() } + + private fun persist(order: Order): Order = + order + .let(mapper::toEntity) + .let(orderJpaRepository::save) + .let(mapper::toDomain) } diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/PaymentGatewayImpl.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/PaymentGatewayImpl.kt index 1fb8d92..ebd2c41 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/PaymentGatewayImpl.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/PaymentGatewayImpl.kt @@ -3,44 +3,43 @@ package com.fiap.order.adapter.gateway.impl import com.fiap.order.adapter.client.PaymentsApiClient import com.fiap.order.adapter.gateway.PaymentGateway import com.fiap.order.domain.entities.Order -import com.fiap.order.domain.entities.Payment -import com.fiap.order.domain.errors.ErrorType -import com.fiap.order.domain.errors.SelfOrderManagementException -import com.fiap.order.driver.database.persistence.jpa.PaymentJpaRepository -import com.fiap.order.driver.database.persistence.mapper.PaymentMapper -import com.fiap.order.driver.web.request.PaymentRequest -import org.mapstruct.factory.Mappers +import com.fiap.order.driver.web.response.PaymentResponse +import com.fiap.order.driver.web.request.OrderInfo +import com.fiap.order.driver.web.request.OrderLine +import com.fiap.order.driver.web.request.PaymentHTTPRequest class PaymentGatewayImpl( - private val paymentJpaRepository: PaymentJpaRepository, private val paymentsApiClient: PaymentsApiClient ) : PaymentGateway { - private val mapper = Mappers.getMapper(PaymentMapper::class.java) - override fun findByOrderNumber(orderNumber: Long): Payment { - return paymentsApiClient.getByOrderNumber(orderNumber) + override fun findByPaymentId(paymentId: String): PaymentResponse { + return paymentsApiClient.getByPaymentId(paymentId) } - override fun create(payment: Payment): Payment { - payment.orderNumber.let { - findByOrderNumber(it).let { - throw SelfOrderManagementException( - errorType = ErrorType.PAYMENT_ALREADY_EXISTS, - message = "Payment record for order [${payment.orderNumber}] already exists", - ) - } - } - return persist(payment) + override fun requestPayment(order: Order): PaymentResponse { + val paymentHTTPRequest = PaymentHTTPRequest( + orderInfo = OrderInfo( + number = order.number!!, + orderedAt = order.date.atStartOfDay(), + orderedBy = order.customer?.name ?: ANONYMOUS, + totalAmount = order.total, + lines = order.items.map { product -> + // TODO: each product as order line for now, fix later + OrderLine( + name = product.name, + quantity = 1, + unitPrice = product.price, + unitOfMeasurement = "unit", + totalAmount = product.price + ) + } + ) + ) + + return paymentsApiClient.create(paymentHTTPRequest) } - - override fun createFromOrder(order: Order): PaymentRequest { - return paymentsApiClient.create(order) + + companion object { + const val ANONYMOUS = "Anonymous" } - - - private fun persist(payment: Payment): Payment = - payment - .let(mapper::toEntity) - .let(paymentJpaRepository::save) - .let(mapper::toDomain) } diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/ProductGatewayImpl.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/ProductGatewayImpl.kt index 018789f..f4f11b4 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/ProductGatewayImpl.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/ProductGatewayImpl.kt @@ -3,9 +3,6 @@ package com.fiap.order.adapter.gateway.impl import com.fiap.order.adapter.client.StockApiClient import com.fiap.order.adapter.gateway.ProductGateway import com.fiap.order.domain.entities.Product -import com.fiap.order.driver.database.persistence.jpa.ProductJpaRepository -import com.fiap.order.driver.database.persistence.mapper.ProductMapper -import org.mapstruct.factory.Mappers class ProductGatewayImpl( private val stockApiClient: StockApiClient, diff --git a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/StockGatewayImpl.kt b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/StockGatewayImpl.kt index 2fc396e..5f718cb 100644 --- a/src/main/kotlin/com/fiap/order/adapter/gateway/impl/StockGatewayImpl.kt +++ b/src/main/kotlin/com/fiap/order/adapter/gateway/impl/StockGatewayImpl.kt @@ -16,5 +16,4 @@ class StockGatewayImpl( override fun decrement(componentNumber: Long, quantity: Long): Stock { return stockApiClient.decrement(componentNumber, QuantityRequest(quantity)); } - } diff --git a/src/main/kotlin/com/fiap/order/domain/entities/Payment.kt b/src/main/kotlin/com/fiap/order/domain/entities/Payment.kt deleted file mode 100644 index 494c29e..0000000 --- a/src/main/kotlin/com/fiap/order/domain/entities/Payment.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.fiap.order.domain.entities - -import com.fiap.order.domain.valueobjects.PaymentStatus -import java.time.LocalDateTime - -data class Payment( - val orderNumber: Long, - val externalOrderId: String, - val externalOrderGlobalId: String?, - val paymentInfo: String, - val createdAt: LocalDateTime, - val status: PaymentStatus, - val statusChangedAt: LocalDateTime, -) { - fun update(newPayment: Payment): Payment = - copy( - orderNumber = newPayment.orderNumber, - externalOrderId = newPayment.externalOrderId, - externalOrderGlobalId = newPayment.externalOrderGlobalId, - paymentInfo = newPayment.paymentInfo, - createdAt = newPayment.createdAt, - status = newPayment.status, - statusChangedAt = newPayment.statusChangedAt, - ) -} diff --git a/src/main/kotlin/com/fiap/order/driver/database/configuration/GatewayConfig.kt b/src/main/kotlin/com/fiap/order/driver/database/configuration/GatewayConfig.kt index e6164a8..37a7cc3 100644 --- a/src/main/kotlin/com/fiap/order/driver/database/configuration/GatewayConfig.kt +++ b/src/main/kotlin/com/fiap/order/driver/database/configuration/GatewayConfig.kt @@ -3,9 +3,20 @@ package com.fiap.order.driver.database.configuration import com.fiap.order.OrderApiApp import com.fiap.order.adapter.client.PaymentsApiClient import com.fiap.order.adapter.client.StockApiClient -import com.fiap.order.adapter.gateway.* -import com.fiap.order.adapter.gateway.impl.* -import com.fiap.order.driver.database.persistence.jpa.* +import com.fiap.order.adapter.gateway.CustomerGateway +import com.fiap.order.adapter.gateway.OrderGateway +import com.fiap.order.adapter.gateway.PaymentGateway +import com.fiap.order.adapter.gateway.ProductGateway +import com.fiap.order.adapter.gateway.StockGateway +import com.fiap.order.adapter.gateway.TransactionalGateway +import com.fiap.order.adapter.gateway.impl.CustomerGatewayImpl +import com.fiap.order.adapter.gateway.impl.OrderGatewayImpl +import com.fiap.order.adapter.gateway.impl.PaymentGatewayImpl +import com.fiap.order.adapter.gateway.impl.ProductGatewayImpl +import com.fiap.order.adapter.gateway.impl.StockGatewayImpl +import com.fiap.order.adapter.gateway.impl.TransactionalGatewayImpl +import com.fiap.order.driver.database.persistence.jpa.CustomerJpaRepository +import com.fiap.order.driver.database.persistence.jpa.OrderJpaRepository import org.springframework.context.annotation.Bean import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration @@ -40,7 +51,7 @@ class GatewayConfig { } @Bean("PaymentGateway") - fun createPaymentGateway(paymentJpaRepository: PaymentJpaRepository, paymentsApiClient: PaymentsApiClient): PaymentGateway { - return PaymentGatewayImpl(paymentJpaRepository, paymentsApiClient) + fun createPaymentGateway(paymentsApiClient: PaymentsApiClient): PaymentGateway { + return PaymentGatewayImpl(paymentsApiClient) } } diff --git a/src/main/kotlin/com/fiap/order/driver/database/configuration/PaymentGatewayConfig.kt b/src/main/kotlin/com/fiap/order/driver/database/configuration/PaymentGatewayConfig.kt deleted file mode 100644 index 860a1fb..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/configuration/PaymentGatewayConfig.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.fiap.order.driver.database.configuration - -import com.fiap.order.OrderApiApp -import com.fiap.order.adapter.client.MercadoPagoClient -import com.fiap.order.adapter.gateway.PaymentProviderGateway -import com.fiap.order.driver.database.persistence.provider.MercadoPagoPaymentProvider -import com.fiap.order.driver.database.persistence.provider.PaymentProviderGatewayMock -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan(basePackageClasses = [OrderApiApp::class]) -class PaymentGatewayConfig { - @Bean("PaymentProvider") - @ConditionalOnProperty("payment-provider.mock", havingValue = "false") - fun createPaymentProvider( - mercadoPagoClient: MercadoPagoClient, - @Value("\${mercadopago.integration.webhookBaseUrl}") webhookBaseUrl: String, - ): PaymentProviderGateway { - return MercadoPagoPaymentProvider( - mercadoPagoClient, - webhookBaseUrl, - ) - } - - @Bean("PaymentProvider") - @ConditionalOnProperty("payment-provider.mock", havingValue = "true") - fun createPaymentProviderMock(): PaymentProviderGateway { - return PaymentProviderGatewayMock() - } -} diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/entities/PaymentEntity.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/entities/PaymentEntity.kt deleted file mode 100644 index bee36c0..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/entities/PaymentEntity.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.fiap.order.driver.database.persistence.entities - -import com.fiap.order.domain.valueobjects.PaymentStatus -import jakarta.persistence.* -import java.time.LocalDateTime - -@Entity -@Table(name = "payment") -class PaymentEntity( - @Id - @Column(name = "payment_order_number") - val orderNumber: Long, - @Column(name = "payment_external_order_id") - val externalOrderId: String, - @Column(name = "payment_external_order_global_id") - val externalOrderGlobalId: String?, - @Column(name = "payment_payment_info") - val paymentInfo: String, - @Column(name = "payment_created_at") - val createdAt: LocalDateTime, - @Enumerated(EnumType.STRING) - @Column(name = "payment_status") - val status: PaymentStatus, - @Column(name = "payment_status_changed_at") - val statusChangedAt: LocalDateTime, -) diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/jpa/PaymentJpaRepository.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/jpa/PaymentJpaRepository.kt deleted file mode 100644 index 0d81925..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/jpa/PaymentJpaRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.fiap.order.driver.database.persistence.jpa - -import com.fiap.order.driver.database.persistence.entities.PaymentEntity -import org.springframework.data.repository.CrudRepository - -interface PaymentJpaRepository : CrudRepository diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/jpa/ProductJpaRepository.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/jpa/ProductJpaRepository.kt deleted file mode 100644 index d9c7240..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/jpa/ProductJpaRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.fiap.order.driver.database.persistence.jpa - -import com.fiap.order.driver.database.persistence.entities.ProductEntity -import org.springframework.data.repository.CrudRepository - -interface ProductJpaRepository : CrudRepository diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/CustomerMapper.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/CustomerMapper.kt index 98d5b32..d3fc5b6 100644 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/CustomerMapper.kt +++ b/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/CustomerMapper.kt @@ -7,5 +7,6 @@ import org.mapstruct.Mapper @Mapper interface CustomerMapper { fun toDomain(entity: CustomerEntity): Customer + fun toEntity(domain: Customer): CustomerEntity } diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/OrderMapper.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/OrderMapper.kt index 118778a..5cbb8ed 100644 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/OrderMapper.kt +++ b/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/OrderMapper.kt @@ -1,11 +1,7 @@ package com.fiap.order.driver.database.persistence.mapper import com.fiap.order.domain.entities.Order -import com.fiap.order.domain.entities.Product -import com.fiap.order.domain.valueobjects.ProductCategory import com.fiap.order.driver.database.persistence.entities.OrderEntity -import com.fiap.order.driver.database.persistence.entities.ProductEntity -import org.mapstruct.Condition import org.mapstruct.Mapper @Mapper @@ -13,5 +9,4 @@ interface OrderMapper { fun toDomain(entity: OrderEntity): Order fun toEntity(domain: Order): OrderEntity - } diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/PaymentMapper.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/PaymentMapper.kt deleted file mode 100644 index 76bf806..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/PaymentMapper.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.fiap.order.driver.database.persistence.mapper - -import com.fiap.order.domain.entities.Payment -import com.fiap.order.domain.entities.Product -import com.fiap.order.domain.valueobjects.ProductCategory -import com.fiap.order.driver.database.persistence.entities.PaymentEntity -import com.fiap.order.driver.database.persistence.entities.ProductEntity -import org.mapstruct.Mapper - -@Mapper -interface PaymentMapper { - fun toDomain(entity: PaymentEntity): Payment - - fun toEntity(domain: Payment): PaymentEntity - - - -} diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/ProductMapper.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/ProductMapper.kt deleted file mode 100644 index 69710c5..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/mapper/ProductMapper.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.fiap.order.driver.database.persistence.mapper - -import com.fiap.order.domain.entities.Product -import com.fiap.order.domain.valueobjects.ProductCategory -import com.fiap.order.driver.database.persistence.entities.ProductEntity -import org.mapstruct.Mapper -import org.mapstruct.Mapping -import org.mapstruct.NullValuePropertyMappingStrategy - -@Mapper -interface ProductMapper { - - fun toDomain(entity: ProductEntity): Product -} diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/provider/MercadoPagoPaymentProvider.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/provider/MercadoPagoPaymentProvider.kt deleted file mode 100644 index b2a6a6b..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/provider/MercadoPagoPaymentProvider.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.fiap.order.driver.database.persistence.provider - -import com.fiap.order.adapter.client.MercadoPagoClient -import com.fiap.order.adapter.client.MercadoPagoQRCodeOrderRequest -import com.fiap.order.adapter.client.MercadoPagoQRCodeOrderRequestItem -import com.fiap.order.adapter.gateway.PaymentProviderGateway -import com.fiap.order.domain.entities.Order -import com.fiap.order.driver.web.request.PaymentRequest - -class MercadoPagoPaymentProvider( - private val mercadoPagoClient: MercadoPagoClient, - private val webhookBaseUrl: String, -) : PaymentProviderGateway { - - override fun createExternalOrder(order: Order): PaymentRequest { - // source_news=ipn indicates application will receive only Instant Payment Notifications (IPNs), not webhooks - val notificationUrl = "${webhookBaseUrl}/payments/notifications/${order.number}?source_news=ipn" - - val response = - mercadoPagoClient.submitMerchantOrder( - MercadoPagoQRCodeOrderRequest( - title = "Order ${order.number}", - description = "Ordered at ${order.date} by ${order.customer?.name ?: order.customer?.document ?: "anonymous"}", - externalReference = order.number.toString(), - notificationUrl = notificationUrl, - totalAmount = order.total, - items = - order.items.map { product -> - MercadoPagoQRCodeOrderRequestItem( - title = product.name, - unitPrice = product.price, - quantity = 1, // TODO: fix to use order lines with persisted quantities per product - unitMeasure = MercadoPagoMeasureUnit.UNIT.measureUnit, - totalAmount = product.price, - ) - }, - ), - ) - - return PaymentRequest( - externalOrderId = response.inStoreOrderId, - externalOrderGlobalId = null, - paymentInfo = response.qrData, - ) - } - - enum class MercadoPagoMeasureUnit(val measureUnit: String) { - UNIT("unit"), - } -} diff --git a/src/main/kotlin/com/fiap/order/driver/database/persistence/provider/PaymentProviderGatewayMock.kt b/src/main/kotlin/com/fiap/order/driver/database/persistence/provider/PaymentProviderGatewayMock.kt deleted file mode 100644 index 1c0534c..0000000 --- a/src/main/kotlin/com/fiap/order/driver/database/persistence/provider/PaymentProviderGatewayMock.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.fiap.order.driver.database.persistence.provider - -import com.fiap.order.adapter.gateway.PaymentProviderGateway -import com.fiap.order.domain.entities.Order -import com.fiap.order.driver.web.request.PaymentRequest -import java.util.* - -class PaymentProviderGatewayMock : PaymentProviderGateway { - override fun createExternalOrder(order: Order): PaymentRequest { - return PaymentRequest( - externalOrderId = UUID.randomUUID().toString(), - externalOrderGlobalId = null, - paymentInfo = "mocked" - ) - } -} diff --git a/src/main/kotlin/com/fiap/order/driver/web/CustomersAPI.kt b/src/main/kotlin/com/fiap/order/driver/web/CustomersAPI.kt index b74e495..4667a73 100644 --- a/src/main/kotlin/com/fiap/order/driver/web/CustomersAPI.kt +++ b/src/main/kotlin/com/fiap/order/driver/web/CustomersAPI.kt @@ -1,6 +1,5 @@ package com.fiap.order.driver.web - import com.fiap.order.domain.entities.Customer import com.fiap.order.driver.web.request.CustomerRequest import io.swagger.v3.oas.annotations.Operation @@ -9,9 +8,16 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +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 -@Tag(name = "cliente", description = "API de clientes") +@Tag(name = "cliente", description = "Clientes") @RequestMapping("/customers") interface CustomersAPI { @Operation(summary = "Retorna todos os clientes") diff --git a/src/main/kotlin/com/fiap/order/driver/web/OrdersAPI.kt b/src/main/kotlin/com/fiap/order/driver/web/OrdersAPI.kt index 5e144a1..306baa4 100644 --- a/src/main/kotlin/com/fiap/order/driver/web/OrdersAPI.kt +++ b/src/main/kotlin/com/fiap/order/driver/web/OrdersAPI.kt @@ -2,7 +2,7 @@ package com.fiap.order.driver.web import com.fiap.order.domain.entities.Order import com.fiap.order.driver.web.request.OrderRequest -import com.fiap.order.driver.web.response.OrderToPayResponse +import com.fiap.order.driver.web.response.PendingOrderResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.responses.ApiResponse @@ -10,9 +10,14 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.security.SecurityRequirement import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +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 -@Tag(name = "pedido", description = "API de pedidos") +@Tag(name = "pedido", description = "Pedidos") @RequestMapping("/orders") interface OrdersAPI { @Operation(summary = "Retorna todos os pedidos") @@ -85,8 +90,19 @@ interface OrdersAPI { @PostMapping fun create( @Parameter(description = "Cadastro de pedido") @RequestBody orderRequest: OrderRequest, - ): ResponseEntity + ): ResponseEntity + @Operation(summary = "Confirma pedido") + @ApiResponses( + value = [ + ApiResponse(responseCode = "200", description = "Operação bem-sucedida"), + ApiResponse(responseCode = "404", description = "Pedido não encontrado"), + ApiResponse(responseCode = "400", description = "Pedido não pode ser confirmado"), + ], + ) + @PostMapping("/{orderNumber}/confirm") + fun confirm(@PathVariable orderNumber: Long) : ResponseEntity + @Operation(summary = "Atualiza status de pedido em preparo") @ApiResponses( value = [ @@ -138,9 +154,4 @@ interface OrdersAPI { fun cancel( @Parameter(description = "Número do pedido") @PathVariable orderNumber: Long, ): ResponseEntity - - - @PostMapping("/notify/{orderNumber}/confirmed") - fun confirm(@PathVariable orderNumber: Long) : ResponseEntity - } diff --git a/src/main/kotlin/com/fiap/order/driver/web/request/OrderRequest.kt b/src/main/kotlin/com/fiap/order/driver/web/request/OrderRequest.kt index 10fa573..1f0711c 100644 --- a/src/main/kotlin/com/fiap/order/driver/web/request/OrderRequest.kt +++ b/src/main/kotlin/com/fiap/order/driver/web/request/OrderRequest.kt @@ -11,5 +11,5 @@ data class OrderRequest( ) val items: List, ) { - fun toOrderItemDomain() = items.map { OrderItem(productNumber = it.productNumber, quantity = it.quantity) } + fun toOrderItemsDomain() = items.map { OrderItem(productNumber = it.productNumber, quantity = it.quantity) } } diff --git a/src/main/kotlin/com/fiap/order/driver/web/request/PaymentHTTPRequest.kt b/src/main/kotlin/com/fiap/order/driver/web/request/PaymentHTTPRequest.kt new file mode 100644 index 0000000..eba0c8f --- /dev/null +++ b/src/main/kotlin/com/fiap/order/driver/web/request/PaymentHTTPRequest.kt @@ -0,0 +1,24 @@ +package com.fiap.order.driver.web.request + +import java.math.BigDecimal +import java.time.LocalDateTime + +data class PaymentHTTPRequest( + val orderInfo: OrderInfo, +) + +data class OrderInfo( + val number: Long, + val totalAmount: BigDecimal, + val lines: List, + val orderedAt: LocalDateTime, + val orderedBy: String, +) + +data class OrderLine( + val name: String, + val unitPrice: BigDecimal, + val quantity: Long, + val unitOfMeasurement: String, + val totalAmount: BigDecimal, +) diff --git a/src/main/kotlin/com/fiap/order/driver/web/request/PaymentRequest.kt b/src/main/kotlin/com/fiap/order/driver/web/request/PaymentRequest.kt deleted file mode 100644 index 66c9beb..0000000 --- a/src/main/kotlin/com/fiap/order/driver/web/request/PaymentRequest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.fiap.order.driver.web.request - -class PaymentRequest( - val externalOrderId: String, - val externalOrderGlobalId: String?, - val paymentInfo: String, -) diff --git a/src/main/kotlin/com/fiap/order/driver/web/response/PaymentResponse.kt b/src/main/kotlin/com/fiap/order/driver/web/response/PaymentResponse.kt new file mode 100644 index 0000000..be7f635 --- /dev/null +++ b/src/main/kotlin/com/fiap/order/driver/web/response/PaymentResponse.kt @@ -0,0 +1,15 @@ +package com.fiap.order.driver.web.response + +import com.fiap.order.domain.valueobjects.PaymentStatus +import java.time.LocalDateTime + +data class PaymentResponse( + val id: String, + val orderNumber: Long, + val externalOrderId: String, + val externalOrderGlobalId: String?, + val paymentInfo: String, + val createdAt: LocalDateTime, + val status: PaymentStatus, + val statusChangedAt: LocalDateTime, +) diff --git a/src/main/kotlin/com/fiap/order/driver/web/response/OrderToPayResponse.kt b/src/main/kotlin/com/fiap/order/driver/web/response/PendingOrderResponse.kt similarity index 62% rename from src/main/kotlin/com/fiap/order/driver/web/response/OrderToPayResponse.kt rename to src/main/kotlin/com/fiap/order/driver/web/response/PendingOrderResponse.kt index 68b700d..78adbf1 100644 --- a/src/main/kotlin/com/fiap/order/driver/web/response/OrderToPayResponse.kt +++ b/src/main/kotlin/com/fiap/order/driver/web/response/PendingOrderResponse.kt @@ -2,7 +2,7 @@ package com.fiap.order.driver.web.response import com.fiap.order.domain.entities.Order -data class OrderToPayResponse( +data class PendingOrderResponse( val order: Order, - val paymentInfo: String, + val payment: PaymentResponse, ) diff --git a/src/main/kotlin/com/fiap/order/usecases/AdjustStockUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/AdjustStockUseCase.kt index 4d79f09..694f14b 100644 --- a/src/main/kotlin/com/fiap/order/usecases/AdjustStockUseCase.kt +++ b/src/main/kotlin/com/fiap/order/usecases/AdjustStockUseCase.kt @@ -3,13 +3,7 @@ package com.fiap.order.usecases import com.fiap.order.domain.entities.Stock interface AdjustStockUseCase { - fun increment( - componentNumber: Long, - quantity: Long, - ): Stock + fun increment(componentNumber: Long, quantity: Long): Stock - fun decrement( - componentNumber: Long, - quantity: Long, - ): Stock + fun decrement(componentNumber: Long, quantity: Long): Stock } diff --git a/src/main/kotlin/com/fiap/order/usecases/CancelOrderStatusUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/CancelOrderStatusUseCase.kt deleted file mode 100644 index 164acd0..0000000 --- a/src/main/kotlin/com/fiap/order/usecases/CancelOrderStatusUseCase.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.fiap.order.usecases - -import com.fiap.order.domain.entities.Order - -interface CancelOrderStatusUseCase { - fun cancelOrder(orderNumber: Long): Order -} diff --git a/src/main/kotlin/com/fiap/order/usecases/PrepareOrderUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/ChangeOrderStatusUseCase.kt similarity index 51% rename from src/main/kotlin/com/fiap/order/usecases/PrepareOrderUseCase.kt rename to src/main/kotlin/com/fiap/order/usecases/ChangeOrderStatusUseCase.kt index 537d104..9cb296e 100644 --- a/src/main/kotlin/com/fiap/order/usecases/PrepareOrderUseCase.kt +++ b/src/main/kotlin/com/fiap/order/usecases/ChangeOrderStatusUseCase.kt @@ -2,8 +2,14 @@ package com.fiap.order.usecases import com.fiap.order.domain.entities.Order -interface PrepareOrderUseCase { +interface ChangeOrderStatusUseCase { + fun completeOrder(orderNumber: Long): Order + + fun confirmOrder(orderNumber: Long): Order + fun startOrderPreparation(orderNumber: Long): Order fun finishOrderPreparation(orderNumber: Long): Order + + fun cancelOrder(orderNumber: Long): Order } diff --git a/src/main/kotlin/com/fiap/order/usecases/CompleteOrderUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/CompleteOrderUseCase.kt deleted file mode 100644 index 065e16f..0000000 --- a/src/main/kotlin/com/fiap/order/usecases/CompleteOrderUseCase.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.fiap.order.usecases - -import com.fiap.order.domain.entities.Order - -interface CompleteOrderUseCase { - fun completeOrder(orderNumber: Long): Order -} diff --git a/src/main/kotlin/com/fiap/order/usecases/ConfirmOrderUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/ConfirmOrderUseCase.kt deleted file mode 100644 index aa6a74d..0000000 --- a/src/main/kotlin/com/fiap/order/usecases/ConfirmOrderUseCase.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.fiap.order.usecases - -import com.fiap.order.domain.entities.Order - -interface ConfirmOrderUseCase { - fun confirmOrder(orderNumber: Long): Order -} diff --git a/src/main/kotlin/com/fiap/order/usecases/CreateCustomerUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/CreateCustomerUseCase.kt index 94c5622..6e1706a 100644 --- a/src/main/kotlin/com/fiap/order/usecases/CreateCustomerUseCase.kt +++ b/src/main/kotlin/com/fiap/order/usecases/CreateCustomerUseCase.kt @@ -2,7 +2,6 @@ package com.fiap.order.usecases import com.fiap.order.domain.entities.Customer - interface CreateCustomerUseCase { fun create(customer: Customer): Customer } diff --git a/src/main/kotlin/com/fiap/order/usecases/CreateOrderUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/CreateOrderUseCase.kt new file mode 100644 index 0000000..86021b3 --- /dev/null +++ b/src/main/kotlin/com/fiap/order/usecases/CreateOrderUseCase.kt @@ -0,0 +1,9 @@ +package com.fiap.order.usecases + +import com.fiap.order.domain.entities.OrderItem +import com.fiap.order.driver.web.response.PendingOrderResponse +import java.util.* + +interface CreateOrderUseCase { + fun create(customerId: UUID?, items: List): PendingOrderResponse +} diff --git a/src/main/kotlin/com/fiap/order/usecases/LoadCustomerUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/LoadCustomerUseCase.kt index 9b91830..d2a4305 100644 --- a/src/main/kotlin/com/fiap/order/usecases/LoadCustomerUseCase.kt +++ b/src/main/kotlin/com/fiap/order/usecases/LoadCustomerUseCase.kt @@ -5,6 +5,8 @@ import java.util.* interface LoadCustomerUseCase { fun getById(customerId: UUID): Customer + fun findAll(): List + fun findById(customerId: UUID): Customer? } diff --git a/src/main/kotlin/com/fiap/order/usecases/LoadOrderUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/LoadOrderUseCase.kt index da76f7b..865eb0b 100644 --- a/src/main/kotlin/com/fiap/order/usecases/LoadOrderUseCase.kt +++ b/src/main/kotlin/com/fiap/order/usecases/LoadOrderUseCase.kt @@ -13,8 +13,5 @@ interface LoadOrderUseCase { fun findByCustomerId(customerId: UUID): List - fun findByCustomerIdAndStatus( - customerId: UUID, - status: OrderStatus, - ): List + fun findByCustomerIdAndStatus(customerId: UUID, status: OrderStatus): List } diff --git a/src/main/kotlin/com/fiap/order/usecases/LoadPaymentUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/LoadPaymentUseCase.kt deleted file mode 100644 index 3e8c56f..0000000 --- a/src/main/kotlin/com/fiap/order/usecases/LoadPaymentUseCase.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.fiap.order.usecases - -import com.fiap.order.domain.entities.Payment - -interface LoadPaymentUseCase { - fun getByOrderNumber(orderNumber: Long): Payment -} diff --git a/src/main/kotlin/com/fiap/order/usecases/PlaceOrderUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/PlaceOrderUseCase.kt deleted file mode 100644 index 62be255..0000000 --- a/src/main/kotlin/com/fiap/order/usecases/PlaceOrderUseCase.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.fiap.order.usecases - -import com.fiap.order.domain.entities.Order -import com.fiap.order.domain.entities.OrderItem -import java.util.* - -interface PlaceOrderUseCase { - fun create( - customerId: UUID?, - items: List, - ): Order -} diff --git a/src/main/kotlin/com/fiap/order/usecases/ProvidePaymentRequestUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/ProvidePaymentRequestUseCase.kt deleted file mode 100644 index 4abde88..0000000 --- a/src/main/kotlin/com/fiap/order/usecases/ProvidePaymentRequestUseCase.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.fiap.order.usecases - -import com.fiap.order.domain.entities.Order -import com.fiap.order.driver.web.request.PaymentRequest - -interface ProvidePaymentRequestUseCase { - fun providePaymentRequest(order: Order): PaymentRequest -} diff --git a/src/main/kotlin/com/fiap/order/usecases/RequestPaymentUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/RequestPaymentUseCase.kt new file mode 100644 index 0000000..994fd4c --- /dev/null +++ b/src/main/kotlin/com/fiap/order/usecases/RequestPaymentUseCase.kt @@ -0,0 +1,8 @@ +package com.fiap.order.usecases + +import com.fiap.order.domain.entities.Order +import com.fiap.order.driver.web.response.PaymentResponse + +interface RequestPaymentUseCase { + fun requestPayment(order: Order): PaymentResponse +} diff --git a/src/main/kotlin/com/fiap/order/usecases/SearchCustomerUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/SearchCustomerUseCase.kt index c1527e0..943b9e3 100644 --- a/src/main/kotlin/com/fiap/order/usecases/SearchCustomerUseCase.kt +++ b/src/main/kotlin/com/fiap/order/usecases/SearchCustomerUseCase.kt @@ -2,8 +2,8 @@ package com.fiap.order.usecases import com.fiap.order.domain.entities.Customer - interface SearchCustomerUseCase { fun searchByName(name: String): List + fun searchByEmail(email: String): Customer? } diff --git a/src/main/kotlin/com/fiap/order/usecases/UpdateCustomerUseCase.kt b/src/main/kotlin/com/fiap/order/usecases/UpdateCustomerUseCase.kt index c56257d..73f10be 100644 --- a/src/main/kotlin/com/fiap/order/usecases/UpdateCustomerUseCase.kt +++ b/src/main/kotlin/com/fiap/order/usecases/UpdateCustomerUseCase.kt @@ -2,7 +2,6 @@ package com.fiap.order.usecases import com.fiap.order.domain.entities.Customer - interface UpdateCustomerUseCase { fun update(customer: Customer): Customer } diff --git a/src/main/kotlin/com/fiap/order/usecases/services/CustomerService.kt b/src/main/kotlin/com/fiap/order/usecases/services/CustomerService.kt index 8ad700e..f2d80d6 100644 --- a/src/main/kotlin/com/fiap/order/usecases/services/CustomerService.kt +++ b/src/main/kotlin/com/fiap/order/usecases/services/CustomerService.kt @@ -4,7 +4,11 @@ import com.fiap.order.adapter.gateway.CustomerGateway import com.fiap.order.domain.entities.Customer import com.fiap.order.domain.errors.ErrorType import com.fiap.order.domain.errors.SelfOrderManagementException -import com.fiap.order.usecases.* +import com.fiap.order.usecases.CreateCustomerUseCase +import com.fiap.order.usecases.LoadCustomerUseCase +import com.fiap.order.usecases.RemoveCustomerUseCase +import com.fiap.order.usecases.SearchCustomerUseCase +import com.fiap.order.usecases.UpdateCustomerUseCase import org.slf4j.LoggerFactory import java.util.* @@ -14,7 +18,8 @@ class CustomerService( SearchCustomerUseCase, CreateCustomerUseCase, UpdateCustomerUseCase, - RemoveCustomerUseCase { + RemoveCustomerUseCase +{ private val log = LoggerFactory.getLogger(javaClass) override fun getById(customerId: UUID): Customer { diff --git a/src/main/kotlin/com/fiap/order/usecases/services/OrderService.kt b/src/main/kotlin/com/fiap/order/usecases/services/OrderService.kt index c9582b6..0e04aeb 100644 --- a/src/main/kotlin/com/fiap/order/usecases/services/OrderService.kt +++ b/src/main/kotlin/com/fiap/order/usecases/services/OrderService.kt @@ -7,8 +7,14 @@ import com.fiap.order.domain.entities.OrderItem import com.fiap.order.domain.errors.ErrorType import com.fiap.order.domain.errors.SelfOrderManagementException import com.fiap.order.domain.valueobjects.OrderStatus -import com.fiap.order.domain.valueobjects.PaymentStatus -import com.fiap.order.usecases.* +import com.fiap.order.driver.web.response.PendingOrderResponse +import com.fiap.order.usecases.AdjustStockUseCase +import com.fiap.order.usecases.ChangeOrderStatusUseCase +import com.fiap.order.usecases.LoadCustomerUseCase +import com.fiap.order.usecases.LoadOrderUseCase +import com.fiap.order.usecases.LoadProductUseCase +import com.fiap.order.usecases.CreateOrderUseCase +import com.fiap.order.usecases.RequestPaymentUseCase import org.slf4j.LoggerFactory import java.time.LocalDate import java.util.* @@ -16,16 +22,14 @@ import java.util.* open class OrderService( private val orderRepository: OrderGateway, private val getCustomersUseCase: LoadCustomerUseCase, - private val getProductUseCase: LoadProductUseCase, + private val loadProductUseCase: LoadProductUseCase, private val adjustInventoryUseCase: AdjustStockUseCase, - private val providePaymentRequestUseCase: ProvidePaymentRequestUseCase, + private val providePaymentRequestUseCase: RequestPaymentUseCase, private val transactionalRepository: TransactionalGateway, ) : LoadOrderUseCase, - PlaceOrderUseCase, - ConfirmOrderUseCase, - PrepareOrderUseCase, - CompleteOrderUseCase, - CancelOrderStatusUseCase { + CreateOrderUseCase, + ChangeOrderStatusUseCase +{ private val log = LoggerFactory.getLogger(javaClass) override fun getByOrderNumber(orderNumber: Long): Order { @@ -55,7 +59,7 @@ open class OrderService( override fun create( customerId: UUID?, items: List, - ): Order { + ): PendingOrderResponse { return transactionalRepository.transaction { if (items.isEmpty()) { throw SelfOrderManagementException( @@ -66,7 +70,7 @@ open class OrderService( val products = items.flatMap { - val product = getProductUseCase.getByProductNumber(it.productNumber) + val product = loadProductUseCase.getByProductNumber(it.productNumber) if (!product.isLogicalItem()!!) { product.components?.mapNotNull { p -> p.number }?.forEach { componentNumber -> adjustInventoryUseCase.decrement(componentNumber, it.quantity) @@ -75,7 +79,7 @@ open class OrderService( MutableList(it.quantity.toInt()) { product } } - val order = orderRepository.upsert( + var order = orderRepository.upsert( Order( number = null, date = LocalDate.now(), @@ -86,11 +90,21 @@ open class OrderService( ) ) - providePaymentRequestUseCase.providePaymentRequest(order) + val payment = providePaymentRequestUseCase.requestPayment(order) - log.info("Storing order $order") - orderRepository.upsert(order.copy(status = OrderStatus.PENDING) - .copy(items = order.items.map { i -> i.copy(orderNumber = order.number) })) + order = orderRepository.upsert( + order.copy( + status = OrderStatus.PENDING, + items = order.items.map { i -> i.copy(orderNumber = order.number) }, + ) + ) + + log.info("Stored order: $order") + + PendingOrderResponse( + order = order, + payment = payment, + ) } } diff --git a/src/main/kotlin/com/fiap/order/usecases/services/PaymentService.kt b/src/main/kotlin/com/fiap/order/usecases/services/PaymentService.kt index 1708cb8..2738c1e 100644 --- a/src/main/kotlin/com/fiap/order/usecases/services/PaymentService.kt +++ b/src/main/kotlin/com/fiap/order/usecases/services/PaymentService.kt @@ -2,32 +2,18 @@ package com.fiap.order.usecases.services import com.fiap.order.adapter.gateway.PaymentGateway import com.fiap.order.domain.entities.Order -import com.fiap.order.domain.entities.Payment -import com.fiap.order.domain.errors.ErrorType -import com.fiap.order.domain.errors.SelfOrderManagementException -import com.fiap.order.driver.web.request.PaymentRequest -import com.fiap.order.usecases.LoadPaymentUseCase -import com.fiap.order.usecases.ProvidePaymentRequestUseCase +import com.fiap.order.driver.web.response.PaymentResponse +import com.fiap.order.usecases.RequestPaymentUseCase import org.slf4j.LoggerFactory class PaymentService( private val paymentGateway: PaymentGateway, -) : - LoadPaymentUseCase, - ProvidePaymentRequestUseCase { +) : RequestPaymentUseCase +{ private val log = LoggerFactory.getLogger(javaClass) - - override fun getByOrderNumber(orderNumber: Long): Payment { - log.info("Requesting payment for order [$orderNumber]") - return paymentGateway.findByOrderNumber(orderNumber) - ?: throw SelfOrderManagementException( - errorType = ErrorType.PAYMENT_NOT_FOUND, - message = "Payment not found for order [$orderNumber]", - ) - } - override fun providePaymentRequest(order: Order): PaymentRequest { + override fun requestPayment(order: Order): PaymentResponse { log.info("Requesting payment request for order $order") - return paymentGateway.createFromOrder(order) + return paymentGateway.requestPayment(order) } } diff --git a/src/main/kotlin/com/fiap/order/usecases/services/ProductService.kt b/src/main/kotlin/com/fiap/order/usecases/services/ProductService.kt index fa384e5..f49c0ee 100644 --- a/src/main/kotlin/com/fiap/order/usecases/services/ProductService.kt +++ b/src/main/kotlin/com/fiap/order/usecases/services/ProductService.kt @@ -9,7 +9,8 @@ import org.slf4j.LoggerFactory class ProductService( private val productGateway: ProductGateway, -) : LoadProductUseCase { +) : LoadProductUseCase +{ private val log = LoggerFactory.getLogger(javaClass) override fun getByProductNumber(productNumber: Long): Product { diff --git a/src/main/kotlin/com/fiap/order/usecases/services/StockService.kt b/src/main/kotlin/com/fiap/order/usecases/services/StockService.kt index 2fa7130..649d245 100644 --- a/src/main/kotlin/com/fiap/order/usecases/services/StockService.kt +++ b/src/main/kotlin/com/fiap/order/usecases/services/StockService.kt @@ -7,21 +7,16 @@ import org.slf4j.LoggerFactory class StockService( private val stockGateway: StockGateway, -) : AdjustStockUseCase { +) : AdjustStockUseCase +{ private val log = LoggerFactory.getLogger(javaClass) - override fun increment( - componentNumber: Long, - quantity: Long, - ): Stock { + override fun increment(componentNumber: Long, quantity: Long): Stock { log.info("Requesting stock of [$componentNumber] to be incremented") return stockGateway.increment(componentNumber, quantity) } - override fun decrement( - componentNumber: Long, - quantity: Long, - ): Stock { + override fun decrement(componentNumber: Long, quantity: Long): Stock { log.info("Requesting stock of [$componentNumber] to be decremented") return stockGateway.decrement(componentNumber, quantity) } diff --git a/src/test/kotlin/TestFixtures.kt b/src/test/kotlin/TestFixtures.kt index 6da8ca4..31215f6 100644 --- a/src/test/kotlin/TestFixtures.kt +++ b/src/test/kotlin/TestFixtures.kt @@ -1,14 +1,18 @@ -import com.fiap.order.domain.entities.* +import com.fiap.order.domain.entities.Component +import com.fiap.order.domain.entities.Customer +import com.fiap.order.domain.entities.Order +import com.fiap.order.domain.entities.OrderItem +import com.fiap.order.domain.entities.Product +import com.fiap.order.domain.entities.Stock import com.fiap.order.domain.valueobjects.OrderStatus import com.fiap.order.domain.valueobjects.PaymentStatus import com.fiap.order.domain.valueobjects.ProductCategory -import com.fiap.order.driver.web.request.PaymentRequest +import com.fiap.order.driver.web.response.PaymentResponse import java.math.BigDecimal import java.time.LocalDate import java.time.LocalDateTime import java.util.* - fun createCustomer( id: UUID = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"), document: String = "444.555.666-77", @@ -79,31 +83,22 @@ fun createOrderItem( quantity = quantity, ) -fun createPayment( - orderNumber: Long = 98765, +fun createPaymentResponse( + id: String = "49f285e9-f748-4f57-ad58-eb6c72cd734f", + orderNumber: Long = 1, externalOrderId: String = "66b0f5f7-9997-4f49-a203-3dab2d936b50", externalOrderGlobalId: String? = null, paymentInfo: String = "00020101021243650016COM.MERCADOLIBRE...", createdAt: LocalDateTime = LocalDateTime.parse("2023-10-01T18:00:00"), status: PaymentStatus = PaymentStatus.PENDING, statusChangedAt: LocalDateTime = LocalDateTime.parse("2023-10-01T18:00:00"), -) = Payment( +) = PaymentResponse( + id = id, orderNumber = orderNumber, externalOrderId = externalOrderId, externalOrderGlobalId = externalOrderGlobalId, paymentInfo = paymentInfo, createdAt = createdAt, status = status, - statusChangedAt, + statusChangedAt = statusChangedAt, ) - -fun createPaymentRequest( - externalOrderId: String = "66b0f5f7-9997-4f49-a203-3dab2d936b50", - externalOrderGlobalId: String? = null, - paymentInfo: String = "00020101021243650016COM.MERCADOLIBRE...", -) = PaymentRequest( - externalOrderId = externalOrderId, - externalOrderGlobalId = externalOrderGlobalId, - paymentInfo = paymentInfo, -) - diff --git a/src/test/kotlin/com/fiap/order/application/services/OrderServiceTest.kt b/src/test/kotlin/com/fiap/order/application/services/OrderServiceTest.kt index d433eb3..262ac23 100644 --- a/src/test/kotlin/com/fiap/order/application/services/OrderServiceTest.kt +++ b/src/test/kotlin/com/fiap/order/application/services/OrderServiceTest.kt @@ -6,14 +6,15 @@ import com.fiap.order.domain.entities.OrderItem import com.fiap.order.domain.errors.ErrorType import com.fiap.order.domain.errors.SelfOrderManagementException import com.fiap.order.domain.valueobjects.OrderStatus -import com.fiap.order.domain.valueobjects.PaymentStatus -import com.fiap.order.usecases.* +import com.fiap.order.usecases.AdjustStockUseCase +import com.fiap.order.usecases.LoadCustomerUseCase +import com.fiap.order.usecases.LoadProductUseCase +import com.fiap.order.usecases.RequestPaymentUseCase import com.fiap.order.usecases.services.OrderService import createCustomer import createOrder import createOrderItem -import createPayment -import createPaymentRequest +import createPaymentResponse import createProduct import createStock import io.mockk.every @@ -35,8 +36,7 @@ class OrderServiceTest { private val getCustomersUseCase = mockk() private val getProductUseCase = mockk() private val adjustInventoryUseCase = mockk() - private val loadPaymentUseCase = mockk() - private val providePaymentRequestUseCase = mockk() + private val requestPaymentUseCase = mockk() private val transactionalRepository = TransactionalGatewayImpl() private val orderService = @@ -45,7 +45,7 @@ class OrderServiceTest { getCustomersUseCase, getProductUseCase, adjustInventoryUseCase, - providePaymentRequestUseCase, + requestPaymentUseCase, transactionalRepository, ) @@ -53,7 +53,7 @@ class OrderServiceTest { fun setUp() { every { getCustomersUseCase.getById(any()) } returns createCustomer() every { getProductUseCase.getByProductNumber(any()) } returns createProduct() - every { providePaymentRequestUseCase.providePaymentRequest(any()) } returns createPaymentRequest() + every { requestPaymentUseCase.requestPayment(any()) } returns createPaymentResponse() } @AfterEach @@ -64,7 +64,7 @@ class OrderServiceTest { @Nested inner class GetByOrderNumberTest { @Test - fun `getByOrderNumber should return an Order when it exists`() { + fun `should find existent order`() { val order = createOrder() every { orderRepository.findByOrderNumber(order.number!!) } returns order @@ -75,8 +75,8 @@ class OrderServiceTest { } @Test - fun `getByOrderNumber should throw an exception when the order is not found`() { - val orderNumber = 67890L + fun `should not find non-existent order`() { + val orderNumber = 1L every { orderRepository.findByOrderNumber(orderNumber) } returns null @@ -89,7 +89,7 @@ class OrderServiceTest { @Nested inner class CreateTest { @Test - fun `create should return a valid Order when items are provided`() { + fun `create create order`() { val items = listOf(createOrderItem()) every { adjustInventoryUseCase.decrement(any(), any()) } returns createStock() @@ -98,9 +98,9 @@ class OrderServiceTest { val result = orderService.create(null, items) assertThat(result).isNotNull() - assertThat(result.number).isNotNull() - assertThat(result.items).hasSize(1) - assertThat(result.total).isEqualTo(BigDecimal("50.00")) + assertThat(result.order.number).isNotNull() + assertThat(result.order.items).hasSize(1) + assertThat(result.order.total).isEqualTo(BigDecimal("50.00")) } @Test @@ -120,7 +120,6 @@ class OrderServiceTest { val order = createOrder(status = OrderStatus.PENDING) every { orderRepository.findByOrderNumber(any()) } returns order - every { loadPaymentUseCase.getByOrderNumber(any()) } returns createPayment(status = PaymentStatus.CONFIRMED) every { orderRepository.upsert(any()) } answers { firstArg() } val result = orderService.confirmOrder(order.number!!) @@ -135,9 +134,6 @@ class OrderServiceTest { val order = createOrder(status = OrderStatus.PENDING) every { orderRepository.findByOrderNumber(any()) } returns order - every { loadPaymentUseCase.getByOrderNumber(any()) } throws ( - SelfOrderManagementException(ErrorType.PAYMENT_NOT_FOUND, message = "") - ) every { orderRepository.upsert(any()) } assertThatThrownBy { orderService.confirmOrder(order.number!!) } @@ -152,7 +148,6 @@ class OrderServiceTest { every { orderRepository.findByOrderNumber(any()) } returns order every { orderRepository.upsert(order) } returns order - every { loadPaymentUseCase.getByOrderNumber(any()) } returns createPayment(status = PaymentStatus.PENDING) every { orderRepository.upsert(any()) } answers { firstArg() } assertThatThrownBy { orderService.confirmOrder(order.number!!) } @@ -167,7 +162,6 @@ class OrderServiceTest { every { orderRepository.findByOrderNumber(any()) } returns order every { orderRepository.upsert(order) } answers { firstArg() } - every { loadPaymentUseCase.getByOrderNumber(any()) } returns createPayment(status = PaymentStatus.CONFIRMED) assertThatThrownBy { orderService.confirmOrder(order.number!!) } .isInstanceOf(SelfOrderManagementException::class.java)