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/app-nodejs-codechallenge.iml b/.idea/app-nodejs-codechallenge.iml
new file mode 100644
index 0000000000..d6ebd48059
--- /dev/null
+++ b/.idea/app-nodejs-codechallenge.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000000..9d5f3a8f2e
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000000..53e8190f2a
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000000..712ab9d985
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000000..40a3abc8f4
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000000..aedd251311
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ 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/README.md b/README.md
index b067a71026..aeb5571bc6 100644
--- a/README.md
+++ b/README.md
@@ -1,82 +1,221 @@
-# Yape Code Challenge :rocket:
+# Transaction Service
-Our code challenge will let you marvel us with your Jedi coding skills :smile:.
+Microservicio desarrollado con Spring Boot para la gestión de transacciones financieras y validación antifraude.
-Don't forget that the proper way to submit your work is to fork the repo and create a PR :wink: ... have fun !!
+---
-- [Problem](#problem)
-- [Tech Stack](#tech_stack)
-- [Send us your challenge](#send_us_your_challenge)
+## 🚀 Tecnologías Utilizadas
-# Problem
+- Java 21
+- Spring Boot 3.2.5
+- Spring Data JPA
+- H2 Database (Base de datos en memoria)
+- Maven
+- Lombok
+- OpenAPI / Swagger
-Every time a financial transaction is created it must be validated by our anti-fraud microservice and then the same service sends a message back to update the transaction status.
-For now, we have only three transaction statuses:
+---
-
-
pending
-
approved
-
rejected
-
+## 🏗 Arquitectura
-Every transaction with a value greater than 1000 should be rejected.
+El proyecto sigue una arquitectura en capas:
-```mermaid
- flowchart LR
- Transaction -- Save Transaction with pending Status --> transactionDatabase[(Database)]
- Transaction --Send transaction Created event--> Anti-Fraud
- Anti-Fraud -- Send transaction Status Approved event--> Transaction
- Anti-Fraud -- Send transaction Status Rejected event--> Transaction
- Transaction -- Update transaction Status event--> transactionDatabase[(Database)]
```
+controller → service → repository → entity → dto
+```
+
+Estructura principal:
+
+```
+src
+ └─ main
+ ├─ java
+ │ └─ com.yape.transactionservice
+ │ ├─ controller
+ │ ├─ service
+ │ ├─ repository
+ │ ├─ entity
+ │ └─ dto
+ └─ resources
+```
+
+---
+
+## ▶️ Cómo Ejecutar el Proyecto
+
+### 1️⃣ Compilar el proyecto
+
+```bash
+mvn clean install
+```
+
+### 2️⃣ Ejecutar la aplicación
+
+```bash
+mvn spring-boot:run
+```
+
+La aplicación se ejecutará en:
+
+```
+http://localhost:8081/api
+```
+
+---
+
+## 🗄 Base de Datos
-# Tech Stack
+Se utiliza H2 en memoria.
-
-
Node. You can use any framework you want (i.e. Nestjs with an ORM like TypeOrm or Prisma)
-
Any database
-
Kafka
-
+### Consola H2
-We do provide a `Dockerfile` to help you get started with a dev environment.
+```
+http://localhost:8081/api/h2-console
+```
+
+Credenciales:
+
+```
+JDBC URL: jdbc:h2:mem:transactiondb
+User: sa
+Password: (vacío)
+```
+
+La base de datos se reinicia cada vez que la aplicación se detiene.
+
+---
-You must have two resources:
+## 📚 Documentación Swagger
-1. Resource to create a transaction that must containt:
+Una vez levantada la aplicación:
+
+```
+http://localhost:8081/api/swagger-ui/index.html
+```
+
+Swagger permite:
+- Visualizar endpoints
+- Probar requests
+- Ver modelos de request y response
+
+---
+
+# 📌 Endpoints
+
+## 🔹 1. Crear Transacción
+
+**POST** `/api/transactions`
+
+### Request
```json
{
- "accountExternalIdDebit": "Guid",
- "accountExternalIdCredit": "Guid",
+ "accountExternalIdDebit": 1001,
+ "accountExternalIdCredit": 2001,
"tranferTypeId": 1,
- "value": 120
+ "amount": 120.50
}
```
-2. Resource to retrieve a transaction
+### Response
```json
{
- "transactionExternalId": "Guid",
+ "transactionExternalId": 1,
"transactionType": {
- "name": ""
+ "id": 1,
+ "name": "TRANSFER"
},
"transactionStatus": {
- "name": ""
+ "id": 1,
+ "name": "PENDING"
},
- "value": 120,
- "createdAt": "Date"
+ "amount": 120.50,
+ "createdAt": "2026-03-02T17:00:00"
}
```
-## Optional
+---
+
+## 🔹 2. Obtener Transacción
+
+**GET** `/api/transactions/{id}`
+
+### Ejemplo
+
+```
+GET /api/transactions/1
+```
+
+### Response
+
+```json
+{
+ "transactionExternalId": 1,
+ "transactionType": {
+ "id": 1,
+ "name": "TRANSFER"
+ },
+ "transactionStatus": {
+ "id": 2,
+ "name": "APPROVED"
+ },
+ "amount": 120.50,
+ "createdAt": "2026-03-02T17:00:00"
+}
+```
+
+---
+
+## 🔹 3. Validar Transacción (AntiFraud)
+
+**POST** `/api/transactions/validate/{id}`
+
+### Ejemplo
+
+```
+POST /api/transactions/validate/1
+```
+
+### Response
+
+```json
+{
+ "transactionId": 1,
+ "status": "APPROVED"
+}
+```
+
+---
+
+# 🛡 Reglas de Negocio (Ejemplo AntiFraude)
+
+- La aprobación o rechazo producto de la validación es aleatoria para efectos de éste reto técnico
+- El estado inicial de una transacción es PENDING
+
+---
+
+# 🧪 Testing
+
+Para ejecutar pruebas (si existen):
+
+```bash
+mvn test
+```
+
+---
+
+# 📈 Mejoras Futuras
-You can use any approach to store transaction data but you should consider that we may deal with high volume scenarios where we have a huge amount of writes and reads for the same data at the same time. How would you tackle this requirement?
+- Migración a PostgreSQL
+- Implementación de Docker
+- Manejo global de excepciones (@ControllerAdvice)
+- Logs estructurados
+- Pruebas unitarias y de integración
-You can use Graphql;
+---
-# Send us your challenge
+# 👨💻 Autor
-When you finish your challenge, after forking a repository, you **must** open a pull request to our repository. There are no limitations to the implementation, you can follow the programming paradigm, modularization, and style that you feel is the most appropriate solution.
+Proyecto desarrollado como parte de un reto técnico backend.
-If you have any questions, please let us know.
diff --git a/transaction-service.iml b/transaction-service.iml
new file mode 100644
index 0000000000..ce57a28691
--- /dev/null
+++ b/transaction-service.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/transaction-service/pom.xml b/transaction-service/pom.xml
new file mode 100644
index 0000000000..efe54e8b0b
--- /dev/null
+++ b/transaction-service/pom.xml
@@ -0,0 +1,88 @@
+
+
+ 4.0.0
+
+ com.yape.ms
+ transaction-service
+ 1.0-SNAPSHOT
+
+
+ 21
+ 21
+ UTF-8
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.2.5
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+
+ com.h2database
+ h2
+ runtime
+
+
+
+ org.springdoc
+ springdoc-openapi-starter-webmvc-ui
+ 2.5.0
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.11.0
+
+ 21
+ 21
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.34
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/TransactionServiceApplication.java b/transaction-service/src/main/java/com/yape/transactionservice/TransactionServiceApplication.java
new file mode 100644
index 0000000000..cf2aa202b5
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/TransactionServiceApplication.java
@@ -0,0 +1,11 @@
+package com.yape.transactionservice;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class TransactionServiceApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(TransactionServiceApplication.class, args);
+ }
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/controller/TransactionController.java b/transaction-service/src/main/java/com/yape/transactionservice/controller/TransactionController.java
new file mode 100644
index 0000000000..71981fab70
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/controller/TransactionController.java
@@ -0,0 +1,44 @@
+package com.yape.transactionservice.controller;
+
+import com.yape.transactionservice.dto.request.CreateTransactionRequest;
+import com.yape.transactionservice.dto.response.TransactionResponse;
+import com.yape.transactionservice.dto.response.ValidateAntiFraudTransactionResponse;
+import com.yape.transactionservice.service.TransactionService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.math.BigInteger;
+
+@RestController
+@RequestMapping("/transactions")
+@RequiredArgsConstructor
+@Tag(name = "Transactions", description = "Operaciones realizadas en la tabla Transacciones")
+public class TransactionController {
+
+ private final TransactionService transactionService;
+
+ @GetMapping("/{id}")
+ @Operation(summary = "Obtener una transacción por ID")
+ public ResponseEntity getTransaction(@PathVariable BigInteger id){
+ TransactionResponse response = transactionService.getTransaction(id);
+ return ResponseEntity.ok(response);
+ }
+
+ @PostMapping
+ @Operation(summary = "Crear una transacción")
+ public ResponseEntity saveTransaction(@RequestBody CreateTransactionRequest request){
+ TransactionResponse response = transactionService.saveTransaction(request);
+ return ResponseEntity.ok(response);
+ }
+
+ @PostMapping("/validate/{id}")
+ @Operation(summary = "Validate si una transacción es Fraudulenta")
+ public ResponseEntity validateAntiFraudTransaction(@PathVariable BigInteger id){
+ ValidateAntiFraudTransactionResponse response = transactionService.validateTransaction(id);
+ return ResponseEntity.ok(response);
+ }
+
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/dto/request/CreateTransactionRequest.java b/transaction-service/src/main/java/com/yape/transactionservice/dto/request/CreateTransactionRequest.java
new file mode 100644
index 0000000000..33347fd212
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/dto/request/CreateTransactionRequest.java
@@ -0,0 +1,15 @@
+package com.yape.transactionservice.dto.request;
+
+import lombok.Data;
+
+import java.math.BigInteger;
+
+@Data
+public class CreateTransactionRequest {
+
+ private BigInteger accountExternalIdDebit;
+ private BigInteger accountExternalIdCredit;
+ private Long tranferTypeId;
+ private Double amount;
+
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/dto/response/TransactionResponse.java b/transaction-service/src/main/java/com/yape/transactionservice/dto/response/TransactionResponse.java
new file mode 100644
index 0000000000..ce582881c3
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/dto/response/TransactionResponse.java
@@ -0,0 +1,19 @@
+package com.yape.transactionservice.dto.response;
+
+import com.yape.transactionservice.entity.TransactionStatus;
+import com.yape.transactionservice.entity.TransactionType;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+@Data
+public class TransactionResponse {
+
+ private Long transactionExternalId;
+ private TransactionType transactionType;
+ private TransactionStatus transactionStatus;
+ private Double amount;
+ private LocalDateTime createdAt;
+
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/dto/response/ValidateAntiFraudTransactionResponse.java b/transaction-service/src/main/java/com/yape/transactionservice/dto/response/ValidateAntiFraudTransactionResponse.java
new file mode 100644
index 0000000000..6f6ede5d71
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/dto/response/ValidateAntiFraudTransactionResponse.java
@@ -0,0 +1,12 @@
+package com.yape.transactionservice.dto.response;
+
+import com.yape.transactionservice.entity.Transaction;
+import lombok.Data;
+
+@Data
+public class ValidateAntiFraudTransactionResponse {
+
+ private boolean success;
+ private Transaction transaction;
+
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/entity/Transaction.java b/transaction-service/src/main/java/com/yape/transactionservice/entity/Transaction.java
new file mode 100644
index 0000000000..e160596f07
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/entity/Transaction.java
@@ -0,0 +1,33 @@
+package com.yape.transactionservice.entity;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+import java.util.UUID;
+
+@Entity
+@Data
+public class Transaction {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long transactionExternalId;
+
+ private BigInteger accountExternalIdDebit;
+
+ private BigInteger accountExternalIdCredit;
+
+ @ManyToOne
+ @JoinColumn(name = "transfer_type_id")
+ private TransactionType transactionType;
+
+ @ManyToOne
+ @JoinColumn(name = "status_id")
+ private TransactionStatus transactionStatus;
+
+
+ private Double amount;
+
+ private LocalDateTime createdAt;
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/entity/TransactionStatus.java b/transaction-service/src/main/java/com/yape/transactionservice/entity/TransactionStatus.java
new file mode 100644
index 0000000000..b7810f6f10
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/entity/TransactionStatus.java
@@ -0,0 +1,13 @@
+package com.yape.transactionservice.entity;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import lombok.Data;
+
+@Entity
+@Data
+public class TransactionStatus {
+ @Id
+ private Long id;
+ private String name;
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/entity/TransactionType.java b/transaction-service/src/main/java/com/yape/transactionservice/entity/TransactionType.java
new file mode 100644
index 0000000000..f2438e5298
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/entity/TransactionType.java
@@ -0,0 +1,13 @@
+package com.yape.transactionservice.entity;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import lombok.Data;
+
+@Entity
+@Data
+public class TransactionType {
+ @Id
+ private Long id;
+ private String name;
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionRepository.java b/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionRepository.java
new file mode 100644
index 0000000000..3704294929
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionRepository.java
@@ -0,0 +1,10 @@
+package com.yape.transactionservice.repository;
+
+import com.yape.transactionservice.entity.Transaction;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface TransactionRepository extends JpaRepository {
+
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionStatusRepository.java b/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionStatusRepository.java
new file mode 100644
index 0000000000..2e1bf8d2cd
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionStatusRepository.java
@@ -0,0 +1,8 @@
+package com.yape.transactionservice.repository;
+
+import com.yape.transactionservice.entity.Transaction;
+import com.yape.transactionservice.entity.TransactionStatus;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface TransactionStatusRepository extends JpaRepository {
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionTypeRepository.java b/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionTypeRepository.java
new file mode 100644
index 0000000000..d354248680
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/repository/TransactionTypeRepository.java
@@ -0,0 +1,8 @@
+package com.yape.transactionservice.repository;
+
+import com.yape.transactionservice.entity.Transaction;
+import com.yape.transactionservice.entity.TransactionType;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface TransactionTypeRepository extends JpaRepository {
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/service/TransactionService.java b/transaction-service/src/main/java/com/yape/transactionservice/service/TransactionService.java
new file mode 100644
index 0000000000..21b6627c2e
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/service/TransactionService.java
@@ -0,0 +1,15 @@
+package com.yape.transactionservice.service;
+
+import com.yape.transactionservice.dto.request.CreateTransactionRequest;
+import com.yape.transactionservice.dto.response.TransactionResponse;
+import com.yape.transactionservice.dto.response.ValidateAntiFraudTransactionResponse;
+
+import java.math.BigInteger;
+
+public interface TransactionService {
+
+ public TransactionResponse getTransaction(BigInteger id);
+ public TransactionResponse saveTransaction(CreateTransactionRequest request);
+ public ValidateAntiFraudTransactionResponse validateTransaction(BigInteger id);
+
+}
diff --git a/transaction-service/src/main/java/com/yape/transactionservice/service/impl/TransactionServiceImpl.java b/transaction-service/src/main/java/com/yape/transactionservice/service/impl/TransactionServiceImpl.java
new file mode 100644
index 0000000000..f8c8ee7fa2
--- /dev/null
+++ b/transaction-service/src/main/java/com/yape/transactionservice/service/impl/TransactionServiceImpl.java
@@ -0,0 +1,112 @@
+package com.yape.transactionservice.service.impl;
+
+import com.yape.transactionservice.dto.request.CreateTransactionRequest;
+import com.yape.transactionservice.dto.response.TransactionResponse;
+import com.yape.transactionservice.dto.response.ValidateAntiFraudTransactionResponse;
+import com.yape.transactionservice.entity.Transaction;
+import com.yape.transactionservice.entity.TransactionStatus;
+import com.yape.transactionservice.entity.TransactionType;
+import com.yape.transactionservice.repository.TransactionRepository;
+import com.yape.transactionservice.repository.TransactionStatusRepository;
+import com.yape.transactionservice.repository.TransactionTypeRepository;
+import com.yape.transactionservice.service.TransactionService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+import java.util.concurrent.ThreadLocalRandom;
+
+@Service
+@RequiredArgsConstructor
+public class TransactionServiceImpl implements TransactionService {
+
+ private final TransactionRepository transactionRepository;
+ private final TransactionTypeRepository transactionTypeRepository;
+ private final TransactionStatusRepository transactionStatusRepository;
+
+ TransactionType transactionType;
+ TransactionStatus transactionStatus;
+
+
+ @Override
+ public TransactionResponse getTransaction(BigInteger id) {
+ Transaction transaction = new Transaction();
+ transaction = transactionRepository
+ .findById(id.longValue())
+ .orElseThrow(() -> new RuntimeException("Transaction not found"));
+ transactionType = transactionTypeRepository
+ .findById(transaction.getTransactionType().getId())
+ .orElseThrow(() -> new RuntimeException("TransactionType not found"));
+ transactionStatus = transactionStatusRepository
+ .findById(transaction.getTransactionStatus().getId())
+ .orElseThrow(() -> new RuntimeException("TransactionType not found"));
+
+ TransactionResponse response = new TransactionResponse();
+ response.setTransactionExternalId(transaction.getTransactionExternalId());
+ response.setTransactionType(transactionType);
+ response.setTransactionStatus(transactionStatus);
+ response.setAmount(transaction.getAmount());
+ response.setCreatedAt(transaction.getCreatedAt());
+
+ return response;
+ }
+
+ @Override
+ public TransactionResponse saveTransaction(CreateTransactionRequest request) {
+
+ Transaction transaction = new Transaction();
+ transaction.setAccountExternalIdDebit(request.getAccountExternalIdDebit());
+ transaction.setAccountExternalIdCredit(request.getAccountExternalIdCredit());
+
+ transactionType = transactionTypeRepository
+ .findById(request.getTranferTypeId())
+ .orElseThrow(() -> new RuntimeException("TransactionType not found"));
+ transaction.setTransactionType(transactionType);
+
+ transactionStatus = transactionStatusRepository
+ .findById(1L)
+ .orElseThrow(() -> new RuntimeException("TransactionStatus not found"));
+ transaction.setTransactionStatus(transactionStatus);
+
+ transaction.setAmount(request.getAmount());
+ transaction.setCreatedAt(LocalDateTime.now());
+
+ transactionRepository.save(transaction);
+
+
+ TransactionResponse response = new TransactionResponse();
+ response.setTransactionExternalId(transaction.getTransactionExternalId());
+ response.setTransactionType(transactionType);
+ response.setTransactionStatus(transactionStatus);
+ response.setAmount(transaction.getAmount());
+ response.setCreatedAt(transaction.getCreatedAt());
+
+ return response;
+ }
+
+ @Override
+ public ValidateAntiFraudTransactionResponse validateTransaction(BigInteger id) {
+
+ Transaction transaction = transactionRepository
+ .findById(id.longValue())
+ .orElseThrow(() -> new RuntimeException("Transaction not found"));
+
+ // Permutación de estados (Aprobado o Rechazado)
+ Long statusId = (long) ThreadLocalRandom.current().nextInt(2, 4);
+
+ TransactionStatus status = transactionStatusRepository
+ .findById(statusId)
+ .orElseThrow();
+
+ transaction.setTransactionStatus(status);
+
+ transactionRepository.save(transaction);
+
+ ValidateAntiFraudTransactionResponse response = new ValidateAntiFraudTransactionResponse();
+ response.setSuccess(statusId == 2);
+ response.setTransaction(transaction);
+
+ return response;
+ }
+}
diff --git a/transaction-service/src/main/resources/application.yaml b/transaction-service/src/main/resources/application.yaml
new file mode 100644
index 0000000000..37fcc05747
--- /dev/null
+++ b/transaction-service/src/main/resources/application.yaml
@@ -0,0 +1,25 @@
+server:
+ port: 8081
+ servlet:
+ context-path: /api
+
+spring:
+ application:
+ name: transaction-service
+
+ datasource:
+ url: jdbc:h2:mem:transactiondb
+ driverClassName: org.h2.Driver
+ username: sa
+ password:
+
+ jpa:
+ database-platform: org.hibernate.dialect.H2Dialect
+ hibernate:
+ ddl-auto: update
+ show-sql: true
+
+ h2:
+ console:
+ enabled: true
+ path: /h2-console
\ No newline at end of file
diff --git a/transaction-service/src/main/resources/data.sql b/transaction-service/src/main/resources/data.sql
new file mode 100644
index 0000000000..24bf3d7cf4
--- /dev/null
+++ b/transaction-service/src/main/resources/data.sql
@@ -0,0 +1,6 @@
+INSERT INTO TRANSACTION_TYPE (id, name) VALUES (1, 'PAGOS');
+INSERT INTO TRANSACTION_TYPE (id, name) VALUES (2, 'EXTORNOS');
+
+INSERT INTO TRANSACTION_STATUS (id, name) VALUES (1, 'PENDIENTE');
+INSERT INTO TRANSACTION_STATUS (id, name) VALUES (2, 'APROBADO');
+INSERT INTO TRANSACTION_STATUS (id, name) VALUES (3, 'RECHAZADO');
\ No newline at end of file
diff --git a/transaction-service/src/main/resources/schema.sql b/transaction-service/src/main/resources/schema.sql
new file mode 100644
index 0000000000..bad5f6d0ef
--- /dev/null
+++ b/transaction-service/src/main/resources/schema.sql
@@ -0,0 +1,18 @@
+CREATE TABLE transaction (
+ transaction_external_id BIGINT AUTO_INCREMENT PRIMARY KEY,
+ account_external_id_debit BIGINT,
+ account_external_id_credit BIGINT,
+ transfer_type_id INT,
+ amount DOUBLE,
+ created_at TIMESTAMP
+);
+
+CREATE TABLE transaction_type (
+ id INT PRIMARY KEY,
+ name VARCHAR(50)
+);
+
+CREATE TABLE transaction_status (
+ id INT PRIMARY KEY,
+ name VARCHAR(50)
+);
\ No newline at end of file
diff --git a/transaction-service/target/classes/application.yaml b/transaction-service/target/classes/application.yaml
new file mode 100644
index 0000000000..37fcc05747
--- /dev/null
+++ b/transaction-service/target/classes/application.yaml
@@ -0,0 +1,25 @@
+server:
+ port: 8081
+ servlet:
+ context-path: /api
+
+spring:
+ application:
+ name: transaction-service
+
+ datasource:
+ url: jdbc:h2:mem:transactiondb
+ driverClassName: org.h2.Driver
+ username: sa
+ password:
+
+ jpa:
+ database-platform: org.hibernate.dialect.H2Dialect
+ hibernate:
+ ddl-auto: update
+ show-sql: true
+
+ h2:
+ console:
+ enabled: true
+ path: /h2-console
\ No newline at end of file
diff --git a/transaction-service/target/classes/com/yape/transactionservice/TransactionServiceApplication.class b/transaction-service/target/classes/com/yape/transactionservice/TransactionServiceApplication.class
new file mode 100644
index 0000000000..0d5cbdb906
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/TransactionServiceApplication.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/controller/TransactionController.class b/transaction-service/target/classes/com/yape/transactionservice/controller/TransactionController.class
new file mode 100644
index 0000000000..7195b6860c
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/controller/TransactionController.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/dto/request/CreateTransactionRequest.class b/transaction-service/target/classes/com/yape/transactionservice/dto/request/CreateTransactionRequest.class
new file mode 100644
index 0000000000..d8d0d7a623
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/dto/request/CreateTransactionRequest.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/dto/response/TransactionResponse.class b/transaction-service/target/classes/com/yape/transactionservice/dto/response/TransactionResponse.class
new file mode 100644
index 0000000000..59d70c10c8
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/dto/response/TransactionResponse.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/dto/response/ValidateAntiFraudTransactionResponse.class b/transaction-service/target/classes/com/yape/transactionservice/dto/response/ValidateAntiFraudTransactionResponse.class
new file mode 100644
index 0000000000..e6bf9ff9e6
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/dto/response/ValidateAntiFraudTransactionResponse.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/entity/Transaction.class b/transaction-service/target/classes/com/yape/transactionservice/entity/Transaction.class
new file mode 100644
index 0000000000..acc9b80019
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/entity/Transaction.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/entity/TransactionStatus.class b/transaction-service/target/classes/com/yape/transactionservice/entity/TransactionStatus.class
new file mode 100644
index 0000000000..b6c10a00bc
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/entity/TransactionStatus.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/entity/TransactionType.class b/transaction-service/target/classes/com/yape/transactionservice/entity/TransactionType.class
new file mode 100644
index 0000000000..bb299c2cd3
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/entity/TransactionType.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionRepository.class b/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionRepository.class
new file mode 100644
index 0000000000..992e170587
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionRepository.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionStatusRepository.class b/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionStatusRepository.class
new file mode 100644
index 0000000000..9d00077308
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionStatusRepository.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionTypeRepository.class b/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionTypeRepository.class
new file mode 100644
index 0000000000..3184a37ef4
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/repository/TransactionTypeRepository.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/service/TransactionService.class b/transaction-service/target/classes/com/yape/transactionservice/service/TransactionService.class
new file mode 100644
index 0000000000..8ef5ff9aa3
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/service/TransactionService.class differ
diff --git a/transaction-service/target/classes/com/yape/transactionservice/service/impl/TransactionServiceImpl.class b/transaction-service/target/classes/com/yape/transactionservice/service/impl/TransactionServiceImpl.class
new file mode 100644
index 0000000000..336bed3b8e
Binary files /dev/null and b/transaction-service/target/classes/com/yape/transactionservice/service/impl/TransactionServiceImpl.class differ
diff --git a/transaction-service/target/classes/data.sql b/transaction-service/target/classes/data.sql
new file mode 100644
index 0000000000..24bf3d7cf4
--- /dev/null
+++ b/transaction-service/target/classes/data.sql
@@ -0,0 +1,6 @@
+INSERT INTO TRANSACTION_TYPE (id, name) VALUES (1, 'PAGOS');
+INSERT INTO TRANSACTION_TYPE (id, name) VALUES (2, 'EXTORNOS');
+
+INSERT INTO TRANSACTION_STATUS (id, name) VALUES (1, 'PENDIENTE');
+INSERT INTO TRANSACTION_STATUS (id, name) VALUES (2, 'APROBADO');
+INSERT INTO TRANSACTION_STATUS (id, name) VALUES (3, 'RECHAZADO');
\ No newline at end of file
diff --git a/transaction-service/target/classes/schema.sql b/transaction-service/target/classes/schema.sql
new file mode 100644
index 0000000000..bad5f6d0ef
--- /dev/null
+++ b/transaction-service/target/classes/schema.sql
@@ -0,0 +1,18 @@
+CREATE TABLE transaction (
+ transaction_external_id BIGINT AUTO_INCREMENT PRIMARY KEY,
+ account_external_id_debit BIGINT,
+ account_external_id_credit BIGINT,
+ transfer_type_id INT,
+ amount DOUBLE,
+ created_at TIMESTAMP
+);
+
+CREATE TABLE transaction_type (
+ id INT PRIMARY KEY,
+ name VARCHAR(50)
+);
+
+CREATE TABLE transaction_status (
+ id INT PRIMARY KEY,
+ name VARCHAR(50)
+);
\ No newline at end of file
diff --git a/transaction-service/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/transaction-service/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000000..473b3adb07
--- /dev/null
+++ b/transaction-service/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -0,0 +1,13 @@
+com\yape\transactionservice\repository\TransactionTypeRepository.class
+com\yape\transactionservice\entity\TransactionType.class
+com\yape\transactionservice\dto\response\ValidateAntiFraudTransactionResponse.class
+com\yape\transactionservice\controller\TransactionController.class
+com\yape\transactionservice\entity\Transaction.class
+com\yape\transactionservice\TransactionServiceApplication.class
+com\yape\transactionservice\dto\request\CreateTransactionRequest.class
+com\yape\transactionservice\service\impl\TransactionServiceImpl.class
+com\yape\transactionservice\service\TransactionService.class
+com\yape\transactionservice\dto\response\TransactionResponse.class
+com\yape\transactionservice\repository\TransactionStatusRepository.class
+com\yape\transactionservice\entity\TransactionStatus.class
+com\yape\transactionservice\repository\TransactionRepository.class
diff --git a/transaction-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/transaction-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000000..7dceee15e0
--- /dev/null
+++ b/transaction-service/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1,13 @@
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\entity\TransactionStatus.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\entity\Transaction.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\entity\TransactionType.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\service\impl\TransactionServiceImpl.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\repository\TransactionRepository.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\repository\TransactionTypeRepository.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\dto\response\ValidateAntiFraudTransactionResponse.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\TransactionServiceApplication.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\service\TransactionService.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\dto\request\CreateTransactionRequest.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\repository\TransactionStatusRepository.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\controller\TransactionController.java
+C:\Users\gilmar.gutierrez\Documents\BEN\Proyectos\app-nodejs-codechallenge\transaction-service\src\main\java\com\yape\transactionservice\dto\response\TransactionResponse.java
diff --git a/transaction-service/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/transaction-service/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/transaction-service/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/transaction-service/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
new file mode 100644
index 0000000000..e69de29bb2