From 0dca6fe1a4e2f33d318ddb936e9936e7ca95cbc1 Mon Sep 17 00:00:00 2001 From: HeeSung98 Date: Thu, 7 Dec 2023 11:36:44 +0900 Subject: [PATCH] =?UTF-8?q?userInfoByNickname=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 10 ++++++++++ .../user/security/filter/ApiCheckFilter.java | 3 --- .../com/weather/user/service/UserService.java | 4 ++++ .../weather/user/service/UserServiceImpl.java | 18 ++++++++++++++++++ .../com/weather/user/repository/UserTest.java | 14 ++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/user/src/main/java/com/weather/user/controller/UserController.java b/user/src/main/java/com/weather/user/controller/UserController.java index 697705c..a02765d 100644 --- a/user/src/main/java/com/weather/user/controller/UserController.java +++ b/user/src/main/java/com/weather/user/controller/UserController.java @@ -137,4 +137,14 @@ public ResponseEntity remove(@PathVariable String email) { return new ResponseEntity(result, HttpStatus.OK); } + + @PostMapping("/api/userinfo") + public ResponseEntity userInfoByNickname(@RequestBody UserDTO userDTO) { + log.info(" ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ userInfoByNickname controller ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ"); + log.info("nickname: " + userDTO.getNickname()); + + UserDTO result = userService.userInfoByNickname(userDTO.getNickname()); + + return new ResponseEntity(result, HttpStatus.OK); + } } diff --git a/user/src/main/java/com/weather/user/security/filter/ApiCheckFilter.java b/user/src/main/java/com/weather/user/security/filter/ApiCheckFilter.java index 8674c9f..43365f8 100644 --- a/user/src/main/java/com/weather/user/security/filter/ApiCheckFilter.java +++ b/user/src/main/java/com/weather/user/security/filter/ApiCheckFilter.java @@ -35,8 +35,6 @@ public void doFilterInternal(HttpServletRequest request, HttpServletResponse res if(headerCheck) { log.info("ApiCheckFilter.............................................."); - log.info("ApiCheckFilter.............................................."); - log.info("ApiCheckFilter.............................................."); // boolean checkHeader = checkAuthHeader(request); // @@ -57,7 +55,6 @@ public void doFilterInternal(HttpServletRequest request, HttpServletResponse res // return; } - log.info("?"); filterChain.doFilter(request, response); } diff --git a/user/src/main/java/com/weather/user/service/UserService.java b/user/src/main/java/com/weather/user/service/UserService.java index cab03bc..430c555 100644 --- a/user/src/main/java/com/weather/user/service/UserService.java +++ b/user/src/main/java/com/weather/user/service/UserService.java @@ -6,6 +6,8 @@ import com.weather.user.entity.User; import org.springframework.web.multipart.MultipartFile; +import java.util.Optional; + public interface UserService { @@ -29,6 +31,8 @@ public interface UserService { void remove(String email); + public UserDTO userInfoByNickname(String nickname); + default User dtoToEntity(UserDTO userDTO) { User user = User.builder() .email(userDTO.getEmail()) diff --git a/user/src/main/java/com/weather/user/service/UserServiceImpl.java b/user/src/main/java/com/weather/user/service/UserServiceImpl.java index 8901935..c5f8e5b 100644 --- a/user/src/main/java/com/weather/user/service/UserServiceImpl.java +++ b/user/src/main/java/com/weather/user/service/UserServiceImpl.java @@ -225,4 +225,22 @@ public void remove(String email) { throw new Error("이미 탈퇴 처리중인 유저입니다."); } } + + @Override + public UserDTO userInfoByNickname(String nickname) { + Optional optionalUser = userRepository.findByNickname(nickname); + log.info("optionalUser: " + optionalUser); + + if(optionalUser.isEmpty()) { + throw new Error("존재하지 않는 유저입니다."); + } + User user = optionalUser.get(); + + if(!user.isStatus()) { + throw new Error("탈퇴 대기중인 유저입니다."); + } + + UserDTO result = entityToDTO(user); + return result; + } } diff --git a/user/src/test/java/com/weather/user/repository/UserTest.java b/user/src/test/java/com/weather/user/repository/UserTest.java index 09d7643..59f9cdb 100644 --- a/user/src/test/java/com/weather/user/repository/UserTest.java +++ b/user/src/test/java/com/weather/user/repository/UserTest.java @@ -39,4 +39,18 @@ void insertUser() { userRepository.save(user); }); } + + @Test + void insertTestUser() { + User user = User.builder() + .email("ryu@test.com") + .password(passwordEncoder.encode("1234")) + .name("류준열") + .nickname("류준열") + .fromSocial(false) + .status(true) + .build(); + + userRepository.save(user); + } }