Skip to content

Commit 53720ac

Browse files
committed
refactor: change implementation
1 parent 9407c36 commit 53720ac

19 files changed

+198
-217
lines changed

docker/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ services:
88
environment:
99
- MYSQL_USER=admin
1010
- MYSQL_PASSWORD=123
11-
- MYSQL_DATABASE=mydb
11+
- MYSQL_DATABASE=cryptodb
1212
- MYSQL_ROOT_PASSWORD=123

pom.xml

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,24 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.2.4</version>
8+
<version>3.2.5</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>tech.buildrun</groupId>
12-
<artifactId>crypto</artifactId>
12+
<artifactId>cryptography</artifactId>
1313
<version>0.0.1-SNAPSHOT</version>
14-
<name>crypto</name>
14+
<name>cryptography</name>
1515
<description>Demo project for Spring Boot</description>
1616
<properties>
1717
<java.version>21</java.version>
1818
</properties>
1919
<dependencies>
20-
<dependency>
21-
<groupId>com.mysql</groupId>
22-
<artifactId>mysql-connector-j</artifactId>
23-
<scope>runtime</scope>
24-
</dependency>
2520
<dependency>
2621
<groupId>org.jasypt</groupId>
2722
<artifactId>jasypt</artifactId>
2823
<version>1.9.3</version>
2924
</dependency>
25+
3026
<dependency>
3127
<groupId>org.springframework.boot</groupId>
3228
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -36,6 +32,11 @@
3632
<artifactId>spring-boot-starter-web</artifactId>
3733
</dependency>
3834

35+
<dependency>
36+
<groupId>com.mysql</groupId>
37+
<artifactId>mysql-connector-j</artifactId>
38+
<scope>runtime</scope>
39+
</dependency>
3940
<dependency>
4041
<groupId>org.springframework.boot</groupId>
4142
<artifactId>spring-boot-starter-test</artifactId>

src/main/java/tech/buildrun/crypto/controller/TransactionController.java

-53
This file was deleted.

src/main/java/tech/buildrun/crypto/controller/dto/CreateTransactionRequest.java

-4
This file was deleted.

src/main/java/tech/buildrun/crypto/controller/dto/TransactionResponse.java

-15
This file was deleted.

src/main/java/tech/buildrun/crypto/service/CryptoService.java

-35
This file was deleted.

src/main/java/tech/buildrun/crypto/service/TransactionService.java

-65
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
package tech.buildrun.crypto;
1+
package tech.buildrun.cryptography;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

66
@SpringBootApplication
7-
public class CryptoApplication {
7+
public class CryptographyApplication {
88

99
public static void main(String[] args) {
10-
SpringApplication.run(CryptoApplication.class, args);
10+
SpringApplication.run(CryptographyApplication.class, args);
1111
}
12+
1213
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package tech.buildrun.cryptography.controller;
2+
3+
import org.springframework.data.domain.Page;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.*;
6+
import tech.buildrun.cryptography.controller.dto.CreateTransactionRequest;
7+
import tech.buildrun.cryptography.controller.dto.TransactionResponse;
8+
import tech.buildrun.cryptography.controller.dto.UpdateTransactionRequest;
9+
import tech.buildrun.cryptography.service.TransactionService;
10+
11+
@RestController
12+
@RequestMapping(value = "/transactions")
13+
public class TransactionController {
14+
15+
private final TransactionService service;
16+
17+
public TransactionController(TransactionService service) {
18+
this.service = service;
19+
}
20+
21+
@PostMapping
22+
public ResponseEntity<Void> create(@RequestBody CreateTransactionRequest request) {
23+
service.create(request);
24+
return ResponseEntity.ok().build();
25+
}
26+
27+
@PutMapping("/{id}")
28+
public ResponseEntity<Void> update(@PathVariable(value = "id") Long id,
29+
@RequestBody UpdateTransactionRequest request) {
30+
service.update(id, request);
31+
return ResponseEntity.noContent().build();
32+
}
33+
34+
@GetMapping
35+
public ResponseEntity<Page<TransactionResponse>> listAll(@RequestParam(name = "page", defaultValue = "0") Integer page,
36+
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
37+
var body = service.listAll(page, pageSize);
38+
return ResponseEntity.ok(body);
39+
}
40+
41+
@GetMapping("/{id}")
42+
public ResponseEntity<TransactionResponse> findById(@PathVariable(value = "id") Long id) {
43+
var body = service.findById(id);
44+
return ResponseEntity.ok(body);
45+
}
46+
47+
@DeleteMapping("/{id}")
48+
public ResponseEntity<Void> deleteById(@PathVariable(value = "id") Long id) {
49+
service.deleteById(id);
50+
return ResponseEntity.noContent().build();
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package tech.buildrun.cryptography.controller.dto;
2+
3+
public record CreateTransactionRequest(String userDocument,
4+
String creditCardToken,
5+
Long value) {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package tech.buildrun.cryptography.controller.dto;
2+
3+
import tech.buildrun.cryptography.entity.TransactionEntity;
4+
5+
public record TransactionResponse(Long id,
6+
String userDocument,
7+
String creditCardToken,
8+
Long value) {
9+
10+
public static TransactionResponse fromEntity(TransactionEntity entity) {
11+
return new TransactionResponse(
12+
entity.getTransactionId(),
13+
entity.getRawUserDocument(),
14+
entity.getRawCreditCardToken(),
15+
entity.getTransactionValue()
16+
);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tech.buildrun.crypto.controller.dto;
1+
package tech.buildrun.cryptography.controller.dto;
22

33
public record UpdateTransactionRequest(Long value) {
44
}

0 commit comments

Comments
 (0)