Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,15 @@ dist

# TernJS port file
.tern-port


*.class
*.jar

#Maven
target/
dist/

# JetBrains IDE
.idea/
.iml/
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip
8 changes: 8 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
</component>
</module>
67 changes: 67 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.yape.challenge</groupId>
<artifactId>transaction-system</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>app</artifactId>

<dependencies>
<dependency>
<groupId>com.yape.challenge</groupId>
<artifactId>core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.challenge.transaction.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TransactionApplication {

public static void main(String[] args) {
SpringApplication.run(TransactionApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.challenge.transaction.app.config;

import com.challenge.transaction.core.ports.input.CreateTransactionUseCase;
import com.challenge.transaction.core.ports.input.GetTransactionUseCase;
import com.challenge.transaction.core.ports.output.TransactionEventPublisher;
import com.challenge.transaction.core.ports.output.TransactionRepository;
import com.challenge.transaction.core.usecase.CreateTransactionService;
import com.challenge.transaction.core.usecase.GetTransactionService;
import com.challenge.transaction.core.usecase.UpdateTransactionStatusService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfiguration {

@Bean
public CreateTransactionUseCase createTransactionUseCase(
TransactionRepository repository,
TransactionEventPublisher publisher) {
return new CreateTransactionService(repository, publisher);
}

@Bean
public GetTransactionUseCase getTransactionUseCase(
TransactionRepository repository) {
return new GetTransactionService(repository);
}

@Bean
public UpdateTransactionStatusService updateTransactionStatusService(
TransactionRepository repository) {
return new UpdateTransactionStatusService(repository);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.challenge.transaction.app.config;

import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class KafkaConfig {

@Bean
public NewTopic transactionCreatedTopic() {
return new NewTopic("transaction-created", 3, (short) 1);
}

@Bean
public NewTopic transactionValidatedTopic() {
return new NewTopic("transaction-validated", 3, (short) 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.challenge.transaction.app.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI transactionApi() {

return new OpenAPI()
.info(new Info()
.title("Transaction API")
.description("Reto de Yape")
.version("1.0"));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.challenge.transaction.app.controller;

import com.challenge.transaction.app.dto.CreateTransactionRequest;
import com.challenge.transaction.app.dto.TransactionResponse;
import com.challenge.transaction.app.mapper.TransactionMapper;
import com.challenge.transaction.core.domain.model.Transaction;
import com.challenge.transaction.core.ports.input.CreateTransactionUseCase;
import com.challenge.transaction.core.ports.input.GetTransactionUseCase;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/transactions")
@AllArgsConstructor
public class TransactionController {

private final CreateTransactionUseCase createUseCase;
private final GetTransactionUseCase getUseCase;

@PostMapping
public ResponseEntity<TransactionResponse> create(
@RequestBody CreateTransactionRequest request) {
Transaction transaction = TransactionMapper.MAPPER.toDomain(request);
Transaction saved = createUseCase.create(transaction);

return ResponseEntity.ok(TransactionMapper.MAPPER.toResponse(saved));
}

@GetMapping("/{id}")
public ResponseEntity<TransactionResponse> get(@PathVariable UUID id) {
Transaction transaction = getUseCase.get(id);

return ResponseEntity.ok(TransactionMapper.MAPPER.toResponse(transaction));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.challenge.transaction.app.dto;

import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.io.Serializable;
import java.util.UUID;

@Getter
@Setter
public class CreateTransactionRequest implements Serializable {

@Serial
private static final long serialVersionUID = 3741074636662158145L;

private UUID accountExternalIdDebit;
private UUID accountExternalIdCredit;
private Integer transferTypeId;
private Double value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.challenge.transaction.app.dto;

import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.UUID;

@Getter
@Setter
public class TransactionResponse implements Serializable {

@Serial
private static final long serialVersionUID = -5230394309771679808L;

private UUID transactionExternalId;
private TypeDto transactionType;
private StatusDto transactionStatus;
private Double value;
private LocalDateTime createdAt;

@Getter
@Setter
public static class StatusDto implements Serializable {
@Serial
private static final long serialVersionUID = 3144852181997944515L;

private String name;
}

@Getter
@Setter
public static class TypeDto implements Serializable {
@Serial
private static final long serialVersionUID = -5686189229013063853L;

private String name;
}
}
Loading