I started a basic Spring Boot banking application. Basically, POST
need mandatory fields for amount and user. I have added @Valid
and @NotEmpty
, but using these, empty POST
goes through as well.
clientController.java
@RestController
public class clientController {
@Autowired
private clientRepo repo;
@PostMapping("/saveClient")
ResponseEntity<String> saveClient(@Valid @RequestBody Client client){
repo.save(client);
return ResponseEntity.ok("Client saved.");
}
@GetMapping("/payments")
List<Client> getAll(){
return repo.findAll();
}
}
Client.java
@Entity
@Data
public class Client {
@Id
@GeneratedValue
private UUID id = UUID.randomUUID() ;
@DecimalMin("1.0")
private double amount;
@NotNull
private String debtorIban;
private LocalDateTime createdAt = LocalDateTime.now(ZoneOffset.UTC).withNano(0);
}