Bael 4781: Introduction to ZeroCode (#10482)
* small example of hexagonal architecture in java * Bael-4781: Introduction to ZeroCode * add readme * Revert "small example of hexagonal architecture in java" This reverts commit c0f96441 * refactoring * refactoring
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.zerocode;
|
||||
|
||||
public class User {
|
||||
private String id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.zerocode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
@RequestMapping("/api/users")
|
||||
public class ZerocodeApplication {
|
||||
private List<User> users = new ArrayList<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ZerocodeApplication.class, args);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity create(@RequestBody User user) {
|
||||
if (!StringUtils.hasText(user.getFirstName())) {
|
||||
return new ResponseEntity("firstName can't be empty!", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!StringUtils.hasText(user.getLastName())) {
|
||||
return new ResponseEntity("lastName can't be empty!", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
user.setId(UUID.randomUUID()
|
||||
.toString());
|
||||
users.add(user);
|
||||
return new ResponseEntity(user, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user