Spring Cloud - 10. Users Microservice 사용자 추가
목차 Spring Cloud - 20. Users Microservice AuthorizationHeaderFilter 추가 Spring Cloud - 19. Users Microservice JWT 생성 Spring Cloud - 18. Users Microservice 로그인 성공 처리 Spring Cloud - 17. Users Microservice Routes 정보 변경 Spring Cloud - 16. Users Microservice loadUserByUsername() 구현 Spring Cloud - 15. Users Microservice AuthenticationFilter Spring Cloud - 14. Users Microservice Order Service Spring Cloud - 13. Users Microservice Catalog Spring Cloud - 12. Users Microservice 사용자 조회 Spring Cloud - 11. Users Microservice Gateway 연동 Spring Cloud - 10. Users Microservice 사용자 추가 Spring Cloud로 개발하는 마이크로서비스 애플리케이션 9 Spring Cloud - Users Microservice Users Microservice 사용자 추가@RestController@RequestMapping("/")public class UserController { private Environment env; private UserService userService; private Greeting greeting; public UserController(Environment env, UserService userService){ this.env = env; this.userService = userService; } @GetMapping("/health_check") public String status(){ return "It's Working in User Service"; } @GetMapping("/welcome") public String welcome(){ return env.getProperty("greeting.message"); } @GetMapping("/welcome_value") public String welcomeValue(){ return greeting.getMessage(); } @PostMapping("/users") public ResponseEntity createUser(@RequestBody RequestUser user){ ModelMapper modelMapper = new ModelMapper(); modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); UserDto userDto = modelMapper.map(user, UserDto.class); userService.createUser(userDto); ResponseUser responseUser = modelMapper.map(userDto, ResponseUser.class); return ResponseEntity.status(HttpStatus.CREATED).body(responseUser); }} @Datapublic class ResponseUser { private String email; private String name; private String userId;} @Datapublic class RequestUser { @NotNull(message = "Email cannot be null") @Size(min = 2, message = "Email not be less than two characters") private String email; @NotNull(message = "Name cannot be null") @Size(min = 2, message = "Name not be less than two characters") private String pwd; @NotNull(message = "Password cannot be null") @Size(min = 8, message = "Password not be less than two characters") private String name;} @Datapublic class UserDto { private String email; private String name; private String pwd; private String userId; private Date createdAt; private String encryptedPwd;} @Component@Data@AllArgsConstructor@NoArgsConstructorpublic class Greeting { @Value("${greeting.message}") private String message;} @Data@Entity@Table("users")public class UserEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false, length = 50) private String email; @Column(nullable = false, length = 50) private String name; @Column(nullable = false, unique = true) private String userId; @Column(nullable = false, unique = true) private String encryptedPwd;}