diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..8af972cded --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/.gradle/9.3.0/checksums/checksums.lock b/.gradle/9.3.0/checksums/checksums.lock new file mode 100644 index 0000000000..800d9bdc75 Binary files /dev/null and b/.gradle/9.3.0/checksums/checksums.lock differ diff --git a/.gradle/9.3.0/checksums/md5-checksums.bin b/.gradle/9.3.0/checksums/md5-checksums.bin new file mode 100644 index 0000000000..b3978e0d10 Binary files /dev/null and b/.gradle/9.3.0/checksums/md5-checksums.bin differ diff --git a/.gradle/9.3.0/checksums/sha1-checksums.bin b/.gradle/9.3.0/checksums/sha1-checksums.bin new file mode 100644 index 0000000000..338b2511eb Binary files /dev/null and b/.gradle/9.3.0/checksums/sha1-checksums.bin differ diff --git a/.gradle/9.3.0/executionHistory/executionHistory.bin b/.gradle/9.3.0/executionHistory/executionHistory.bin new file mode 100644 index 0000000000..35491e54e6 Binary files /dev/null and b/.gradle/9.3.0/executionHistory/executionHistory.bin differ diff --git a/.gradle/9.3.0/executionHistory/executionHistory.lock b/.gradle/9.3.0/executionHistory/executionHistory.lock new file mode 100644 index 0000000000..bba7d32c36 Binary files /dev/null and b/.gradle/9.3.0/executionHistory/executionHistory.lock differ diff --git a/.gradle/9.3.0/fileChanges/last-build.bin b/.gradle/9.3.0/fileChanges/last-build.bin new file mode 100644 index 0000000000..f76dd238ad Binary files /dev/null and b/.gradle/9.3.0/fileChanges/last-build.bin differ diff --git a/.gradle/9.3.0/fileHashes/fileHashes.bin b/.gradle/9.3.0/fileHashes/fileHashes.bin new file mode 100644 index 0000000000..63b5709206 Binary files /dev/null and b/.gradle/9.3.0/fileHashes/fileHashes.bin differ diff --git a/.gradle/9.3.0/fileHashes/fileHashes.lock b/.gradle/9.3.0/fileHashes/fileHashes.lock new file mode 100644 index 0000000000..59e89d52b1 Binary files /dev/null and b/.gradle/9.3.0/fileHashes/fileHashes.lock differ diff --git a/.gradle/9.3.0/fileHashes/resourceHashesCache.bin b/.gradle/9.3.0/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000000..e53d7d85fe Binary files /dev/null and b/.gradle/9.3.0/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/9.3.0/gc.properties b/.gradle/9.3.0/gc.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000000..16af45c9b1 Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000000..59a86641d7 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Wed Feb 18 12:06:26 PET 2026 +gradle.version=9.3.0 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000000..4a6ad95853 Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe new file mode 100644 index 0000000000..580c710dd8 Binary files /dev/null and b/.gradle/file-system.probe differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..ab1f4164ed --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000000..418c823649 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +yape \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000000..d4fb165e39 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.agent.xml b/.idea/copilot.data.migration.agent.xml new file mode 100644 index 0000000000..4ea72a911a --- /dev/null +++ b/.idea/copilot.data.migration.agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.ask2agent.xml b/.idea/copilot.data.migration.ask2agent.xml new file mode 100644 index 0000000000..1f2ea11e7f --- /dev/null +++ b/.idea/copilot.data.migration.ask2agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/copilot.data.migration.edit.xml b/.idea/copilot.data.migration.edit.xml new file mode 100644 index 0000000000..8648f9401a --- /dev/null +++ b/.idea/copilot.data.migration.edit.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000000..ce1c62c7c6 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..956e012a3d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..bf2f3c6e5f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/yape.main.iml b/.idea/modules/yape.main.iml new file mode 100644 index 0000000000..afc1871cc7 --- /dev/null +++ b/.idea/modules/yape.main.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..35eb1ddfbb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000000..5a04dab98c --- /dev/null +++ b/HELP.md @@ -0,0 +1,24 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/4.0.2/gradle-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/4.0.2/gradle-plugin/packaging-oci-image.html) +* [Spring for Apache Kafka](https://docs.spring.io/spring-boot/4.0.2/reference/messaging/kafka.html) +* [Spring Web](https://docs.spring.io/spring-boot/4.0.2/reference/web/servlet.html) +* [OAuth2 Client](https://docs.spring.io/spring-boot/4.0.2/reference/web/spring-security.html#web.security.oauth2.client) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..b18312b537 --- /dev/null +++ b/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.5' + id 'io.spring.dependency-management' version '1.1.6' +} + +group = 'com.yape' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + runtimeOnly 'org.postgresql:postgresql' + + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.kafka:spring-kafka' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' +} + +tasks.named('test') { + useJUnitPlatform() +} + +// Opcional: fuerza encoding consistente +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' +} diff --git a/build/classes/java/main/com/yape/yape/YapeServiceApplication.class b/build/classes/java/main/com/yape/yape/YapeServiceApplication.class new file mode 100644 index 0000000000..1841ee8536 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/YapeServiceApplication.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/CreateTransactionRequestDto$CreateTransactionRequestDtoBuilder.class b/build/classes/java/main/com/yape/yape/application/dto/CreateTransactionRequestDto$CreateTransactionRequestDtoBuilder.class new file mode 100644 index 0000000000..0f2d2dd830 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/CreateTransactionRequestDto$CreateTransactionRequestDtoBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/CreateTransactionRequestDto.class b/build/classes/java/main/com/yape/yape/application/dto/CreateTransactionRequestDto.class new file mode 100644 index 0000000000..1f147e0411 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/CreateTransactionRequestDto.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/DeleteTransactionResponseDto.class b/build/classes/java/main/com/yape/yape/application/dto/DeleteTransactionResponseDto.class new file mode 100644 index 0000000000..3a536656d6 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/DeleteTransactionResponseDto.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionCreatedEvent$TransactionCreatedEventBuilder.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionCreatedEvent$TransactionCreatedEventBuilder.class new file mode 100644 index 0000000000..f16cb36412 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionCreatedEvent$TransactionCreatedEventBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionCreatedEvent.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionCreatedEvent.class new file mode 100644 index 0000000000..2baf054138 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionCreatedEvent.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionResponseDtoBuilder.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionResponseDtoBuilder.class new file mode 100644 index 0000000000..28b7300988 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionResponseDtoBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionStatusDto$TransactionStatusDtoBuilder.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionStatusDto$TransactionStatusDtoBuilder.class new file mode 100644 index 0000000000..adc25d646a Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionStatusDto$TransactionStatusDtoBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionStatusDto.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionStatusDto.class new file mode 100644 index 0000000000..c6a86ade0a Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionStatusDto.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionTypeDto$TransactionTypeDtoBuilder.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionTypeDto$TransactionTypeDtoBuilder.class new file mode 100644 index 0000000000..8400dea88a Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionTypeDto$TransactionTypeDtoBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionTypeDto.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionTypeDto.class new file mode 100644 index 0000000000..883619bfa1 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto$TransactionTypeDto.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto.class new file mode 100644 index 0000000000..c9d8d01931 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionResponseDto.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionStatusUpdatedEvent$TransactionStatusUpdatedEventBuilder.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionStatusUpdatedEvent$TransactionStatusUpdatedEventBuilder.class new file mode 100644 index 0000000000..500afc89de Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionStatusUpdatedEvent$TransactionStatusUpdatedEventBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/TransactionStatusUpdatedEvent.class b/build/classes/java/main/com/yape/yape/application/dto/TransactionStatusUpdatedEvent.class new file mode 100644 index 0000000000..109b6771a1 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/TransactionStatusUpdatedEvent.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/UpdateTransactionRequestDto$UpdateTransactionRequestDtoBuilder.class b/build/classes/java/main/com/yape/yape/application/dto/UpdateTransactionRequestDto$UpdateTransactionRequestDtoBuilder.class new file mode 100644 index 0000000000..314ef40339 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/UpdateTransactionRequestDto$UpdateTransactionRequestDtoBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/application/dto/UpdateTransactionRequestDto.class b/build/classes/java/main/com/yape/yape/application/dto/UpdateTransactionRequestDto.class new file mode 100644 index 0000000000..1b64b034ba Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/dto/UpdateTransactionRequestDto.class differ diff --git a/build/classes/java/main/com/yape/yape/application/mapper/TransactionResponseMapper.class b/build/classes/java/main/com/yape/yape/application/mapper/TransactionResponseMapper.class new file mode 100644 index 0000000000..a0f7fdf9b7 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/mapper/TransactionResponseMapper.class differ diff --git a/build/classes/java/main/com/yape/yape/application/usecase/CreateTransactionUseCase.class b/build/classes/java/main/com/yape/yape/application/usecase/CreateTransactionUseCase.class new file mode 100644 index 0000000000..fa3289131b Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/usecase/CreateTransactionUseCase.class differ diff --git a/build/classes/java/main/com/yape/yape/application/usecase/DeleteTransactionUseCase.class b/build/classes/java/main/com/yape/yape/application/usecase/DeleteTransactionUseCase.class new file mode 100644 index 0000000000..69b6891b4e Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/usecase/DeleteTransactionUseCase.class differ diff --git a/build/classes/java/main/com/yape/yape/application/usecase/GetTransactionUseCase.class b/build/classes/java/main/com/yape/yape/application/usecase/GetTransactionUseCase.class new file mode 100644 index 0000000000..f34e4409f7 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/usecase/GetTransactionUseCase.class differ diff --git a/build/classes/java/main/com/yape/yape/application/usecase/UpdateTransactionStatusUseCase.class b/build/classes/java/main/com/yape/yape/application/usecase/UpdateTransactionStatusUseCase.class new file mode 100644 index 0000000000..a77c0920fc Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/usecase/UpdateTransactionStatusUseCase.class differ diff --git a/build/classes/java/main/com/yape/yape/application/usecase/UpdateTransactionUseCase.class b/build/classes/java/main/com/yape/yape/application/usecase/UpdateTransactionUseCase.class new file mode 100644 index 0000000000..99f0327d14 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/application/usecase/UpdateTransactionUseCase.class differ diff --git a/build/classes/java/main/com/yape/yape/domain/exception/TransactionAlreadyFinalizedException.class b/build/classes/java/main/com/yape/yape/domain/exception/TransactionAlreadyFinalizedException.class new file mode 100644 index 0000000000..9d1432948b Binary files /dev/null and b/build/classes/java/main/com/yape/yape/domain/exception/TransactionAlreadyFinalizedException.class differ diff --git a/build/classes/java/main/com/yape/yape/domain/exception/TransactionNotFoundException.class b/build/classes/java/main/com/yape/yape/domain/exception/TransactionNotFoundException.class new file mode 100644 index 0000000000..17dfcec83f Binary files /dev/null and b/build/classes/java/main/com/yape/yape/domain/exception/TransactionNotFoundException.class differ diff --git a/build/classes/java/main/com/yape/yape/domain/model/Transaction.class b/build/classes/java/main/com/yape/yape/domain/model/Transaction.class new file mode 100644 index 0000000000..97f87e46a2 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/domain/model/Transaction.class differ diff --git a/build/classes/java/main/com/yape/yape/domain/model/TransactionStatus.class b/build/classes/java/main/com/yape/yape/domain/model/TransactionStatus.class new file mode 100644 index 0000000000..084f024ee9 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/domain/model/TransactionStatus.class differ diff --git a/build/classes/java/main/com/yape/yape/domain/model/TransactionType.class b/build/classes/java/main/com/yape/yape/domain/model/TransactionType.class new file mode 100644 index 0000000000..11d3e2a5fc Binary files /dev/null and b/build/classes/java/main/com/yape/yape/domain/model/TransactionType.class differ diff --git a/build/classes/java/main/com/yape/yape/domain/port/EventPublisherPort.class b/build/classes/java/main/com/yape/yape/domain/port/EventPublisherPort.class new file mode 100644 index 0000000000..7933c0c39c Binary files /dev/null and b/build/classes/java/main/com/yape/yape/domain/port/EventPublisherPort.class differ diff --git a/build/classes/java/main/com/yape/yape/domain/port/TransactionRepositoryPort.class b/build/classes/java/main/com/yape/yape/domain/port/TransactionRepositoryPort.class new file mode 100644 index 0000000000..00ed723fa3 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/domain/port/TransactionRepositoryPort.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/in/kafka/AntiFraudConsumer.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/in/kafka/AntiFraudConsumer.class new file mode 100644 index 0000000000..ef039de16b Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/in/kafka/AntiFraudConsumer.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/in/kafka/TransactionStatusConsumer.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/in/kafka/TransactionStatusConsumer.class new file mode 100644 index 0000000000..54be247035 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/in/kafka/TransactionStatusConsumer.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/TransactionRepositoryAdapter.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/TransactionRepositoryAdapter.class new file mode 100644 index 0000000000..add4bfc0f4 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/TransactionRepositoryAdapter.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/entity/TransactionEntity$TransactionEntityBuilder.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/entity/TransactionEntity$TransactionEntityBuilder.class new file mode 100644 index 0000000000..bf40797604 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/entity/TransactionEntity$TransactionEntityBuilder.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/entity/TransactionEntity.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/entity/TransactionEntity.class new file mode 100644 index 0000000000..dacdee4456 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/entity/TransactionEntity.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/mapper/TransactionJpaMapper.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/mapper/TransactionJpaMapper.class new file mode 100644 index 0000000000..9e9b83e7b5 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/mapper/TransactionJpaMapper.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/repository/JpaTransactionRepository.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/repository/JpaTransactionRepository.class new file mode 100644 index 0000000000..cacae74586 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/jpa/repository/JpaTransactionRepository.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/kafka/KafkaEventPublisherAdapter.class b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/kafka/KafkaEventPublisherAdapter.class new file mode 100644 index 0000000000..3547164592 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/adapter/out/kafka/KafkaEventPublisherAdapter.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/config/DbIdentityLogger.class b/build/classes/java/main/com/yape/yape/infrastructure/config/DbIdentityLogger.class new file mode 100644 index 0000000000..acbb87d2b3 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/config/DbIdentityLogger.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/config/KafkaConsumerConfig.class b/build/classes/java/main/com/yape/yape/infrastructure/config/KafkaConsumerConfig.class new file mode 100644 index 0000000000..eb2dc1f0e2 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/config/KafkaConsumerConfig.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/controller/TransactionController.class b/build/classes/java/main/com/yape/yape/infrastructure/controller/TransactionController.class new file mode 100644 index 0000000000..694c3fd869 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/controller/TransactionController.class differ diff --git a/build/classes/java/main/com/yape/yape/infrastructure/handler/ApiExceptionHandler.class b/build/classes/java/main/com/yape/yape/infrastructure/handler/ApiExceptionHandler.class new file mode 100644 index 0000000000..f574ca05f4 Binary files /dev/null and b/build/classes/java/main/com/yape/yape/infrastructure/handler/ApiExceptionHandler.class differ diff --git a/build/reports/problems/problems-report.html b/build/reports/problems/problems-report.html new file mode 100644 index 0000000000..d33a9dadd1 --- /dev/null +++ b/build/reports/problems/problems-report.html @@ -0,0 +1,659 @@ + + + + + + + + + + + + + Gradle Configuration Cache + + + +
+ +
+ Loading... +
+ + + + + + diff --git a/build/resources/main/application.properties b/build/resources/main/application.properties new file mode 100644 index 0000000000..6a37bb2bfc --- /dev/null +++ b/build/resources/main/application.properties @@ -0,0 +1,25 @@ +spring.application.name=yape-service +server.port=8080 + +# PostgreSQL +spring.datasource.url=jdbc:postgresql://localhost:5432/yape +spring.datasource.username=postgres +spring.datasource.password=postgres +spring.datasource.driver-class-name=org.postgresql.Driver +spring.jpa.open-in-view=false + +# JPA +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=false +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.jdbc.time_zone=UTC + +# Kafka +spring.kafka.bootstrap-servers=localhost:9092 +spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer +spring.kafka.consumer.group-id=yape-service +spring.kafka.consumer.auto-offset-reset=earliest +app.kafka.topics.transaction-created=transaction-created +app.kafka.topics.transaction-approved=transaction-approved +app.kafka.topics.transaction-rejected=transaction-rejected diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/ApiExceptionHandler.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/ApiExceptionHandler.class.uniqueId1 new file mode 100644 index 0000000000..45acd91b2c Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/ApiExceptionHandler.class.uniqueId1 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeleteTransactionResponseDto$DeleteTransactionResponseDtoBuilder.class.uniqueId2 b/build/tmp/compileJava/compileTransaction/stash-dir/DeleteTransactionResponseDto$DeleteTransactionResponseDtoBuilder.class.uniqueId2 new file mode 100644 index 0000000000..c09381be3b Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeleteTransactionResponseDto$DeleteTransactionResponseDtoBuilder.class.uniqueId2 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/DeleteTransactionResponseDto.class.uniqueId3 b/build/tmp/compileJava/compileTransaction/stash-dir/DeleteTransactionResponseDto.class.uniqueId3 new file mode 100644 index 0000000000..c8211d8548 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/DeleteTransactionResponseDto.class.uniqueId3 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/TransactionController.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/TransactionController.class.uniqueId0 new file mode 100644 index 0000000000..327d071cb6 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/TransactionController.class.uniqueId0 differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 0000000000..02ad8644bb Binary files /dev/null and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..61285a659d Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..19a6bdeb84 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000000..adff685a03 --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..c4bdd3ab8e --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,93 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000000..94686ad2af --- /dev/null +++ b/schema.sql @@ -0,0 +1,35 @@ +-- Yape Challenge - PostgreSQL schema +-- Target DB: yape (schema: public) +-- Notes: +-- 1) This script is idempotent (safe to re-run). +-- 2) Uses UUID as primary key: transaction_external_id. +-- 3) Includes optimistic locking column: version (BIGINT). +-- 4) Includes basic constraints and helpful indexes. + +BEGIN; + +-- Optional: ensure uuid generation functions exist (not required if app generates UUIDs) +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +CREATE TABLE IF NOT EXISTS public.transactions ( + transaction_external_id UUID NOT NULL, + version BIGINT NOT NULL DEFAULT 0, + account_external_id_debit UUID NOT NULL, + account_external_id_credit UUID NOT NULL, + transfer_type_id INTEGER NOT NULL, + value NUMERIC(18,2) NOT NULL, + status VARCHAR(20) NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + CONSTRAINT transactions_pkey PRIMARY KEY (transaction_external_id), + CONSTRAINT transactions_value_positive CHECK (value >= 0), + CONSTRAINT transactions_accounts_distinct CHECK (account_external_id_debit <> account_external_id_credit), + CONSTRAINT transactions_status_valid CHECK (status IN ('PENDING','APPROVED','REJECTED')) +); + +-- Helpful indexes for common access patterns +CREATE INDEX IF NOT EXISTS idx_transactions_created_at ON public.transactions (created_at); +CREATE INDEX IF NOT EXISTS idx_transactions_status ON public.transactions (status); +CREATE INDEX IF NOT EXISTS idx_transactions_debit ON public.transactions (account_external_id_debit); +CREATE INDEX IF NOT EXISTS idx_transactions_credit ON public.transactions (account_external_id_credit); + +COMMIT; diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000000..b4fcdd6681 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'yape' diff --git a/src/main/java/com/yape/yape/YapeServiceApplication.java b/src/main/java/com/yape/yape/YapeServiceApplication.java new file mode 100644 index 0000000000..51592dbe42 --- /dev/null +++ b/src/main/java/com/yape/yape/YapeServiceApplication.java @@ -0,0 +1,13 @@ +package com.yape.yape; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class YapeServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(YapeServiceApplication.class, args); + } + +} diff --git a/src/main/java/com/yape/yape/application/dto/CreateTransactionRequestDto.java b/src/main/java/com/yape/yape/application/dto/CreateTransactionRequestDto.java new file mode 100644 index 0000000000..d8eef0d27f --- /dev/null +++ b/src/main/java/com/yape/yape/application/dto/CreateTransactionRequestDto.java @@ -0,0 +1,28 @@ +package com.yape.yape.application.dto; + +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.NotNull; +import lombok.*; + +import java.math.BigDecimal; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CreateTransactionRequestDto { + + @NotNull + private UUID accountExternalIdDebit; + + @NotNull + private UUID accountExternalIdCredit; + + @NotNull + private Integer tranferTypeId; + + @NotNull + @DecimalMin(value = "0.01") + private BigDecimal value; +} diff --git a/src/main/java/com/yape/yape/application/dto/DeleteTransactionResponseDto.java b/src/main/java/com/yape/yape/application/dto/DeleteTransactionResponseDto.java new file mode 100644 index 0000000000..063d2dce46 --- /dev/null +++ b/src/main/java/com/yape/yape/application/dto/DeleteTransactionResponseDto.java @@ -0,0 +1,6 @@ +package com.yape.yape.application.dto; + +public record DeleteTransactionResponseDto( + String message, + String transactionExternalId +) {} diff --git a/src/main/java/com/yape/yape/application/dto/TransactionCreatedEvent.java b/src/main/java/com/yape/yape/application/dto/TransactionCreatedEvent.java new file mode 100644 index 0000000000..204702ebd4 --- /dev/null +++ b/src/main/java/com/yape/yape/application/dto/TransactionCreatedEvent.java @@ -0,0 +1,21 @@ +package com.yape.yape.application.dto; + +import lombok.*; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TransactionCreatedEvent { + + private UUID transactionExternalId; + private UUID accountExternalIdDebit; + private UUID accountExternalIdCredit; + private Integer tranferTypeId; + private BigDecimal value; + private Instant createdAt; +} diff --git a/src/main/java/com/yape/yape/application/dto/TransactionResponseDto.java b/src/main/java/com/yape/yape/application/dto/TransactionResponseDto.java new file mode 100644 index 0000000000..9aa808298a --- /dev/null +++ b/src/main/java/com/yape/yape/application/dto/TransactionResponseDto.java @@ -0,0 +1,36 @@ +package com.yape.yape.application.dto; + +import lombok.*; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TransactionResponseDto { + + private UUID transactionExternalId; + private TransactionTypeDto transactionType; + private TransactionStatusDto transactionStatus; + private BigDecimal value; + private Instant createdAt; + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class TransactionTypeDto { + private String name; + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class TransactionStatusDto { + private String name; + } +} diff --git a/src/main/java/com/yape/yape/application/dto/TransactionStatusUpdatedEvent.java b/src/main/java/com/yape/yape/application/dto/TransactionStatusUpdatedEvent.java new file mode 100644 index 0000000000..9c47eaec27 --- /dev/null +++ b/src/main/java/com/yape/yape/application/dto/TransactionStatusUpdatedEvent.java @@ -0,0 +1,17 @@ +package com.yape.yape.application.dto; + +import com.yape.yape.domain.model.TransactionStatus; +import lombok.*; + +import java.time.Instant; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TransactionStatusUpdatedEvent { + private UUID transactionExternalId; + private TransactionStatus status; + private Instant updatedAt; +} diff --git a/src/main/java/com/yape/yape/application/dto/UpdateTransactionRequestDto.java b/src/main/java/com/yape/yape/application/dto/UpdateTransactionRequestDto.java new file mode 100644 index 0000000000..e62246def6 --- /dev/null +++ b/src/main/java/com/yape/yape/application/dto/UpdateTransactionRequestDto.java @@ -0,0 +1,25 @@ +package com.yape.yape.application.dto; + +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.NotNull; +import lombok.*; + +import java.math.BigDecimal; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UpdateTransactionRequestDto { + + @NotNull + private UUID accountExternalIdDebit; + + @NotNull + private UUID accountExternalIdCredit; + + @NotNull + @DecimalMin(value = "0.01") + private BigDecimal value; +} diff --git a/src/main/java/com/yape/yape/application/mapper/TransactionResponseMapper.java b/src/main/java/com/yape/yape/application/mapper/TransactionResponseMapper.java new file mode 100644 index 0000000000..be65940e91 --- /dev/null +++ b/src/main/java/com/yape/yape/application/mapper/TransactionResponseMapper.java @@ -0,0 +1,23 @@ +package com.yape.yape.application.mapper; + +import com.yape.yape.application.dto.TransactionResponseDto; +import com.yape.yape.domain.model.Transaction; + +public final class TransactionResponseMapper { + + private TransactionResponseMapper() {} + + public static TransactionResponseDto toDto(Transaction t) { + return TransactionResponseDto.builder() + .transactionExternalId(t.getTransactionExternalId()) + .transactionType(TransactionResponseDto.TransactionTypeDto.builder() + .name(t.getTransactionType().name()) + .build()) + .transactionStatus(TransactionResponseDto.TransactionStatusDto.builder() + .name(t.getStatus().name()) + .build()) + .value(t.getValue()) + .createdAt(t.getCreatedAt()) + .build(); + } +} diff --git a/src/main/java/com/yape/yape/application/usecase/CreateTransactionUseCase.java b/src/main/java/com/yape/yape/application/usecase/CreateTransactionUseCase.java new file mode 100644 index 0000000000..08c5beff6d --- /dev/null +++ b/src/main/java/com/yape/yape/application/usecase/CreateTransactionUseCase.java @@ -0,0 +1,61 @@ +package com.yape.yape.application.usecase; + +import com.yape.yape.application.dto.CreateTransactionRequestDto; +import com.yape.yape.application.dto.TransactionCreatedEvent; +import com.yape.yape.application.dto.TransactionResponseDto; +import com.yape.yape.application.mapper.TransactionResponseMapper; +import com.yape.yape.domain.model.Transaction; +import com.yape.yape.domain.model.TransactionStatus; +import com.yape.yape.domain.model.TransactionType; +import com.yape.yape.domain.port.EventPublisherPort; +import com.yape.yape.domain.port.TransactionRepositoryPort; +import org.springframework.stereotype.Service; + +import java.time.Instant; +import java.util.UUID; + +@Service +public class CreateTransactionUseCase { + + private final TransactionRepositoryPort repo; + private final EventPublisherPort publisher; + + public CreateTransactionUseCase(TransactionRepositoryPort repo, EventPublisherPort publisher) { + this.repo = repo; + this.publisher = publisher; + } + + public TransactionResponseDto execute(CreateTransactionRequestDto request) { + + UUID id = UUID.randomUUID(); + + TransactionType type = TransactionType.TRANSFER; + + Transaction tx = new Transaction( + id, + request.getAccountExternalIdDebit(), + request.getAccountExternalIdCredit(), + request.getTranferTypeId(), + type, + TransactionStatus.PENDING, // SIEMPRE PENDING al crear + request.getValue(), + Instant.now() + ); + + Transaction saved = repo.save(tx); + + // evento para antifraud + TransactionCreatedEvent event = TransactionCreatedEvent.builder() + .transactionExternalId(saved.getTransactionExternalId()) + .accountExternalIdDebit(saved.getAccountExternalIdDebit()) + .accountExternalIdCredit(saved.getAccountExternalIdCredit()) + .tranferTypeId(saved.getTransferTypeId()) + .value(saved.getValue()) + .createdAt(saved.getCreatedAt()) + .build(); + + publisher.publishTransactionCreated(event); + + return TransactionResponseMapper.toDto(saved); + } +} diff --git a/src/main/java/com/yape/yape/application/usecase/DeleteTransactionUseCase.java b/src/main/java/com/yape/yape/application/usecase/DeleteTransactionUseCase.java new file mode 100644 index 0000000000..e0a976cf06 --- /dev/null +++ b/src/main/java/com/yape/yape/application/usecase/DeleteTransactionUseCase.java @@ -0,0 +1,24 @@ +package com.yape.yape.application.usecase; + +import com.yape.yape.domain.exception.TransactionNotFoundException; +import com.yape.yape.domain.port.TransactionRepositoryPort; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class DeleteTransactionUseCase { + + private final TransactionRepositoryPort repo; + + public DeleteTransactionUseCase(TransactionRepositoryPort repo) { + this.repo = repo; + } + + public void execute(UUID externalId) { + if (!repo.existsByExternalId(externalId)) { + throw new TransactionNotFoundException("Transaction not found: " + externalId); + } + repo.deleteByExternalId(externalId); + } +} diff --git a/src/main/java/com/yape/yape/application/usecase/GetTransactionUseCase.java b/src/main/java/com/yape/yape/application/usecase/GetTransactionUseCase.java new file mode 100644 index 0000000000..9d12459c39 --- /dev/null +++ b/src/main/java/com/yape/yape/application/usecase/GetTransactionUseCase.java @@ -0,0 +1,27 @@ +package com.yape.yape.application.usecase; + +import com.yape.yape.application.dto.TransactionResponseDto; +import com.yape.yape.application.mapper.TransactionResponseMapper; +import com.yape.yape.domain.exception.TransactionNotFoundException; +import com.yape.yape.domain.model.Transaction; +import com.yape.yape.domain.port.TransactionRepositoryPort; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class GetTransactionUseCase { + + private final TransactionRepositoryPort repo; + + public GetTransactionUseCase(TransactionRepositoryPort repo) { + this.repo = repo; + } + + public TransactionResponseDto execute(UUID externalId) { + Transaction tx = repo.findByExternalId(externalId) + .orElseThrow(() -> new TransactionNotFoundException("Transaction not found: " + externalId)); + + return TransactionResponseMapper.toDto(tx); + } +} diff --git a/src/main/java/com/yape/yape/application/usecase/UpdateTransactionStatusUseCase.java b/src/main/java/com/yape/yape/application/usecase/UpdateTransactionStatusUseCase.java new file mode 100644 index 0000000000..bb07340fc9 --- /dev/null +++ b/src/main/java/com/yape/yape/application/usecase/UpdateTransactionStatusUseCase.java @@ -0,0 +1,42 @@ +package com.yape.yape.application.usecase; + +import com.yape.yape.domain.exception.TransactionNotFoundException; +import com.yape.yape.domain.model.Transaction; +import com.yape.yape.domain.model.TransactionStatus; +import com.yape.yape.domain.port.TransactionRepositoryPort; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class UpdateTransactionStatusUseCase { + + private final TransactionRepositoryPort repo; + + public UpdateTransactionStatusUseCase(TransactionRepositoryPort repo) { + this.repo = repo; + } + + public void execute(UUID externalId, TransactionStatus newStatus) { + + Transaction current = repo.findByExternalId(externalId) + .orElseThrow(() -> new TransactionNotFoundException("Transaction not found: " + externalId)); + + if (current.getStatus() == TransactionStatus.APPROVED || current.getStatus() == TransactionStatus.REJECTED) { + return; + } + + Transaction updated = new Transaction( + current.getTransactionExternalId(), + current.getAccountExternalIdDebit(), + current.getAccountExternalIdCredit(), + current.getTransferTypeId(), + current.getTransactionType(), + newStatus, + current.getValue(), + current.getCreatedAt() + ); + + repo.save(updated); + } +} diff --git a/src/main/java/com/yape/yape/application/usecase/UpdateTransactionUseCase.java b/src/main/java/com/yape/yape/application/usecase/UpdateTransactionUseCase.java new file mode 100644 index 0000000000..6994c5cd14 --- /dev/null +++ b/src/main/java/com/yape/yape/application/usecase/UpdateTransactionUseCase.java @@ -0,0 +1,50 @@ +package com.yape.yape.application.usecase; + +import com.yape.yape.application.dto.UpdateTransactionRequestDto; +import com.yape.yape.application.dto.TransactionResponseDto; +import com.yape.yape.application.mapper.TransactionResponseMapper; +import com.yape.yape.domain.exception.TransactionAlreadyFinalizedException; +import com.yape.yape.domain.exception.TransactionNotFoundException; +import com.yape.yape.domain.model.Transaction; +import com.yape.yape.domain.model.TransactionStatus; +import com.yape.yape.domain.port.TransactionRepositoryPort; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class UpdateTransactionUseCase { + + private final TransactionRepositoryPort repo; + + public UpdateTransactionUseCase(TransactionRepositoryPort repo) { + this.repo = repo; + } + + public TransactionResponseDto execute(UUID externalId, UpdateTransactionRequestDto request) { + + Transaction current = repo.findByExternalId(externalId) + .orElseThrow(() -> new TransactionNotFoundException("Transaction not found: " + externalId)); + + if (current.getStatus() != TransactionStatus.APPROVED) { + throw new TransactionAlreadyFinalizedException( + "Transaction cannot be updated once finalized. Current status: " + current.getStatus() + ); + } + + Transaction updated = new Transaction( + current.getTransactionExternalId(), + request.getAccountExternalIdDebit(), + request.getAccountExternalIdCredit(), + current.getTransferTypeId(), + current.getTransactionType(), + current.getStatus(), + request.getValue(), + current.getCreatedAt() + ); + + Transaction saved = repo.save(updated); + + return TransactionResponseMapper.toDto(saved); + } +} diff --git a/src/main/java/com/yape/yape/domain/exception/TransactionAlreadyFinalizedException.java b/src/main/java/com/yape/yape/domain/exception/TransactionAlreadyFinalizedException.java new file mode 100644 index 0000000000..8a59d51a3b --- /dev/null +++ b/src/main/java/com/yape/yape/domain/exception/TransactionAlreadyFinalizedException.java @@ -0,0 +1,7 @@ +package com.yape.yape.domain.exception; + +public class TransactionAlreadyFinalizedException extends RuntimeException { + public TransactionAlreadyFinalizedException(String message) { + super(message); + } +} diff --git a/src/main/java/com/yape/yape/domain/exception/TransactionNotFoundException.java b/src/main/java/com/yape/yape/domain/exception/TransactionNotFoundException.java new file mode 100644 index 0000000000..2a68538818 --- /dev/null +++ b/src/main/java/com/yape/yape/domain/exception/TransactionNotFoundException.java @@ -0,0 +1,7 @@ +package com.yape.yape.domain.exception; + +public class TransactionNotFoundException extends RuntimeException { + public TransactionNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/com/yape/yape/domain/model/Transaction.java b/src/main/java/com/yape/yape/domain/model/Transaction.java new file mode 100644 index 0000000000..c9f3cc67c6 --- /dev/null +++ b/src/main/java/com/yape/yape/domain/model/Transaction.java @@ -0,0 +1,20 @@ +package com.yape.yape.domain.model; + +import lombok.*; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.UUID; + +@Getter +@AllArgsConstructor +public class Transaction { + private final UUID transactionExternalId; + private final UUID accountExternalIdDebit; + private final UUID accountExternalIdCredit; + private final int transferTypeId; + private final TransactionType transactionType; + private final TransactionStatus status; + private final BigDecimal value; + private final Instant createdAt; +} diff --git a/src/main/java/com/yape/yape/domain/model/TransactionStatus.java b/src/main/java/com/yape/yape/domain/model/TransactionStatus.java new file mode 100644 index 0000000000..4396fab253 --- /dev/null +++ b/src/main/java/com/yape/yape/domain/model/TransactionStatus.java @@ -0,0 +1,7 @@ +package com.yape.yape.domain.model; + +public enum TransactionStatus { + PENDING, + APPROVED, + REJECTED +} diff --git a/src/main/java/com/yape/yape/domain/model/TransactionType.java b/src/main/java/com/yape/yape/domain/model/TransactionType.java new file mode 100644 index 0000000000..f51ab07329 --- /dev/null +++ b/src/main/java/com/yape/yape/domain/model/TransactionType.java @@ -0,0 +1,5 @@ +package com.yape.yape.domain.model; + +public enum TransactionType { + TRANSFER +} diff --git a/src/main/java/com/yape/yape/domain/port/EventPublisherPort.java b/src/main/java/com/yape/yape/domain/port/EventPublisherPort.java new file mode 100644 index 0000000000..55493e5aeb --- /dev/null +++ b/src/main/java/com/yape/yape/domain/port/EventPublisherPort.java @@ -0,0 +1,7 @@ +package com.yape.yape.domain.port; + +public interface EventPublisherPort { + void publishTransactionCreated(Object event); + void publishTransactionApproved(Object event); + void publishTransactionRejected(Object event); +} diff --git a/src/main/java/com/yape/yape/domain/port/TransactionRepositoryPort.java b/src/main/java/com/yape/yape/domain/port/TransactionRepositoryPort.java new file mode 100644 index 0000000000..f366fd6d12 --- /dev/null +++ b/src/main/java/com/yape/yape/domain/port/TransactionRepositoryPort.java @@ -0,0 +1,13 @@ +package com.yape.yape.domain.port; + +import com.yape.yape.domain.model.Transaction; + +import java.util.Optional; +import java.util.UUID; + +public interface TransactionRepositoryPort { + Transaction save(Transaction transaction); + Optional findByExternalId(UUID externalId); + void deleteByExternalId(UUID externalId); + boolean existsByExternalId(UUID externalId); +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/in/kafka/AntiFraudConsumer.java b/src/main/java/com/yape/yape/infrastructure/adapter/in/kafka/AntiFraudConsumer.java new file mode 100644 index 0000000000..ba8d603caf --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/in/kafka/AntiFraudConsumer.java @@ -0,0 +1,47 @@ +package com.yape.yape.infrastructure.adapter.in.kafka; + +import com.yape.yape.application.dto.TransactionCreatedEvent; +import com.yape.yape.application.dto.TransactionStatusUpdatedEvent; +import com.yape.yape.domain.model.TransactionStatus; +import com.yape.yape.domain.port.EventPublisherPort; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.time.Instant; + +@Component +public class AntiFraudConsumer { + + private static final BigDecimal LIMIT = BigDecimal.valueOf(1000); + + private final EventPublisherPort eventPublisherPort; + + public AntiFraudConsumer(EventPublisherPort eventPublisherPort) { + this.eventPublisherPort = eventPublisherPort; + } + + @KafkaListener( + topics = "${app.kafka.topics.transaction-created}", + groupId = "antifraud-group-v2", + containerFactory = "transactionCreatedKafkaListenerContainerFactory" + ) + public void onTransactionCreated(TransactionCreatedEvent event) { + + TransactionStatus status = event.getValue().compareTo(LIMIT) > 0 + ? TransactionStatus.REJECTED + : TransactionStatus.APPROVED; + + TransactionStatusUpdatedEvent resultEvent = TransactionStatusUpdatedEvent.builder() + .transactionExternalId(event.getTransactionExternalId()) + .status(status) + .updatedAt(Instant.now()) + .build(); + + if (status == TransactionStatus.APPROVED) { + eventPublisherPort.publishTransactionApproved(resultEvent); + } else { + eventPublisherPort.publishTransactionRejected(resultEvent); + } + } +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/in/kafka/TransactionStatusConsumer.java b/src/main/java/com/yape/yape/infrastructure/adapter/in/kafka/TransactionStatusConsumer.java new file mode 100644 index 0000000000..4415003afa --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/in/kafka/TransactionStatusConsumer.java @@ -0,0 +1,34 @@ +package com.yape.yape.infrastructure.adapter.in.kafka; + +import com.yape.yape.application.dto.TransactionStatusUpdatedEvent; +import com.yape.yape.application.usecase.UpdateTransactionStatusUseCase; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +@Component +public class TransactionStatusConsumer { + + private final UpdateTransactionStatusUseCase updateTransactionStatusUseCase; + + public TransactionStatusConsumer(UpdateTransactionStatusUseCase updateTransactionStatusUseCase) { + this.updateTransactionStatusUseCase = updateTransactionStatusUseCase; + } + + @KafkaListener( + topics = "${app.kafka.topics.transaction-approved}", + groupId = "transaction-status-group", + containerFactory = "transactionStatusKafkaListenerContainerFactory" + ) + public void onApproved(TransactionStatusUpdatedEvent event) { + updateTransactionStatusUseCase.execute(event.getTransactionExternalId(), event.getStatus()); + } + + @KafkaListener( + topics = "${app.kafka.topics.transaction-rejected}", + groupId = "transaction-status-group", + containerFactory = "transactionStatusKafkaListenerContainerFactory" + ) + public void onRejected(TransactionStatusUpdatedEvent event) { + updateTransactionStatusUseCase.execute(event.getTransactionExternalId(), event.getStatus()); + } +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/out/entity/TransactionEntity.java b/src/main/java/com/yape/yape/infrastructure/adapter/out/entity/TransactionEntity.java new file mode 100644 index 0000000000..a7cb0eab7d --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/out/entity/TransactionEntity.java @@ -0,0 +1,45 @@ +package com.yape.yape.infrastructure.adapter.out.jpa.entity; + +import jakarta.persistence.*; +import lombok.*; + +import java.math.BigDecimal; +import java.time.Instant; +import java.util.UUID; + +@Entity +@Table(name = "transactions") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TransactionEntity { + + @Id + @Column(name = "transaction_external_id", nullable = false) + private UUID transactionExternalId; + + @Version + @Column(name = "version", nullable = false) + private Long version; + + @Column(name = "account_external_id_debit", nullable = false) + private UUID accountExternalIdDebit; + + @Column(name = "account_external_id_credit", nullable = false) + private UUID accountExternalIdCredit; + + @Column(name = "transfer_type_id", nullable = false) + private Integer transferTypeId; + + @Column(name = "value", nullable = false, precision = 18, scale = 2) + private BigDecimal value; + + @Column(name = "status", nullable = false, length = 20) + private String status; + + @Column(name = "created_at", nullable = false) + private Instant createdAt; + +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/TransactionRepositoryAdapter.java b/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/TransactionRepositoryAdapter.java new file mode 100644 index 0000000000..0c997544b1 --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/TransactionRepositoryAdapter.java @@ -0,0 +1,64 @@ +package com.yape.yape.infrastructure.adapter.out.jpa; + +import com.yape.yape.domain.model.Transaction; +import com.yape.yape.domain.port.TransactionRepositoryPort; +import com.yape.yape.infrastructure.adapter.out.jpa.entity.TransactionEntity; +import com.yape.yape.infrastructure.adapter.out.jpa.mapper.TransactionJpaMapper; +import com.yape.yape.infrastructure.adapter.out.jpa.repository.JpaTransactionRepository; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; +import java.util.UUID; + +@Repository +public class TransactionRepositoryAdapter implements TransactionRepositoryPort { + + private final JpaTransactionRepository jpa; + + public TransactionRepositoryAdapter(JpaTransactionRepository jpa) { + this.jpa = jpa; + } + + @Override + @Transactional + public Transaction save(Transaction transaction) { + + UUID id = transaction.getTransactionExternalId(); + + Optional existingOpt = jpa.findById(id); + + TransactionEntity entityToSave; + if (existingOpt.isPresent()) { + TransactionEntity existing = existingOpt.get(); + + existing.setAccountExternalIdDebit(transaction.getAccountExternalIdDebit()); + existing.setAccountExternalIdCredit(transaction.getAccountExternalIdCredit()); + existing.setTransferTypeId(transaction.getTransferTypeId()); + existing.setValue(transaction.getValue()); + existing.setStatus(transaction.getStatus().name()); // si tu entity guarda String + + entityToSave = existing; + } else { + entityToSave = TransactionJpaMapper.toEntity(transaction); + } + + TransactionEntity saved = jpa.save(entityToSave); + return TransactionJpaMapper.toDomain(saved); + } + + @Override + public Optional findByExternalId(UUID externalId) { + return jpa.findById(externalId).map(TransactionJpaMapper::toDomain); + } + + @Override + public void deleteByExternalId(UUID externalId) { + jpa.deleteById(externalId); + } + + @Override + public boolean existsByExternalId(UUID externalId) { + return jpa.existsById(externalId); + } +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/mapper/TransactionJpaMapper.java b/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/mapper/TransactionJpaMapper.java new file mode 100644 index 0000000000..b27f562ec2 --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/mapper/TransactionJpaMapper.java @@ -0,0 +1,40 @@ +package com.yape.yape.infrastructure.adapter.out.jpa.mapper; + +import com.yape.yape.domain.model.Transaction; +import com.yape.yape.domain.model.TransactionStatus; +import com.yape.yape.domain.model.TransactionType; +import com.yape.yape.infrastructure.adapter.out.jpa.entity.TransactionEntity; + +public final class TransactionJpaMapper { + + private TransactionJpaMapper() {} + + public static Transaction toDomain(TransactionEntity e) { + return new Transaction( + e.getTransactionExternalId(), + e.getAccountExternalIdDebit(), + e.getAccountExternalIdCredit(), + e.getTransferTypeId(), + resolveType(e.getTransferTypeId()), + TransactionStatus.valueOf(e.getStatus()), + e.getValue(), + e.getCreatedAt() + ); + } + + public static TransactionEntity toEntity(Transaction t) { + return TransactionEntity.builder() + .transactionExternalId(t.getTransactionExternalId()) + .accountExternalIdDebit(t.getAccountExternalIdDebit()) + .accountExternalIdCredit(t.getAccountExternalIdCredit()) + .transferTypeId(t.getTransferTypeId()) + .value(t.getValue()) + .status(t.getStatus().name()) + .createdAt(t.getCreatedAt()) + .build(); + } + + private static TransactionType resolveType(Integer transferTypeId) { + return TransactionType.TRANSFER; + } +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/repository/JpaTransactionRepository.java b/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/repository/JpaTransactionRepository.java new file mode 100644 index 0000000000..08da5ee2dc --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/out/jpa/repository/JpaTransactionRepository.java @@ -0,0 +1,9 @@ +package com.yape.yape.infrastructure.adapter.out.jpa.repository; + +import com.yape.yape.infrastructure.adapter.out.jpa.entity.TransactionEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface JpaTransactionRepository extends JpaRepository { +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/out/kafka/KafkaEventPublisherAdapter.java b/src/main/java/com/yape/yape/infrastructure/adapter/out/kafka/KafkaEventPublisherAdapter.java new file mode 100644 index 0000000000..69a57d8bc2 --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/out/kafka/KafkaEventPublisherAdapter.java @@ -0,0 +1,40 @@ +package com.yape.yape.infrastructure.adapter.out.kafka; + +import com.yape.yape.domain.port.EventPublisherPort; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +@Component +public class KafkaEventPublisherAdapter implements EventPublisherPort { + + private final KafkaTemplate kafkaTemplate; + + @Value("${app.kafka.topics.transaction-created}") + private String transactionCreatedTopic; + + @Value("${app.kafka.topics.transaction-approved}") + private String transactionApprovedTopic; + + @Value("${app.kafka.topics.transaction-rejected}") + private String transactionRejectedTopic; + + public KafkaEventPublisherAdapter(KafkaTemplate kafkaTemplate) { + this.kafkaTemplate = kafkaTemplate; + } + + @Override + public void publishTransactionCreated(Object event) { + kafkaTemplate.send(transactionCreatedTopic, event); + } + + @Override + public void publishTransactionApproved(Object event) { + kafkaTemplate.send(transactionApprovedTopic, event); + } + + @Override + public void publishTransactionRejected(Object event) { + kafkaTemplate.send(transactionRejectedTopic, event); + } +} diff --git a/src/main/java/com/yape/yape/infrastructure/adapter/out/memory/InMemoryTransactionRepository.java b/src/main/java/com/yape/yape/infrastructure/adapter/out/memory/InMemoryTransactionRepository.java new file mode 100644 index 0000000000..22e42a3d3c --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/adapter/out/memory/InMemoryTransactionRepository.java @@ -0,0 +1,38 @@ +//package com.yape.yape.infrastructure.adapter.out.memory; +// +//import com.yape.yape.domain.model.Transaction; +//import com.yape.yape.domain.port.TransactionRepositoryPort; +//import org.springframework.stereotype.Repository; +// +//import java.util.Optional; +//import java.util.UUID; +//import java.util.concurrent.ConcurrentHashMap; +// +//@Repository +//public class InMemoryTransactionRepository implements TransactionRepositoryPort { +// +// private final ConcurrentHashMap store = new ConcurrentHashMap<>(); +// +// @Override +// public Transaction save(Transaction transaction) { +// store.put(transaction.getTransactionExternalId(), transaction); +// System.out.println("SAVED: " + transaction.getTransactionExternalId()); +// return transaction; +// } +// +// @Override +// public Optional findByExternalId(UUID externalId) { +// System.out.println("FIND: " + externalId + " exists=" + store.containsKey(externalId)); +// return Optional.ofNullable(store.get(externalId)); +// } +// +// @Override +// public void deleteByExternalId(UUID externalId) { +// store.remove(externalId); +// } +// +// @Override +// public boolean existsByExternalId(UUID externalId) { +// return store.containsKey(externalId); +// } +//} diff --git a/src/main/java/com/yape/yape/infrastructure/config/DbIdentityLogger.java b/src/main/java/com/yape/yape/infrastructure/config/DbIdentityLogger.java new file mode 100644 index 0000000000..fcffe67f9d --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/config/DbIdentityLogger.java @@ -0,0 +1,28 @@ +package com.yape.yape.infrastructure.config; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +public class DbIdentityLogger implements ApplicationRunner { + + private final JdbcTemplate jdbcTemplate; + + @Override + public void run(ApplicationArguments args) { + var row = jdbcTemplate.queryForMap(""" + select inet_server_addr() as host, + inet_server_port() as port, + current_database() as db, + current_schema() as schema, + current_user as usr + """); + log.info("[DB_IDENTITY] {}", row); + } +} diff --git a/src/main/java/com/yape/yape/infrastructure/config/KafkaConsumerConfig.java b/src/main/java/com/yape/yape/infrastructure/config/KafkaConsumerConfig.java new file mode 100644 index 0000000000..48806a571d --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/config/KafkaConsumerConfig.java @@ -0,0 +1,68 @@ +package com.yape.yape.infrastructure.config; + +import com.yape.yape.application.dto.TransactionCreatedEvent; +import com.yape.yape.application.dto.TransactionStatusUpdatedEvent; +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.springframework.boot.autoconfigure.kafka.KafkaProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; +import org.springframework.kafka.core.DefaultKafkaConsumerFactory; +import org.springframework.kafka.support.serializer.ErrorHandlingDeserializer; +import org.springframework.kafka.support.serializer.JsonDeserializer; + +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class KafkaConsumerConfig { + + private Map baseConsumerProps(KafkaProperties kafkaProperties) { + Map props = new HashMap<>(kafkaProperties.buildConsumerProperties()); + + props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ErrorHandlingDeserializer.class); + props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ErrorHandlingDeserializer.class); + + props.put(ErrorHandlingDeserializer.KEY_DESERIALIZER_CLASS, StringDeserializer.class); + props.put(ErrorHandlingDeserializer.VALUE_DESERIALIZER_CLASS, JsonDeserializer.class); + + props.put(JsonDeserializer.TRUSTED_PACKAGES, "*"); + props.put(JsonDeserializer.USE_TYPE_INFO_HEADERS, false); + + return props; + } + + @Bean(name = "transactionCreatedKafkaListenerContainerFactory") + public ConcurrentKafkaListenerContainerFactory transactionCreatedFactory( + KafkaProperties kafkaProperties + ) { + Map props = baseConsumerProps(kafkaProperties); + props.put(JsonDeserializer.VALUE_DEFAULT_TYPE, TransactionCreatedEvent.class.getName()); + + // OJO: no pasar deserializer custom (para que no aplique configure + setters) + DefaultKafkaConsumerFactory consumerFactory = + new DefaultKafkaConsumerFactory<>(props); + + ConcurrentKafkaListenerContainerFactory factory = + new ConcurrentKafkaListenerContainerFactory<>(); + factory.setConsumerFactory(consumerFactory); + return factory; + } + + @Bean(name = "transactionStatusKafkaListenerContainerFactory") + public ConcurrentKafkaListenerContainerFactory transactionStatusFactory( + KafkaProperties kafkaProperties + ) { + Map props = baseConsumerProps(kafkaProperties); + props.put(JsonDeserializer.VALUE_DEFAULT_TYPE, TransactionStatusUpdatedEvent.class.getName()); + + DefaultKafkaConsumerFactory consumerFactory = + new DefaultKafkaConsumerFactory<>(props); + + ConcurrentKafkaListenerContainerFactory factory = + new ConcurrentKafkaListenerContainerFactory<>(); + factory.setConsumerFactory(consumerFactory); + return factory; + } +} diff --git a/src/main/java/com/yape/yape/infrastructure/controller/TransactionController.java b/src/main/java/com/yape/yape/infrastructure/controller/TransactionController.java new file mode 100644 index 0000000000..1e32d97798 --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/controller/TransactionController.java @@ -0,0 +1,63 @@ +package com.yape.yape.infrastructure.controller; + +import com.yape.yape.application.dto.CreateTransactionRequestDto; +import com.yape.yape.application.dto.DeleteTransactionResponseDto; +import com.yape.yape.application.dto.TransactionResponseDto; +import com.yape.yape.application.dto.UpdateTransactionRequestDto; +import com.yape.yape.application.usecase.*; +import jakarta.validation.Valid; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; +import java.util.UUID; + +@RestController +@RequestMapping("/transactions") +public class TransactionController { + + private final CreateTransactionUseCase createUseCase; + private final GetTransactionUseCase getUseCase; + private final DeleteTransactionUseCase deleteUseCase; + private final UpdateTransactionUseCase updateUseCase; + + public TransactionController( + CreateTransactionUseCase createUseCase, + GetTransactionUseCase getUseCase, + DeleteTransactionUseCase deleteUseCase, + UpdateTransactionUseCase updateUseCase + ) { + this.createUseCase = createUseCase; + this.getUseCase = getUseCase; + this.deleteUseCase = deleteUseCase; + this.updateUseCase = updateUseCase; + } + + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + public TransactionResponseDto create(@Valid @RequestBody CreateTransactionRequestDto request) { + return createUseCase.execute(request); + } + + @GetMapping("/{externalId}") + public TransactionResponseDto get(@PathVariable UUID externalId) { + return getUseCase.execute(externalId); + } + + @PutMapping("/{externalId}") + public TransactionResponseDto update(@PathVariable UUID externalId, + @Valid @RequestBody UpdateTransactionRequestDto request) { + return updateUseCase.execute(externalId, request); + } + + @DeleteMapping("/{externalId}") + public DeleteTransactionResponseDto delete(@PathVariable UUID externalId) { + deleteUseCase.execute(externalId); + + return new DeleteTransactionResponseDto( + "Transaction deleted successfully", + externalId.toString() + ); + } + +} diff --git a/src/main/java/com/yape/yape/infrastructure/handler/ApiExceptionHandler.java b/src/main/java/com/yape/yape/infrastructure/handler/ApiExceptionHandler.java new file mode 100644 index 0000000000..235ec613de --- /dev/null +++ b/src/main/java/com/yape/yape/infrastructure/handler/ApiExceptionHandler.java @@ -0,0 +1,32 @@ +package com.yape.yape.infrastructure.handler; + +import com.yape.yape.domain.exception.TransactionAlreadyFinalizedException; +import com.yape.yape.domain.exception.TransactionNotFoundException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ProblemDetail; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.Map; + +@RestControllerAdvice +public class ApiExceptionHandler { + + @ExceptionHandler(TransactionNotFoundException.class) + public ProblemDetail handleNotFound(TransactionNotFoundException ex) { + ProblemDetail problem = ProblemDetail.forStatus(HttpStatus.NOT_FOUND); + problem.setTitle("Transaction not found"); + problem.setDetail(ex.getMessage()); + return problem; + } + + @ExceptionHandler(TransactionAlreadyFinalizedException.class) + public ProblemDetail handleFinalized(TransactionAlreadyFinalizedException ex) { + ProblemDetail problem = ProblemDetail.forStatus(HttpStatus.CONFLICT); + problem.setTitle("Transaction already finalized"); + problem.setDetail(ex.getMessage()); + return problem; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000000..6a37bb2bfc --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,25 @@ +spring.application.name=yape-service +server.port=8080 + +# PostgreSQL +spring.datasource.url=jdbc:postgresql://localhost:5432/yape +spring.datasource.username=postgres +spring.datasource.password=postgres +spring.datasource.driver-class-name=org.postgresql.Driver +spring.jpa.open-in-view=false + +# JPA +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=false +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.jdbc.time_zone=UTC + +# Kafka +spring.kafka.bootstrap-servers=localhost:9092 +spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer +spring.kafka.consumer.group-id=yape-service +spring.kafka.consumer.auto-offset-reset=earliest +app.kafka.topics.transaction-created=transaction-created +app.kafka.topics.transaction-approved=transaction-approved +app.kafka.topics.transaction-rejected=transaction-rejected diff --git a/src/test/java/com/yape/yape/YapeServiceApplicationTests.java b/src/test/java/com/yape/yape/YapeServiceApplicationTests.java new file mode 100644 index 0000000000..22c2a805f6 --- /dev/null +++ b/src/test/java/com/yape/yape/YapeServiceApplicationTests.java @@ -0,0 +1,13 @@ +package com.yape.yape; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class YapeServiceApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/yape-service.postman_collection.json b/yape-service.postman_collection.json new file mode 100644 index 0000000000..b7c86dc140 --- /dev/null +++ b/yape-service.postman_collection.json @@ -0,0 +1,134 @@ +{ + "info": { + "_postman_id": "1af0e93f-c796-4557-a9a6-6e887c0bd227", + "name": "yape-service", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "36481549" + }, + "item": [ + { + "name": "transactions", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"accountExternalIdDebit\": \"11111111-1111-1111-1111-111111111111\",\r\n \"accountExternalIdCredit\": \"22222222-2222-2222-2222-222222222222\",\r\n \"tranferTypeId\": 1,\r\n \"value\": 120\r\n}\r\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/transactions", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "transactions" + ] + } + }, + "response": [] + }, + { + "name": "SearchTransaction", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8080/transactions/4d89a448-6c35-47eb-928a-e956a441df96", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "transactions", + "4d89a448-6c35-47eb-928a-e956a441df96" + ] + } + }, + "response": [] + }, + { + "name": "health", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8080/actuator/health", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "actuator", + "health" + ] + } + }, + "response": [] + }, + { + "name": "Delete Transaction", + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "http://localhost:8080/transactions/4d89a448-6c35-47eb-928a-e956a441df96", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "transactions", + "4d89a448-6c35-47eb-928a-e956a441df96" + ] + }, + "description": "Generated from cURL: curl -X DELETE http://localhost:8080/transactions/bf1e870a-b34f-47e4-a596-75009a46b356 -i\r\n" + }, + "response": [] + }, + { + "name": "update yape service", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\r\n \"accountExternalIdDebit\": \"11111111-1111-1111-1111-111111111111\",\r\n \"accountExternalIdCredit\": \"22222222-2222-2222-2222-222222222223\",\r\n \"tranferTypeId\": 1,\r\n \"value\": 999\r\n }", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/transactions/4d89a448-6c35-47eb-928a-e956a441df96", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "transactions", + "4d89a448-6c35-47eb-928a-e956a441df96" + ] + }, + "description": "Generated from cURL: curl -X PUT \"http://localhost:8080/transactions/2a94a12f-8f93-4c96-9055-acb09ad6c26d\" \\\r\n -H \"Content-Type: application/json\" \\\r\n -d '{\r\n \"accountExternalIdDebit\": \"11111111-1111-1111-1111-111111111111\",\r\n \"accountExternalIdCredit\": \"33333333-3333-3333-3333-333333333333\",\r\n \"value\": 500\r\n }'\r\n" + }, + "response": [] + } + ] +} \ No newline at end of file