-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53f972c
commit adae578
Showing
20 changed files
with
215 additions
and
25 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
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
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
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
src/main/kotlin/com/fiap/order/adapter/messaging/config/MessagingConfig.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.fiap.order.adapter.messaging.config | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fiap.order.adapter.messaging.sender.PaymentSender | ||
import com.fiap.order.adapter.messaging.sender.impl.PaymentSenderImpl | ||
import io.awspring.cloud.sns.core.SnsTemplate | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class MessagingConfig { | ||
|
||
@Bean("PaymentSender") | ||
fun createPaymentSender(snsTemplate: SnsTemplate, | ||
@Value("\${topic.request-payment}") topicArn: String, | ||
objectMapper: ObjectMapper) : PaymentSender { | ||
return PaymentSenderImpl(snsTemplate, topicArn, objectMapper) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/fiap/order/adapter/messaging/sender/PaymentSender.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,7 @@ | ||
package com.fiap.order.adapter.messaging.sender | ||
|
||
import com.fiap.order.driver.web.request.PaymentRequest | ||
|
||
interface PaymentSender { | ||
fun requestPayment(paymentRequest:PaymentRequest) | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/fiap/order/adapter/messaging/sender/impl/PaymentSenderImpl.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,15 @@ | ||
package com.fiap.order.adapter.messaging.sender.impl | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fiap.order.adapter.messaging.sender.PaymentSender | ||
import com.fiap.order.driver.web.request.PaymentRequest | ||
import io.awspring.cloud.sns.core.SnsTemplate | ||
import org.springframework.messaging.support.GenericMessage | ||
|
||
|
||
class PaymentSenderImpl(private val snsTemplate: SnsTemplate, private val topicName: String, private val mapper: ObjectMapper) : PaymentSender { | ||
|
||
override fun requestPayment(paymentRequest: PaymentRequest) { | ||
snsTemplate.send(topicName, GenericMessage(mapper.writeValueAsString(paymentRequest))) | ||
} | ||
} |
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,15 @@ | ||
package com.fiap.order.domain.entities | ||
|
||
import com.fiap.order.domain.valueobjects.PaymentStatus | ||
import java.time.LocalDateTime | ||
|
||
data class Payment( | ||
val id: String, | ||
val orderNumber: Long, | ||
val externalOrderId: String, | ||
val externalOrderGlobalId: String?, | ||
val paymentInfo: String, | ||
val createdAt: LocalDateTime, | ||
val status: PaymentStatus, | ||
val statusChangedAt: LocalDateTime, | ||
) |
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
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/fiap/order/driver/messaging/consumer/OrderConsumer.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,32 @@ | ||
package com.fiap.order.driver.messaging.consumer | ||
|
||
import com.fiap.order.domain.valueobjects.PaymentStatus | ||
import com.fiap.order.driver.messaging.event.PaymentEvent | ||
import com.fiap.order.driver.messaging.event.toDomain | ||
import com.fiap.order.usecases.CreateOrderUseCase | ||
import com.fiap.order.usecases.services.OrderService | ||
import io.awspring.cloud.sqs.annotation.SqsListener | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.messaging.MessageHeaders | ||
import org.springframework.messaging.handler.annotation.Headers | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class OrderConsumer( | ||
private val createOrderUseCase: CreateOrderUseCase, | ||
) { | ||
|
||
private val log = LoggerFactory.getLogger(javaClass) | ||
|
||
|
||
@SqsListener("\${sqs.queues.request-payment-response}") | ||
fun onMessage(message: PaymentEvent, @Headers headers: MessageHeaders) { | ||
when (message.status) { | ||
PaymentStatus.PENDING -> createOrderUseCase.acceptPending(message.toDomain()) | ||
PaymentStatus.EXPIRED -> TODO() | ||
PaymentStatus.FAILED -> TODO() | ||
PaymentStatus.CONFIRMED -> TODO() | ||
} | ||
log.info(message.toString()) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/fiap/order/driver/messaging/event/PaymentEvent.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,27 @@ | ||
package com.fiap.order.driver.messaging.event | ||
|
||
import com.fiap.order.domain.entities.Payment | ||
import com.fiap.order.domain.valueobjects.PaymentStatus | ||
import java.time.LocalDateTime | ||
|
||
data class PaymentEvent( | ||
val id: String, | ||
val orderNumber: Long, | ||
val externalOrderId: String, | ||
val externalOrderGlobalId: String?, | ||
val paymentInfo: String, | ||
val createdAt: LocalDateTime, | ||
val status: PaymentStatus, | ||
val statusChangedAt: LocalDateTime, | ||
) | ||
|
||
fun PaymentEvent.toDomain() = Payment( | ||
id = id, | ||
orderNumber = orderNumber, | ||
externalOrderId = externalOrderId, | ||
externalOrderGlobalId = externalOrderGlobalId, | ||
paymentInfo = paymentInfo, | ||
createdAt = createdAt, | ||
status = status, | ||
statusChangedAt = statusChangedAt, | ||
) |
3 changes: 2 additions & 1 deletion
3
src/main/kotlin/com/fiap/order/driver/web/response/PendingOrderResponse.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package com.fiap.order.driver.web.response | ||
|
||
import com.fiap.order.domain.entities.Order | ||
import com.fiap.order.domain.entities.Payment | ||
|
||
data class PendingOrderResponse( | ||
val order: Order, | ||
val payment: PaymentResponse, | ||
val payment: Payment?, | ||
) |
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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.fiap.order.usecases | ||
|
||
import com.fiap.order.domain.entities.Order | ||
import com.fiap.order.domain.entities.OrderItem | ||
import com.fiap.order.domain.entities.Payment | ||
import com.fiap.order.domain.valueobjects.PaymentStatus | ||
import com.fiap.order.driver.messaging.event.PaymentEvent | ||
import com.fiap.order.driver.web.response.PendingOrderResponse | ||
import java.util.* | ||
|
||
interface CreateOrderUseCase { | ||
fun create(customerId: UUID?, items: List<OrderItem>): PendingOrderResponse | ||
fun requestCreate(customerId: UUID?, items: List<OrderItem>): PendingOrderResponse | ||
fun acceptPending(payment: Payment) : PendingOrderResponse | ||
} |
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
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
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
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
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
Oops, something went wrong.