feature: add bank account request dto validation
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@@ -32,7 +33,7 @@ public class BankAccountController {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<String> createBankAccount(@RequestBody CreateBankAccountRequestDTO dto) {
|
||||
public ResponseEntity<String> createBankAccount(@Valid @RequestBody CreateBankAccountRequestDTO dto) {
|
||||
final var aggregateID = UUID.randomUUID().toString();
|
||||
final var command = new CreateBankAccountCommand(aggregateID, dto.email(), dto.userName(), dto.address());
|
||||
final var id = commandService.handle(command);
|
||||
@@ -41,7 +42,7 @@ public class BankAccountController {
|
||||
}
|
||||
|
||||
@PostMapping(path = "/deposit/{aggregateId}")
|
||||
public ResponseEntity<Void> depositAmount(@RequestBody DepositAmountRequestDTO dto, @PathVariable String aggregateId) {
|
||||
public ResponseEntity<Void> depositAmount(@Valid @RequestBody DepositAmountRequestDTO dto, @PathVariable String aggregateId) {
|
||||
final var command = new DepositAmountCommand(aggregateId, dto.amount());
|
||||
commandService.handle(command);
|
||||
log.info("DepositAmountCommand command: {}", command);
|
||||
@@ -49,7 +50,7 @@ public class BankAccountController {
|
||||
}
|
||||
|
||||
@PostMapping(path = "/email/{aggregateId}")
|
||||
public ResponseEntity<Void> changeEmail(@RequestBody ChangeEmailRequestDTO dto, @PathVariable String aggregateId) {
|
||||
public ResponseEntity<Void> changeEmail(@Valid @RequestBody ChangeEmailRequestDTO dto, @PathVariable String aggregateId) {
|
||||
final var command = new ChangeEmailCommand(aggregateId, dto.newEmail());
|
||||
commandService.handle(command);
|
||||
log.info("ChangeEmailCommand command: {}", command);
|
||||
@@ -57,7 +58,7 @@ public class BankAccountController {
|
||||
}
|
||||
|
||||
@PostMapping(path = "/address/{aggregateId}")
|
||||
public ResponseEntity<Void> changeAddress(@RequestBody ChangeAddressRequestDTO dto, @PathVariable String aggregateId) {
|
||||
public ResponseEntity<Void> changeAddress(@Valid @RequestBody ChangeAddressRequestDTO dto, @PathVariable String aggregateId) {
|
||||
final var command = new ChangeAddressCommand(aggregateId, dto.newAddress());
|
||||
commandService.handle(command);
|
||||
log.info("changeAddress command: {}", command);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package com.eventsourcing.bankAccount.dto;
|
||||
|
||||
public record ChangeAddressRequestDTO(String newAddress) {
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
public record ChangeAddressRequestDTO(@NotBlank @Size(min = 10, max = 250) String newAddress) {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
package com.eventsourcing.bankAccount.dto;
|
||||
|
||||
public record ChangeEmailRequestDTO(String newEmail) {
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
public record ChangeEmailRequestDTO(@Email @NotBlank @Size(min = 10, max = 250) String newEmail) {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.eventsourcing.bankAccount.dto;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
public record CreateBankAccountRequestDTO(
|
||||
String email,
|
||||
String address,
|
||||
String userName) {
|
||||
@Email @NotBlank @Size(min = 10, max = 250) String email,
|
||||
@NotBlank @Size(min = 10, max = 250) String address,
|
||||
@NotBlank @Size(min = 10, max = 250) String userName) {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.eventsourcing.bankAccount.dto;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public record DepositAmountRequestDTO(BigDecimal amount) {
|
||||
public record DepositAmountRequestDTO(@Min(value = 300, message = "minimal amount is 300") @NotNull BigDecimal amount) {
|
||||
}
|
||||
Reference in New Issue
Block a user