Spring Cloud - 12. 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 12. Users Microservice 사용자 조회@Overridepublic UserDto getUserByUserId(String userId) { UserEntity userEntity = userRepository.findByUserId(userId); if (userEntity == null) throw new UsernameNotFoundException("User not found"); UserDto userDto = new ModelMapper().map(userEntity, UserDto.class); List<ResponseOrder> orders = new ArrayList<>(); userDto.setOrders(orders); return userDto;}@Overridepublic Iterable<UserEntity> getUserByAll() { return userRepository.findAll();} public interface UserRepository extends CrudRepository<UserEntity, Long> { UserEntity findByUserId(String userId);} 전체 User 정보 가져오기@GetMapping("/users")public ResponseEntity<List<ResponseUser>> getUsers() { Iterable<UserEntity> userList = userService.getUserByAll(); List<ResponseUser> result = new ArrayList<>(); userList.forEach(v -> { result.add(new ModelMapper().map(v, ResponseUser.class)); }); return ResponseEntity.status(HttpStatus.OK).body(result);} 특정 User 정보 가져오기@GetMapping("/users/{userId}") public ResponseEntity<ResponseUser> getUsers(@PathVariable("userId") String userId) { UserDto userDto = userService.getUserByUserId(userId); ResponseUser returnValue = new ModelMapper().map(userDto, ResponseUser.class); return ResponseEntity.status(HttpStatus.OK).body(returnValue); }