From d84017c6a881f7516a22a20047dbf0759994b0d7 Mon Sep 17 00:00:00 2001 From: Lee Eun Seob <107783650+MinchoGreenT@users.noreply.github.com> Date: Fri, 20 Oct 2023 16:13:45 +0900 Subject: [PATCH 01/95] Update actions.yml --- .github/workflows/actions.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index e26bbc4..5012f3d 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,9 @@ name: ModernFarmer CI/CD on: push: - branches: ["main"] + branches: ["dev"] + pull_request: + branches: ["dev"] permissions: contents: read @@ -72,4 +74,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 \ No newline at end of file + docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From ae467b568a9f1815e3ab2c0523f54e4ba5b37114 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Fri, 20 Oct 2023 16:25:40 +0900 Subject: [PATCH 02/95] =?UTF-8?q?[feat]=20=EA=B5=AC=EA=B8=80=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/AuthController.java | 10 +++ .../dto/response/GoogleUserResponseDto.java | 20 ++++++ .../farmususer/user/service/AuthService.java | 64 ++++++++++++++++++- .../user/util/JwtTokenProvider.java | 2 +- 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java index 40c86ba..3d0fb85 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java @@ -35,7 +35,17 @@ public TokenResponseDto kakaoLogin(HttpServletRequest request) { return reissueTokenResponseDto; } + @PostMapping(value = "/google-login") + public TokenResponseDto googleLogin(HttpServletRequest request) { + String accessToken = jwtTokenProvider.resolveToken(request); + + TokenResponseDto tokenResponseDto = authService.googleLogin(accessToken); + + LOGGER.info("구글 로그인 완료"); + + return tokenResponseDto; + } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java new file mode 100644 index 0000000..410a17f --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java @@ -0,0 +1,20 @@ +package modernfarmer.server.farmususer.user.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class GoogleUserResponseDto { + + private String id; + private String email; + private boolean verified_email; + private String name; + private String given_name; + private String family_name; + private String picture; + private String locale; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 71466eb..36b22c6 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,5 +1,6 @@ package modernfarmer.server.farmususer.user.service; +import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.entity.User; @@ -38,14 +39,64 @@ public AuthService(WebClient webClient, UserRepository userRepository, JwtTokenP this.redisTemplate = redisTemplate; } + public TokenResponseDto googleLogin(String accessToken) { + + User user; + + Mono<GoogleUserResponseDto> userInfoMono = getUserGoogleInfo(accessToken); + GoogleUserResponseDto userInfo = userInfoMono.block(); + +// LOGGER.info(String.valueOf(userInfo.getAccount_email())); +// LOGGER.info(String.valueOf(userInfo.getProfile_nickname())); +// LOGGER.info(String.valueOf(userInfo.getProfile_image())); + +// LOGGER.info(String.valueOf(userInfo.getKakao_account().getEmail())); +// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfileImageUrl())); +// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); + + Optional<User> userData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + + if(userData.isEmpty()){ + user = User.builder() + .usernumber(String.valueOf(userInfo.getId())) + .role("USER") +// .email(userInfo.getKakao_account().getEmail()) +// .nickname(userInfo.getKakao_account().getProfile().getNickname()) +// .userProfile(userInfo.getKakao_account().getProfile().getProfileImageUrl()) + .build(); + + userRepository.save(user); + } + + Optional<User> userLoginData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + String refreshToken = "Bearer " +jwtTokenProvider.createRereshToken(userLoginData.get().getId()); + + TokenResponseDto tokenResponseDto = TokenResponseDto.builder() + .message("OK") + .code(200) + .accessToken("Bearer " +jwtTokenProvider.createAccessToken( + userLoginData.get().getId(), + String.valueOf(userLoginData.get().getRole()))) + .refreshToken(refreshToken) + .build(); + +// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"userId", String.valueOf(userLoginData.get().getId())); +// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"role", String.valueOf(userLoginData.get().getRole())); + + redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); + + + return tokenResponseDto; + } + public TokenResponseDto kakaoLogin(String accessToken) { User user; - Mono<KakaoUserResponseDto> userInfoMono = getUserInfo(accessToken); + Mono<KakaoUserResponseDto> userInfoMono = getUserKakaoInfo(accessToken); KakaoUserResponseDto userInfo = userInfoMono.block(); // LOGGER.info(String.valueOf(userInfo.getAccount_email())); @@ -94,7 +145,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { } - public Mono<KakaoUserResponseDto> getUserInfo(String accessToken) { + public Mono<KakaoUserResponseDto> getUserKakaoInfo(String accessToken) { return webClient .get() .uri("https://kapi.kakao.com/v2/user/me") // 카카오 사용자 정보 엔드포인트 @@ -102,4 +153,13 @@ public Mono<KakaoUserResponseDto> getUserInfo(String accessToken) { .retrieve() .bodyToMono(KakaoUserResponseDto.class); } + + public Mono<GoogleUserResponseDto> getUserGoogleInfo(String accessToken) { + return webClient + .get() + .uri("https://www.googleapis.com/oauth2/v2/userinfo") // 카카오 사용자 정보 엔드포인트 + .headers(headers -> headers.setBearerAuth(accessToken)) + .retrieve() + .bodyToMono(GoogleUserResponseDto.class); + } } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 751a796..1a6dccc 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -72,7 +72,7 @@ public String createRereshToken(Long userId) { // 토큰 생성 public String resolveToken(HttpServletRequest request) { LOGGER.info("[resolveToken] HTTP 헤더에서 Token 값 추출"); - String tokenHeader = request.getHeader("Authentication"); + String tokenHeader = request.getHeader("Authorization"); if (tokenHeader != null && tokenHeader.startsWith("Bearer ")) { return tokenHeader.substring(7); From 9f305395b03c3bbd063c48ad8e8b8820c28b3f95 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Sat, 21 Oct 2023 15:53:03 +0900 Subject: [PATCH 03/95] =?UTF-8?q?[fix]=20=EC=9E=AC=EB=B0=9C=EA=B8=89,=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/AuthController.java | 52 +++++++++---------- .../user/controller/UserController.java | 51 ++++++++++++++++++ 2 files changed, 77 insertions(+), 26 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java index 8c8a619..4039492 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java @@ -35,32 +35,32 @@ public TokenResponseDto kakaoLogin(HttpServletRequest request) { return reissueTokenResponseDto; } - - @DeleteMapping("/logout") - public ResponseDto logout(HttpServletRequest request) { - - - String userId = jwtTokenProvider.getUserId(request); - - ResponseDto logoutResponseDto = authService.logout(Long.valueOf(userId)); - - LOGGER.info("로그아웃 완료"); - - return logoutResponseDto; - } - - @GetMapping(value = "/reissue-token") - public TokenResponseDto reissueToken(HttpServletRequest request) { - - String userId = jwtTokenProvider.getUserId(request); - String refreshToken = jwtTokenProvider.resolveToken(request); - - TokenResponseDto reissueTokenResponseDto = authService.reissueToken(refreshToken, Long.valueOf(userId)); - - LOGGER.info("토큰 재발급 완료"); - - return reissueTokenResponseDto; - } +// +// @DeleteMapping("/logout") +// public ResponseDto logout(HttpServletRequest request) { +// +// +// String userId = jwtTokenProvider.getUserId(request); +// +// ResponseDto logoutResponseDto = authService.logout(Long.valueOf(userId)); +// +// LOGGER.info("로그아웃 완료"); +// +// return logoutResponseDto; +// } +// +// @GetMapping(value = "/reissue-token") +// public TokenResponseDto reissueToken(HttpServletRequest request) { +// +// String userId = jwtTokenProvider.getUserId(request); +// String refreshToken = jwtTokenProvider.resolveToken(request); +// +// TokenResponseDto reissueTokenResponseDto = authService.reissueToken(refreshToken, Long.valueOf(userId)); +// +// LOGGER.info("토큰 재발급 완료"); +// +// return reissueTokenResponseDto; +// } @PostMapping(value = "/google-login") public TokenResponseDto googleLogin(HttpServletRequest request) { diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java new file mode 100644 index 0000000..fd8a8bf --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -0,0 +1,51 @@ +package modernfarmer.server.farmususer.user.controller; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; +import modernfarmer.server.farmususer.user.service.AuthService; +import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@Slf4j +@RestController +@RequestMapping("/api/user") +@RequiredArgsConstructor +public class UserController { + + private final AuthService authService; + private final JwtTokenProvider jwtTokenProvider; + + + @DeleteMapping("/logout") + public ResponseDto logout(HttpServletRequest request) { + + + String userId = jwtTokenProvider.getUserId(request); + + ResponseDto logoutResponseDto = authService.logout(Long.valueOf(userId)); + + log.info("로그아웃 완료"); + + return logoutResponseDto; + } + + @GetMapping(value = "/reissue-token") + public TokenResponseDto reissueToken(HttpServletRequest request) { + + String userId = jwtTokenProvider.getUserId(request); + String refreshToken = jwtTokenProvider.resolveToken(request); + + TokenResponseDto reissueTokenResponseDto = authService.reissueToken(refreshToken, Long.valueOf(userId)); + + log.info("토큰 재발급 완료"); + + return reissueTokenResponseDto; + } +} From c48078abddeec736697e5939a418645088359283 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Sat, 21 Oct 2023 22:13:26 +0900 Subject: [PATCH 04/95] =?UTF-8?q?[fix]=20=EC=9E=AC=EB=B0=9C=EA=B8=89=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20userId=20=ED=98=95=EB=B3=80?= =?UTF-8?q?=ED=99=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/AuthService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index f6e8ca4..c99ca8f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -169,7 +169,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { return reissueTokenResponse; } - String redisRefreshToken = redisTemplate.opsForValue().get(userId); + String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); if(redisRefreshToken.equals(refreshToken)){ @@ -179,7 +179,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { .builder() .code(200) .message("OK") - .accessToken(jwtTokenProvider.createAccessToken(Long.valueOf(userId),userRole)) + .accessToken(jwtTokenProvider.createAccessToken(userId,userRole)) .refreshToken(refreshToken) .build(); From b5e5a0b501c1516740f596c22899b3fcd9b05641 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Sat, 21 Oct 2023 23:55:28 +0900 Subject: [PATCH 05/95] =?UTF-8?q?[fix]=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=89=AC=20=ED=86=A0=ED=81=B0=EC=97=90=20=EC=84=9C=EB=B8=8C?= =?UTF-8?q?=EC=A0=9D=ED=8A=B8=20=EC=A0=95=EB=B3=B4=20=EC=82=BD=EC=9E=85=20?= =?UTF-8?q?=EB=A6=AC=ED=94=84=EB=A0=88=EC=89=AC=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95=20(createRereshToken=20?= =?UTF-8?q?->=20createRefreshToken)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/AuthService.java | 4 ++-- .../server/farmususer/user/util/JwtTokenProvider.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 3971ee4..efb137f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -72,7 +72,7 @@ public TokenResponseDto googleLogin(String accessToken) { Optional<User> userLoginData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); - String refreshToken = "Bearer " +jwtTokenProvider.createRereshToken(userLoginData.get().getId()); + String refreshToken = "Bearer " +jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") @@ -123,7 +123,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { Optional<User> userLoginData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); - String refreshToken = "Bearer " +jwtTokenProvider.createRereshToken(userLoginData.get().getId()); + String refreshToken = "Bearer " +jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 726d9b0..998d757 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -55,11 +55,12 @@ public String createAccessToken(Long userId, String roles) { // 토 return token; } - public String createRereshToken(Long userId) { // 토큰 생성 + public String createRefreshToken(Long userId) { // 토큰 생성 Claims claims = Jwts.claims().setSubject(String.valueOf(userId)); Date now = new Date(); String token = Jwts.builder() + .setClaims(claims) .setIssuedAt(now) .setExpiration(new Date(now.getTime() + refreshTokenTime)) .signWith(SignatureAlgorithm.HS256, secretKey) // 암호화 알고리즘, secret 값 세팅 From a615cefba6f662bc6bff255d3cd218a0fbcec51b Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Sun, 22 Oct 2023 01:08:34 +0900 Subject: [PATCH 06/95] =?UTF-8?q?[fix]=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=89=AC=20=ED=86=A0=ED=81=B0=20=EC=A0=80=EC=9E=A5=20=EC=8B=9C?= =?UTF-8?q?=20bearer=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/AuthService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index efb137f..923f9d9 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -123,7 +123,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { Optional<User> userLoginData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); - String refreshToken = "Bearer " +jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); + String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") From 559e9c56f6aa0992d69c0a2a5ddf68137846a558 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Sun, 22 Oct 2023 15:12:22 +0900 Subject: [PATCH 07/95] =?UTF-8?q?[fix]=20UserRepository=EC=9D=98=20findUse?= =?UTF-8?q?rRole=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EA=B0=92=20User=20->=20String=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/repository/UserRepository.java | 2 +- .../server/farmususer/user/service/AuthService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 1082964..cacff0b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -15,7 +15,7 @@ public interface UserRepository extends JpaRepository<User, Long> { Optional<User> findByUsernumber(String usernumber); @Query("SELECT a.role FROM User AS a WHERE a.id = :userId") - User findUserRole(@Param("userId") Long userId); + String findUserRole(@Param("userId") Long userId); diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 923f9d9..9f8c7cb 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -171,13 +171,13 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { if(redisRefreshToken.equals(refreshToken)){ - String userRole = String.valueOf(userRepository.findUserRole(userId)); + String userRole = userRepository.findUserRole(userId); reissueTokenResponse= TokenResponseDto .builder() .code(200) .message("OK") - .accessToken(jwtTokenProvider.createAccessToken(userId,userRole)) + .accessToken(jwtTokenProvider.createAccessToken(userId, userRole)) .refreshToken(refreshToken) .build(); From 69e0948a45869b5e438b52b5927f49300dde0e41 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Mon, 23 Oct 2023 16:22:59 +0900 Subject: [PATCH 08/95] =?UTF-8?q?[fix]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8,=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EC=8B=9C=20Bearer=20?= =?UTF-8?q?=EB=B6=99=EC=9D=B4=EC=A7=80=20=EC=95=8A=EA=B3=A0=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/AuthService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 9f8c7cb..32da0bd 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -72,12 +72,12 @@ public TokenResponseDto googleLogin(String accessToken) { Optional<User> userLoginData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); - String refreshToken = "Bearer " +jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); + String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") .code(200) - .accessToken("Bearer " +jwtTokenProvider.createAccessToken( + .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole()))) .refreshToken(refreshToken) @@ -128,7 +128,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") .code(200) - .accessToken("Bearer " +jwtTokenProvider.createAccessToken( + .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole()))) .refreshToken(refreshToken) From 5744641eafc0c08b58d4e7ecd8b61e7fdd6ffe29 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 15:32:11 +0900 Subject: [PATCH 09/95] =?UTF-8?q?[feat]=20=EC=97=90=EB=9F=AC=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/CustomExceptionContext.java | 25 +++++++++++ .../global/exception/ErrorResponse.java | 13 ++++++ .../global/exception/ExceptionContext.java | 11 +++++ .../exception/GlobalExceptionHandler.java | 43 +++++++++++++++++++ .../exception/ModernFarmerException.java | 19 ++++++++ .../badrequest/BadRequestException.java | 13 ++++++ .../badrequest/FirebaseConfigException.java | 10 +++++ .../exception/notfound/NotFoundException.java | 16 +++++++ .../notfound/NotFoundMedicineException.java | 12 ++++++ .../notfound/NotFoundMemberException.java | 12 ++++++ .../unauthorized/InvalidBearerException.java | 8 ++++ .../unauthorized/InvalidTokenException.java | 12 ++++++ .../unauthorized/TokenExpiredException.java | 12 ++++++ .../unauthorized/UnauthorizedException.java | 12 ++++++ .../farmususer/user/service/AuthService.java | 4 ++ 15 files changed, 222 insertions(+) create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java new file mode 100644 index 0000000..bf83931 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java @@ -0,0 +1,25 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum CustomExceptionContext implements ExceptionContext{ + // MEMBER (예시) + NOT_FOUND_MEMBER_ERROR(HttpStatus.NOT_FOUND, 1000, "해당 회원을 찾을 수 없습니다."), + INVALID_MEMBER_ID_ERROR(HttpStatus.BAD_REQUEST, 1001, "회원에 대한 유효하지 않은 요청입니다."), + NOT_FOUND_ALARM_ERROR(HttpStatus.NOT_FOUND, 1002, "해당 알람 정보를 찾을 수 없습니다."), + INVALID_ADD_MEMBER(HttpStatus.BAD_REQUEST, 1003, "이미 존재하는 캐릭터입니다."), + SDK_NOT_FOUND(HttpStatus.BAD_REQUEST, 1007, "해당 경로에 Firebase SDK json 파일이 존재하지 않아, Firebase 시스템을 초기화 할 수 없습니다."), + FIREBASE_TOKEN_EXCEPTION(HttpStatus.BAD_REQUEST, 1004, "파이어베이스 토큰 오류입니다."), + FIREBASE_CONFIG_EXCEPTION(HttpStatus.BAD_REQUEST, 1005, "파이어베이스 설정 오류입니다."), + NOT_FOUND_MEDICINE_ERROR(HttpStatus.NOT_FOUND, 1006, "해당 약 정보를 찾을 수 없습니다."); + // DOMAIN PER EXCEPTIONS ... + + + private final HttpStatus httpStatus; + private final int code; + private final String message; +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java new file mode 100644 index 0000000..472b87c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java @@ -0,0 +1,13 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@ToString +public class ErrorResponse { + + private int code; + private String message; +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java new file mode 100644 index 0000000..8f2bbb7 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java @@ -0,0 +1,11 @@ +package modernfarmer.server.farmususer.global.exception; + +import org.springframework.http.HttpStatus; + +public interface ExceptionContext { + HttpStatus getHttpStatus(); + + String getMessage(); + + int getCode(); +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..7f34258 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java @@ -0,0 +1,43 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import javax.servlet.http.HttpServletRequest; +import java.util.Objects; + +@Slf4j +@RequiredArgsConstructor +@RestControllerAdvice +public class GlobalExceptionHandler { + private final int INVALID_PARAMETER_CODE = 400; + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity<ErrorResponse> handleInputFieldException(MethodArgumentNotValidException e) { + FieldError mainError = e.getFieldErrors().get(0); + String[] errorInfo = Objects.requireNonNull(mainError.getDefaultMessage()).split(":"); + String message = errorInfo[0]; + return ResponseEntity.badRequest().body(new ErrorResponse(INVALID_PARAMETER_CODE, message)); + } + + @ExceptionHandler(ModernFarmerException.class) + public ResponseEntity<ErrorResponse> handleModernFarmerException(ModernFarmerException e) { + return ResponseEntity.status(e.getHttpStatus()).body(new ErrorResponse(e.getCode(), e.getMessage())); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity<ErrorResponse> unhandledException(Exception e, HttpServletRequest request) { + log.error("UnhandledException: {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage() + ); + return ResponseEntity.internalServerError() + .body(new ErrorResponse(7777, "서버와의 접속이 원활하지 않습니다.")); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java new file mode 100644 index 0000000..6a40961 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java @@ -0,0 +1,19 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +public class ModernFarmerException extends RuntimeException { + private final HttpStatus httpStatus; + private final String message; + private final int code; + + public ModernFarmerException(HttpStatus httpStatus, String message, int code) { + this.httpStatus = httpStatus; + this.message = message; + this.code = code; + } + + +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java new file mode 100644 index 0000000..b91018d --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java @@ -0,0 +1,13 @@ +package modernfarmer.server.farmususer.global.exception.badrequest; + + +import lombok.Getter; +import modernfarmer.server.farmususer.global.exception.ExceptionContext; +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; + +@Getter +public class BadRequestException extends ModernFarmerException { + public BadRequestException(ExceptionContext context){ + super(context.getHttpStatus(), context.getMessage(), context.getCode()); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java new file mode 100644 index 0000000..fa3c385 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java @@ -0,0 +1,10 @@ +package modernfarmer.server.farmususer.global.exception.badrequest; + + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.FIREBASE_CONFIG_EXCEPTION; + +public class FirebaseConfigException extends BadRequestException { + public FirebaseConfigException(){ + super(FIREBASE_CONFIG_EXCEPTION); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java new file mode 100644 index 0000000..a522576 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java @@ -0,0 +1,16 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + + +import lombok.Getter; +import modernfarmer.server.farmususer.global.exception.ExceptionContext; +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; +import org.springframework.http.HttpStatus; + +@Getter +public class NotFoundException extends ModernFarmerException { + public NotFoundException(ExceptionContext context) { + super(context.getHttpStatus(), context.getMessage(), context.getCode()); + } + + +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java new file mode 100644 index 0000000..2d02c6c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + + +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.NOT_FOUND_MEDICINE_ERROR; + +public class NotFoundMedicineException extends NotFoundException { + public NotFoundMedicineException() { + super(NOT_FOUND_MEDICINE_ERROR); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java new file mode 100644 index 0000000..976fe3e --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.NOT_FOUND_MEMBER_ERROR; + + +public class NotFoundMemberException extends NotFoundException { + public NotFoundMemberException() { + super(NOT_FOUND_MEMBER_ERROR); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java new file mode 100644 index 0000000..01c1a40 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java @@ -0,0 +1,8 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + +public class InvalidBearerException extends UnauthorizedException { + + public InvalidBearerException() { + super("로그인이 필요한 서비스입니다.", 1013); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java new file mode 100644 index 0000000..55af400 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + +public class InvalidTokenException extends UnauthorizedException { + + public InvalidTokenException() { + super("올바르지 않은 토큰입니다. 다시 로그인해주세요.", 1015); + } + + public InvalidTokenException(String message) { + super(message, 1015); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java new file mode 100644 index 0000000..f7882b6 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + +public class TokenExpiredException extends UnauthorizedException { + + public TokenExpiredException() { + super("로그인 인증 유효기간이 만료되었습니다. 다시 로그인 해주세요.", 1014); + } + + public TokenExpiredException(String message) { + super(message, 1014); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java new file mode 100644 index 0000000..8ebccb6 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + + +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; +import org.springframework.http.HttpStatus; + +public class UnauthorizedException extends ModernFarmerException { + + public UnauthorizedException(String message, int code) { + super(HttpStatus.UNAUTHORIZED, message, code); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 32da0bd..d399a87 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,6 +1,7 @@ package modernfarmer.server.farmususer.user.service; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; @@ -163,6 +164,9 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { .code(417) .message("재로그인하시오") .build(); + + + new TokenExpiredException(); return reissueTokenResponse; } From d9506d3c959a7bb525b9382799e5d6e6cad7043a Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 17:19:16 +0900 Subject: [PATCH 10/95] =?UTF-8?q?[feat]=20=EC=9E=AC=EB=B0=9C=EA=B8=89=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC=20=EC=A0=81=EC=9A=A9=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../unauthorized/InvalidBearerException.java | 8 -- .../unauthorized/InvalidTokenException.java | 12 --- .../user/controller/UserController.java | 8 +- .../farmususer/user/service/AuthService.java | 66 -------------- .../farmususer/user/service/UserService.java | 90 +++++++++++++++++++ .../user/util/JwtTokenProvider.java | 4 +- 7 files changed, 98 insertions(+), 92 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/service/UserService.java diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 2b9666e..20917ec 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["dev"] + branches: ["feature_11/에러처리-추가"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java deleted file mode 100644 index 01c1a40..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java +++ /dev/null @@ -1,8 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - -public class InvalidBearerException extends UnauthorizedException { - - public InvalidBearerException() { - super("로그인이 필요한 서비스입니다.", 1013); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java deleted file mode 100644 index 55af400..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - -public class InvalidTokenException extends UnauthorizedException { - - public InvalidTokenException() { - super("올바르지 않은 토큰입니다. 다시 로그인해주세요.", 1015); - } - - public InvalidTokenException(String message) { - super(message, 1015); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index fd8a8bf..60eed70 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -4,7 +4,9 @@ import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; + import modernfarmer.server.farmususer.user.service.AuthService; +import modernfarmer.server.farmususer.user.service.UserService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -19,7 +21,7 @@ @RequiredArgsConstructor public class UserController { - private final AuthService authService; + private final UserService userService; private final JwtTokenProvider jwtTokenProvider; @@ -29,7 +31,7 @@ public ResponseDto logout(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); - ResponseDto logoutResponseDto = authService.logout(Long.valueOf(userId)); + ResponseDto logoutResponseDto = userService.logout(Long.valueOf(userId)); log.info("로그아웃 완료"); @@ -42,7 +44,7 @@ public TokenResponseDto reissueToken(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); String refreshToken = jwtTokenProvider.resolveToken(request); - TokenResponseDto reissueTokenResponseDto = authService.reissueToken(refreshToken, Long.valueOf(userId)); + TokenResponseDto reissueTokenResponseDto = userService.reissueToken(refreshToken, Long.valueOf(userId)); log.info("토큰 재발급 완료"); diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index d399a87..03f9d1d 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -145,72 +145,6 @@ public TokenResponseDto kakaoLogin(String accessToken) { } - public ResponseDto logout(Long userId) { - deleteValueByKey(String.valueOf(userId)); - - ResponseDto responseDto = ResponseDto.builder() - .message("OK") - .code(200) - .build(); - return responseDto; - } - - public TokenResponseDto reissueToken(String refreshToken, Long userId) { - TokenResponseDto reissueTokenResponse; - - if(!jwtTokenProvider.validateRefreshToken(refreshToken)){ - - reissueTokenResponse = TokenResponseDto.builder() - .code(417) - .message("재로그인하시오") - .build(); - - - new TokenExpiredException(); - - return reissueTokenResponse; - } - - String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - - if(redisRefreshToken.equals(refreshToken)){ - - String userRole = userRepository.findUserRole(userId); - - reissueTokenResponse= TokenResponseDto - .builder() - .code(200) - .message("OK") - .accessToken(jwtTokenProvider.createAccessToken(userId, userRole)) - .refreshToken(refreshToken) - .build(); - - return reissueTokenResponse; - - } - - reissueTokenResponse = TokenResponseDto.builder() - .code(403) - .message("접근이 올바르지 않습니다.") - .build(); - - return reissueTokenResponse; - - } - - - - - public void deleteValueByKey(String key) { - redisTemplate.delete(key); - } - - - - - - - public Mono<KakaoUserResponseDto> getUserKakaoInfo(String accessToken) { return webClient .get() diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java new file mode 100644 index 0000000..5bb839f --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -0,0 +1,90 @@ +package modernfarmer.server.farmususer.user.service; + +import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; +import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; +import modernfarmer.server.farmususer.user.repository.UserRepository; +import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; + + +@Service +public class UserService { + + public JwtTokenProvider jwtTokenProvider; + public RedisTemplate<String, String> redisTemplate; + + public UserRepository userRepository; + + private final WebClient webClient; + + @Autowired + public UserService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate) { + this.webClient = webClient; + this.userRepository = userRepository; + this.jwtTokenProvider = jwtTokenProvider; + this.redisTemplate = redisTemplate; + } + + + public ResponseDto logout(Long userId) { + deleteValueByKey(String.valueOf(userId)); + + ResponseDto responseDto = ResponseDto.builder() + .message("OK") + .code(200) + .build(); + return responseDto; + } + + public TokenResponseDto reissueToken(String refreshToken, Long userId) { + TokenResponseDto reissueTokenResponse; + + if(!jwtTokenProvider.validateRefreshToken(refreshToken)){ + +// reissueTokenResponse = TokenResponseDto.builder() +// .code(417) +// .message("재로그인하시오") +// .build(); + + + new TokenExpiredException(); + + // return reissueTokenResponse; + } + + String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); + + if(redisRefreshToken.equals(refreshToken)){ + + String userRole = userRepository.findUserRole(userId); + + reissueTokenResponse= TokenResponseDto + .builder() + .code(200) + .message("OK") + .accessToken(jwtTokenProvider.createAccessToken(userId, userRole)) + .refreshToken(refreshToken) + .build(); + + return reissueTokenResponse; + + } + + reissueTokenResponse = TokenResponseDto.builder() + .code(403) + .message("접근이 올바르지 않습니다.") + .build(); + + return reissueTokenResponse; + + } + + public void deleteValueByKey(String key) { + redisTemplate.delete(key); + } + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 998d757..12d657b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -26,10 +26,10 @@ public class JwtTokenProvider { private String secretKey; - private final long accessTokenTime = 30L * 24L * 60 * 60 * 1000; // 1달 토큰 유효 + private final long accessTokenTime = 30L * 1000;; // 1달 토큰 유효 - private final long refreshTokenTime = 1L * 60 * 1000 * 2; // 1달 토큰 유효 + private final long refreshTokenTime = 30L * 1000 * 2; // 1달 토큰 유효 @PostConstruct protected void init() { From 72233ddb07ad9d6819ad3dd8a2c51fffa50846a4 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 17:23:22 +0900 Subject: [PATCH 11/95] =?UTF-8?q?[fix]=20=EC=9D=B8=EC=8A=A4=ED=84=B4?= =?UTF-8?q?=EC=8A=A4=20=EB=8F=84=EC=BB=A4=20=EA=B6=8C=ED=95=9C=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 20917ec..be8a018 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -7,7 +7,6 @@ on: pull_request: branches: ["dev"] - permissions: contents: read From b976adffdfc757349714cc722965d74f5d7f165e Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 18:21:17 +0900 Subject: [PATCH 12/95] =?UTF-8?q?[fix]=20jwt=20secret=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index be8a018..100b0c8 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -63,6 +63,7 @@ jobs: docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 . docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + # 서버에서 Docker 이미지 실행 - name: EC2 Docker Run uses: appleboy/ssh-action@master From 999737025784cd684f2a272a4ad59372d24b8614 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 18:33:09 +0900 Subject: [PATCH 13/95] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 100b0c8..c1b2e44 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -76,4 +76,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + docker run -d -p 80:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 5c88fb20a08d0a2cd9646cd294cefb209c1b4849 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 18:48:24 +0900 Subject: [PATCH 14/95] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index c1b2e44..5213cb3 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -63,7 +63,6 @@ jobs: docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 . docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - # 서버에서 Docker 이미지 실행 - name: EC2 Docker Run uses: appleboy/ssh-action@master From 9b2181bb239380ea8da4c554c263cf49de50a9fa Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 18:54:11 +0900 Subject: [PATCH 15/95] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5213cb3..be8a018 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -75,4 +75,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 99cd678acd8fcb4cdb1a6279bccf833382ab2c7f Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 27 Oct 2023 19:04:53 +0900 Subject: [PATCH 16/95] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD=208081?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index be8a018..5213cb3 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -75,4 +75,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + docker run -d -p 80:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 885b27b3954baf98ea8a5bc72ff2597d163845cd Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 28 Oct 2023 02:45:22 +0900 Subject: [PATCH 17/95] =?UTF-8?q?[fix]=20unauthorizedException=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unauthorized/TokenExpiredException.java | 12 ------------ .../unauthorized/UnauthorizedException.java | 12 ------------ .../farmususer/user/service/AuthService.java | 4 ---- .../farmususer/user/service/UserService.java | 14 -------------- 4 files changed, 42 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java deleted file mode 100644 index f7882b6..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - -public class TokenExpiredException extends UnauthorizedException { - - public TokenExpiredException() { - super("로그인 인증 유효기간이 만료되었습니다. 다시 로그인 해주세요.", 1014); - } - - public TokenExpiredException(String message) { - super(message, 1014); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java deleted file mode 100644 index 8ebccb6..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - - -import modernfarmer.server.farmususer.global.exception.ModernFarmerException; -import org.springframework.http.HttpStatus; - -public class UnauthorizedException extends ModernFarmerException { - - public UnauthorizedException(String message, int code) { - super(HttpStatus.UNAUTHORIZED, message, code); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 03f9d1d..20add15 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,16 +1,12 @@ package modernfarmer.server.farmususer.user.service; import lombok.extern.slf4j.Slf4j; -import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.HttpStatus; diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 5bb839f..b50093a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,6 +1,5 @@ package modernfarmer.server.farmususer.user.service; -import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.repository.UserRepository; @@ -43,19 +42,6 @@ public ResponseDto logout(Long userId) { public TokenResponseDto reissueToken(String refreshToken, Long userId) { TokenResponseDto reissueTokenResponse; - if(!jwtTokenProvider.validateRefreshToken(refreshToken)){ - -// reissueTokenResponse = TokenResponseDto.builder() -// .code(417) -// .message("재로그인하시오") -// .build(); - - - new TokenExpiredException(); - - // return reissueTokenResponse; - } - String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); if(redisRefreshToken.equals(refreshToken)){ From 217f533be84ffab730ebc9b3570ac3f058521c1d Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 28 Oct 2023 03:06:35 +0900 Subject: [PATCH 18/95] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index b50093a..1d60305 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -9,6 +9,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; +import java.util.Objects; + @Service public class UserService { @@ -44,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(redisRefreshToken.equals(refreshToken)){ + if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken)){ String userRole = userRepository.findUserRole(userId); From b1503a565b18c019c1abfac3b2a0d2aeb2d6dcfd Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 28 Oct 2023 03:10:11 +0900 Subject: [PATCH 19/95] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 1d60305..fae8b0f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken)){ + if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) || redisRefreshToken.isEmpty()){ String userRole = userRepository.findUserRole(userId); From 8dcb7299c995489a5e1aa3d11a6a8cb93e3fedc6 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 28 Oct 2023 03:14:08 +0900 Subject: [PATCH 20/95] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index fae8b0f..843b2b1 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) || redisRefreshToken.isEmpty()){ + if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) && !redisRefreshToken.isEmpty()){ String userRole = userRepository.findUserRole(userId); From 4c168cdbe9f01eda20cc3743ef6301528fc2ae8b Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 28 Oct 2023 03:21:57 +0900 Subject: [PATCH 21/95] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 843b2b1..2a46829 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) && !redisRefreshToken.isEmpty()){ + if(!redisRefreshToken.isEmpty() && redisRefreshToken.equals(refreshToken)){ String userRole = userRepository.findUserRole(userId); From 1ef7e7aad3905d45c288b2e41e7bc8bbcd6f2be6 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 28 Oct 2023 03:26:01 +0900 Subject: [PATCH 22/95] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 2a46829..c26aef7 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(!redisRefreshToken.isEmpty() && redisRefreshToken.equals(refreshToken)){ + if(refreshToken.equals(redisRefreshToken)){ String userRole = userRepository.findUserRole(userId); From 627687f34282066d12842fa6e98cb39f620d126b Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 28 Oct 2023 11:13:44 +0900 Subject: [PATCH 23/95] =?UTF-8?q?[fix]=20=EC=9E=AC=EB=B0=9C=EA=B8=89=20api?= =?UTF-8?q?=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/CustomExceptionContext.java | 12 ++++-------- .../global/exception/GlobalExceptionHandler.java | 2 +- .../exception/notfound/NotFoundMemberException.java | 12 ------------ .../notfound/NotFoundRefreshTokenException.java | 10 ++++++++++ .../server/farmususer/user/service/UserService.java | 10 +++------- 5 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java index bf83931..bb79779 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java @@ -7,15 +7,11 @@ @Getter @RequiredArgsConstructor public enum CustomExceptionContext implements ExceptionContext{ - // MEMBER (예시) - NOT_FOUND_MEMBER_ERROR(HttpStatus.NOT_FOUND, 1000, "해당 회원을 찾을 수 없습니다."), - INVALID_MEMBER_ID_ERROR(HttpStatus.BAD_REQUEST, 1001, "회원에 대한 유효하지 않은 요청입니다."), - NOT_FOUND_ALARM_ERROR(HttpStatus.NOT_FOUND, 1002, "해당 알람 정보를 찾을 수 없습니다."), - INVALID_ADD_MEMBER(HttpStatus.BAD_REQUEST, 1003, "이미 존재하는 캐릭터입니다."), - SDK_NOT_FOUND(HttpStatus.BAD_REQUEST, 1007, "해당 경로에 Firebase SDK json 파일이 존재하지 않아, Firebase 시스템을 초기화 할 수 없습니다."), - FIREBASE_TOKEN_EXCEPTION(HttpStatus.BAD_REQUEST, 1004, "파이어베이스 토큰 오류입니다."), + + FIREBASE_CONFIG_EXCEPTION(HttpStatus.BAD_REQUEST, 1005, "파이어베이스 설정 오류입니다."), - NOT_FOUND_MEDICINE_ERROR(HttpStatus.NOT_FOUND, 1006, "해당 약 정보를 찾을 수 없습니다."); + NOT_FOUND_MEDICINE_ERROR(HttpStatus.NOT_FOUND, 1006, "해당 약 정보를 찾을 수 없습니다."), + REFRESH_TOKEN_DIFFERENT(HttpStatus.BAD_REQUEST , 1000,"접근이 올바르지 않습니다."); // DOMAIN PER EXCEPTIONS ... diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java index 7f34258..17d97cc 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java @@ -38,6 +38,6 @@ public ResponseEntity<ErrorResponse> unhandledException(Exception e, HttpServlet e.getMessage() ); return ResponseEntity.internalServerError() - .body(new ErrorResponse(7777, "서버와의 접속이 원활하지 않습니다.")); + .body(new ErrorResponse(500, "서버와의 접속이 원활하지 않습니다.")); } } diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java deleted file mode 100644 index 976fe3e..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.notfound; - -import modernfarmer.server.farmususer.global.exception.ModernFarmerException; - -import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.NOT_FOUND_MEMBER_ERROR; - - -public class NotFoundMemberException extends NotFoundException { - public NotFoundMemberException() { - super(NOT_FOUND_MEMBER_ERROR); - } -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java new file mode 100644 index 0000000..37e735c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java @@ -0,0 +1,10 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.REFRESH_TOKEN_DIFFERENT; + +public class NotFoundRefreshTokenException extends NotFoundException{ + + public NotFoundRefreshTokenException() { + super(REFRESH_TOKEN_DIFFERENT); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index c26aef7..b3cc99f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,5 +1,6 @@ package modernfarmer.server.farmususer.user.service; +import modernfarmer.server.farmususer.global.exception.notfound.NotFoundRefreshTokenException; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.repository.UserRepository; @@ -60,14 +61,9 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { return reissueTokenResponse; - } - - reissueTokenResponse = TokenResponseDto.builder() - .code(403) - .message("접근이 올바르지 않습니다.") - .build(); - return reissueTokenResponse; + } + throw new NotFoundRefreshTokenException(); } From 19f40ba00610b8b1f9fd857493e37e3a97ecdb73 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 29 Oct 2023 20:01:24 +0900 Subject: [PATCH 24/95] =?UTF-8?q?[fix]=20=EC=B9=B4=EC=B9=B4=EC=98=A4,=20?= =?UTF-8?q?=EA=B5=AC=EA=B8=80=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=99=80=20=EC=A0=80=EC=9E=A5,=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../user/controller/AuthController.java | 27 --------- .../dto/response/GoogleUserResponseDto.java | 6 +- .../dto/response/KakaoUserResponseDto.java | 56 ++++++++++--------- .../server/farmususer/user/entity/User.java | 8 +++ .../farmususer/user/service/AuthService.java | 36 ++++-------- 6 files changed, 50 insertions(+), 85 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5213cb3..e1c3968 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_11/에러처리-추가"] + branches: ["feature_13/카카오,-구글-로그인-수정"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java index bcbae14..72beb69 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java @@ -36,33 +36,6 @@ public TokenResponseDto kakaoLogin(HttpServletRequest request) { return reissueTokenResponseDto; } -// -// @DeleteMapping("/logout") -// public ResponseDto logout(HttpServletRequest request) { -// -// -// String userId = jwtTokenProvider.getUserId(request); -// -// ResponseDto logoutResponseDto = authService.logout(Long.valueOf(userId)); -// -// LOGGER.info("로그아웃 완료"); -// -// return logoutResponseDto; -// } -// -// @GetMapping(value = "/reissue-token") -// public TokenResponseDto reissueToken(HttpServletRequest request) { -// -// String userId = jwtTokenProvider.getUserId(request); -// String refreshToken = jwtTokenProvider.resolveToken(request); -// -// TokenResponseDto reissueTokenResponseDto = authService.reissueToken(refreshToken, Long.valueOf(userId)); -// -// LOGGER.info("토큰 재발급 완료"); -// -// return reissueTokenResponseDto; -// } - @PostMapping(value = "/google-login") public TokenResponseDto googleLogin(HttpServletRequest request) { diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java index 410a17f..6ede66f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GoogleUserResponseDto.java @@ -11,10 +11,6 @@ public class GoogleUserResponseDto { private String id; private String email; - private boolean verified_email; - private String name; - private String given_name; - private String family_name; private String picture; - private String locale; + private String name; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java index b2d1756..cd44f2f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/KakaoUserResponseDto.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -9,6 +10,7 @@ @Getter @Builder +@AllArgsConstructor public class KakaoUserResponseDto { private long id; @@ -16,33 +18,33 @@ public class KakaoUserResponseDto { public KakaoUserResponseDto(@JsonProperty("id") long id) { this.id = id; } -// private UserProfileDTO kakao_account; -// -// -// @Setter -// @Getter -// public class UserProfileDTO { -// private boolean profileNicknameNeedsAgreement; -// private boolean profileImageNeedsAgreement; -// private ProfileData profile; -// private boolean hasEmail; -// private boolean emailNeedsAgreement; -// private boolean isEmailValid; -// private boolean isEmailVerified; -// private String email; -// -// -// -// -// @Getter -// @Setter -// public class ProfileData { -// private String nickname; -// private String thumbnailImageUrl; -// private String profileImageUrl; -// private boolean isDefaultImage; -// } -// } + private UserProfileDTO kakao_account; + + + @Setter + @Getter + public class UserProfileDTO { + private boolean profileNicknameNeedsAgreement; + private boolean profileImageNeedsAgreement; + private ProfileData profile; + private boolean hasEmail; + private boolean emailNeedsAgreement; + private boolean isEmailValid; + private boolean isEmailVerified; + private String email; + + + + + @Getter + @Setter + public class ProfileData { + private String nickname; + private String thumbnail_image_Url; + private String profile_image_url; + private boolean isDefaultImage; + } + } diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index 7bf3e13..5893b64 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -35,4 +35,12 @@ public class User { private String role; + @Size(max = 45) + @Column(name = "nickname", length = 45) + private String nickname; + + @Size(max = 255) + @Column(name = "profile_image") + private String profileImage; + } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 20add15..5f7075a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,5 +1,6 @@ package modernfarmer.server.farmususer.user.service; + import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; @@ -9,7 +10,6 @@ import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -44,23 +44,18 @@ public TokenResponseDto googleLogin(String accessToken) { Mono<GoogleUserResponseDto> userInfoMono = getUserGoogleInfo(accessToken); GoogleUserResponseDto userInfo = userInfoMono.block(); -// LOGGER.info(String.valueOf(userInfo.getAccount_email())); -// LOGGER.info(String.valueOf(userInfo.getProfile_nickname())); -// LOGGER.info(String.valueOf(userInfo.getProfile_image())); - -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getEmail())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfileImageUrl())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); Optional<User> userData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + log.info(String.valueOf(userInfo.getEmail())); + log.info(String.valueOf(userInfo.getPicture())); + log.info(String.valueOf(userInfo.getId())); + if(userData.isEmpty()){ user = User.builder() .usernumber(String.valueOf(userInfo.getId())) .role("USER") -// .email(userInfo.getKakao_account().getEmail()) -// .nickname(userInfo.getKakao_account().getProfile().getNickname()) -// .userProfile(userInfo.getKakao_account().getProfile().getProfileImageUrl()) + .profileImage(userInfo.getPicture()) .build(); userRepository.save(user); @@ -80,8 +75,6 @@ public TokenResponseDto googleLogin(String accessToken) { .refreshToken(refreshToken) .build(); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"userId", String.valueOf(userLoginData.get().getId())); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"role", String.valueOf(userLoginData.get().getRole())); redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); @@ -95,13 +88,11 @@ public TokenResponseDto kakaoLogin(String accessToken) { Mono<KakaoUserResponseDto> userInfoMono = getUserKakaoInfo(accessToken); KakaoUserResponseDto userInfo = userInfoMono.block(); -// LOGGER.info(String.valueOf(userInfo.getAccount_email())); -// LOGGER.info(String.valueOf(userInfo.getProfile_nickname())); -// LOGGER.info(String.valueOf(userInfo.getProfile_image())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getEmail())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfileImageUrl())); -// LOGGER.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); + log.info(String.valueOf(userInfo.getKakao_account().getEmail())); + log.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfile_image_url())); + log.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); + Optional<User> userData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); @@ -109,9 +100,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { user = User.builder() .usernumber(String.valueOf(userInfo.getId())) .role("USER") -// .email(userInfo.getKakao_account().getEmail()) -// .nickname(userInfo.getKakao_account().getProfile().getNickname()) -// .userProfile(userInfo.getKakao_account().getProfile().getProfileImageUrl()) + .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) .build(); userRepository.save(user); @@ -131,8 +120,6 @@ public TokenResponseDto kakaoLogin(String accessToken) { .refreshToken(refreshToken) .build(); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"userId", String.valueOf(userLoginData.get().getId())); -// redisTemplate.opsForHash().put(jwtTokenProvider.createRereshToken(),"role", String.valueOf(userLoginData.get().getRole())); redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); @@ -140,7 +127,6 @@ public TokenResponseDto kakaoLogin(String accessToken) { return tokenResponseDto; } - public Mono<KakaoUserResponseDto> getUserKakaoInfo(String accessToken) { return webClient .get() From fee7553ac583646925e53a8c4b9e973936e95e30 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 29 Oct 2023 20:14:26 +0900 Subject: [PATCH 25/95] =?UTF-8?q?[fix]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=9C=20=EC=B4=88=EA=B8=B0=20=EC=9C=A0=EC=A0=80,=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=EC=9C=A0=EC=A0=80=20=EA=B5=AC=EB=B6=84=20?= =?UTF-8?q?boolean=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jpb/jpb-settings.xml | 10 ++++++++++ .../farmususer/user/dto/response/TokenResponseDto.java | 2 ++ .../server/farmususer/user/service/AuthService.java | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 .jpb/jpb-settings.xml diff --git a/.jpb/jpb-settings.xml b/.jpb/jpb-settings.xml new file mode 100644 index 0000000..484f362 --- /dev/null +++ b/.jpb/jpb-settings.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="JpaPluginProjectSettings"> + <option name="entityNameTemplate" /> + <option name="isLombokBuilder" value="true" /> + <option name="isLombokAllArgsConstructor" value="true" /> + <option name="isLombokNoArgsConstructor" value="true" /> + <option name="scaffoldingLanguage" /> + </component> +</project> \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java index e746e38..d992472 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java @@ -17,4 +17,6 @@ public class TokenResponseDto { private String accessToken; private String refreshToken; + + private boolean early; } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 5f7075a..1b73a5c 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -28,6 +28,7 @@ public class AuthService{ public UserRepository userRepository; private final WebClient webClient; + private boolean early = false; @Autowired public AuthService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate) { @@ -57,6 +58,7 @@ public TokenResponseDto googleLogin(String accessToken) { .role("USER") .profileImage(userInfo.getPicture()) .build(); + early = true; userRepository.save(user); } @@ -69,6 +71,7 @@ public TokenResponseDto googleLogin(String accessToken) { TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") .code(200) + .early(early) .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole()))) @@ -103,6 +106,8 @@ public TokenResponseDto kakaoLogin(String accessToken) { .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) .build(); + early = true; + userRepository.save(user); } @@ -114,6 +119,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { TokenResponseDto tokenResponseDto = TokenResponseDto.builder() .message("OK") .code(200) + .early(early) .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), String.valueOf(userLoginData.get().getRole()))) From da64130519bf375d009b98696f611f36305f88c6 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 29 Oct 2023 21:24:25 +0900 Subject: [PATCH 26/95] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EB=8B=89?= =?UTF-8?q?=EB=84=A4=EC=9E=84=20=EC=83=9D=EC=84=B1=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 21 +++++++++++++++---- .../dto/request/ProduceNicknameRequest.java | 14 +++++++++++++ .../user/repository/UserRepository.java | 3 +++ .../farmususer/user/service/UserService.java | 14 +++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/request/ProduceNicknameRequest.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 60eed70..f16e786 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -1,17 +1,16 @@ package modernfarmer.server.farmususer.user.controller; import lombok.RequiredArgsConstructor; +import lombok.Value; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.service.AuthService; import modernfarmer.server.farmususer.user.service.UserService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; @@ -25,6 +24,18 @@ public class UserController { private final JwtTokenProvider jwtTokenProvider; + + @PostMapping(value = "/nickname") + public ResponseDto produceNickname(HttpServletRequest request, ProduceNicknameRequest produceNicknameRequest){ + + String userId = jwtTokenProvider.getUserId(request); + + ResponseDto responseDto = userService.produceNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); + + return responseDto; + } + + @DeleteMapping("/logout") public ResponseDto logout(HttpServletRequest request) { @@ -50,4 +61,6 @@ public TokenResponseDto reissueToken(HttpServletRequest request) { return reissueTokenResponseDto; } + + } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/request/ProduceNicknameRequest.java b/src/main/java/modernfarmer/server/farmususer/user/dto/request/ProduceNicknameRequest.java new file mode 100644 index 0000000..a71b618 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/request/ProduceNicknameRequest.java @@ -0,0 +1,14 @@ +package modernfarmer.server.farmususer.user.dto.request; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class ProduceNicknameRequest { + + private String nickName; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index cacff0b..cc134bf 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -17,6 +17,9 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("SELECT a.role FROM User AS a WHERE a.id = :userId") String findUserRole(@Param("userId") Long userId); + @Query("update User as u set u = :nickName where u.id = :userId") + void updateUserNickname(@Param("nickName") String nickName, @Param("userId") Long userId); + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index b3cc99f..7e15a56 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -3,6 +3,7 @@ import modernfarmer.server.farmususer.global.exception.notfound.NotFoundRefreshTokenException; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; +import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +33,19 @@ public UserService(WebClient webClient, UserRepository userRepository, JwtTokenP } + public ResponseDto produceNickname(Long userId, String nickName){ + + userRepository.updateUserNickname(nickName, userId); + + ResponseDto responseDto = ResponseDto.builder() + .code(200) + .message("OK") + .build(); + + return responseDto; + } + + public ResponseDto logout(Long userId) { deleteValueByKey(String.valueOf(userId)); From e335fa0b1ef1bec66e17f1cdeba7610d4f46d0c6 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 29 Oct 2023 21:27:43 +0900 Subject: [PATCH 27/95] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EB=8B=89?= =?UTF-8?q?=EB=84=A4=EC=9E=84=20=EC=88=98=EC=A0=95=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/controller/UserController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index f16e786..6ebc5ab 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -35,6 +35,16 @@ public ResponseDto produceNickname(HttpServletRequest request, ProduceNicknameRe return responseDto; } + @PutMapping(value = "/nickname") + public ResponseDto updateNickname(HttpServletRequest request, ProduceNicknameRequest produceNicknameRequest){ + + String userId = jwtTokenProvider.getUserId(request); + + ResponseDto responseDto = userService.produceNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); + + return responseDto; + } + @DeleteMapping("/logout") public ResponseDto logout(HttpServletRequest request) { From 10473aee57b9709ddd2329d9aa67d441de2e7dc9 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 29 Oct 2023 21:36:49 +0900 Subject: [PATCH 28/95] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EB=B0=8F=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20put=20->=20patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/controller/UserController.java | 13 ++++++++++++- .../farmususer/user/repository/UserRepository.java | 3 +++ .../server/farmususer/user/service/UserService.java | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 6ebc5ab..6e421c9 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -24,6 +24,17 @@ public class UserController { private final JwtTokenProvider jwtTokenProvider; + @DeleteMapping(value = "/delete") + public ResponseDto deleteUser(HttpServletRequest request){ + + String userId = jwtTokenProvider.getUserId(request); + + ResponseDto responseDto = userService.deleteUser(Long.valueOf(userId)); + + return responseDto; + } + + @PostMapping(value = "/nickname") public ResponseDto produceNickname(HttpServletRequest request, ProduceNicknameRequest produceNicknameRequest){ @@ -35,7 +46,7 @@ public ResponseDto produceNickname(HttpServletRequest request, ProduceNicknameRe return responseDto; } - @PutMapping(value = "/nickname") + @PatchMapping(value = "/nickname") public ResponseDto updateNickname(HttpServletRequest request, ProduceNicknameRequest produceNicknameRequest){ String userId = jwtTokenProvider.getUserId(request); diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index cc134bf..b9072b4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -20,6 +20,9 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("update User as u set u = :nickName where u.id = :userId") void updateUserNickname(@Param("nickName") String nickName, @Param("userId") Long userId); + @Query("delete from User as u where u.id = : userId") + void deleteUser(@Param("userId") Long userId); + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 7e15a56..11c58e4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -32,6 +32,19 @@ public UserService(WebClient webClient, UserRepository userRepository, JwtTokenP this.redisTemplate = redisTemplate; } + public ResponseDto deleteUser(Long userId){ + + userRepository.deleteUser(userId); + + ResponseDto responseDto = ResponseDto + .builder() + .code(200) + .message("OK") + .build(); + + return responseDto; + } + public ResponseDto produceNickname(Long userId, String nickName){ From be6b4b1b7136f503d08888a18c4e0a3daa6127c9 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 29 Oct 2023 21:59:18 +0900 Subject: [PATCH 29/95] =?UTF-8?q?[feat]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=20=EB=9E=9C=EB=8D=94=EB=A7=81=20API,=20Respo?= =?UTF-8?q?nseDto=20=EC=83=81=EC=86=8D=EA=B5=AC=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 13 +++++++++++ .../dto/response/ProfileImageResponseDto.java | 14 +++++++++++ .../user/dto/response/ResponseDto.java | 1 - .../user/dto/response/TokenResponseDto.java | 9 +++----- .../user/repository/UserRepository.java | 3 +++ .../farmususer/user/service/UserService.java | 23 +++++++++++++++++++ 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 6e421c9..ec84c50 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -4,6 +4,7 @@ import lombok.Value; import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; +import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; @@ -24,6 +25,18 @@ public class UserController { private final JwtTokenProvider jwtTokenProvider; + + @GetMapping(value = "/profileImage") + public ProfileImageResponseDto selectProfileImage(HttpServletRequest request){ + + String userId = jwtTokenProvider.getUserId(request); + + ProfileImageResponseDto profileImageResponseDto = userService.selectProfileImage(Long.valueOf(userId)); + + return profileImageResponseDto; + } + + @DeleteMapping(value = "/delete") public ResponseDto deleteUser(HttpServletRequest request){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java new file mode 100644 index 0000000..1ae6158 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java @@ -0,0 +1,14 @@ +package modernfarmer.server.farmususer.user.dto.response; + + +import lombok.*; +import lombok.experimental.SuperBuilder; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@SuperBuilder +public class ProfileImageResponseDto extends ResponseDto{ + + private String profileImage; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java index 49a0746..c78237c 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java @@ -6,7 +6,6 @@ @NoArgsConstructor @AllArgsConstructor -@Data @SuperBuilder public class ResponseDto { private int code; diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java index d992472..beba6e7 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java @@ -2,17 +2,14 @@ import lombok.*; +import lombok.experimental.SuperBuilder; @NoArgsConstructor @AllArgsConstructor @ToString -@Builder +@SuperBuilder @Getter -public class TokenResponseDto { - - private int code; - - private String message; +public class TokenResponseDto extends ResponseDto{ private String accessToken; diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index b9072b4..5dec76e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -23,6 +23,9 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("delete from User as u where u.id = : userId") void deleteUser(@Param("userId") Long userId); + @Query("select u.profileImage from User as u where u.id = :userId") + String selectUserProfileImage(@Param("userId") Long userId); + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 11c58e4..88f3b8e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,6 +1,7 @@ package modernfarmer.server.farmususer.user.service; import modernfarmer.server.farmususer.global.exception.notfound.NotFoundRefreshTokenException; +import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.entity.User; @@ -32,6 +33,28 @@ public UserService(WebClient webClient, UserRepository userRepository, JwtTokenP this.redisTemplate = redisTemplate; } + public ProfileImageResponseDto selectProfileImage(Long userId){ + + String userProfileImage = userRepository.selectUserProfileImage(userId); + + + ProfileImageResponseDto profileImageResponseDto = ProfileImageResponseDto + .builder() + .code(200) + .message("OK") + .profileImage(userProfileImage) + .build(); + + + return profileImageResponseDto; + } + + + + + + + public ResponseDto deleteUser(Long userId){ userRepository.deleteUser(userId); From c533aea8f97d7e44fa48ebd259d492a7693ae95a Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 30 Oct 2023 02:12:33 +0900 Subject: [PATCH 30/95] =?UTF-8?q?[feat]=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=82=AC=EC=A7=84=20=EC=97=85=EB=A1=9C=EB=93=9C=20api=20?= =?UTF-8?q?=EB=AF=B8=EC=99=84=EC=84=B1,=20s3=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 + .../config/s3/AmazonS3ResourceStorage.java | 34 ++++++++++++++ .../global/config/s3/FileDetail.java | 34 ++++++++++++++ .../global/config/s3/MultipartUtil.java | 45 +++++++++++++++++++ .../farmususer/global/config/s3/S3Config.java | 28 ++++++++++++ .../user/controller/UserController.java | 16 +++++-- .../farmususer/user/service/UserService.java | 35 ++++++++++++--- 7 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Config.java diff --git a/build.gradle b/build.gradle index a8fb8ae..0fe7026 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,8 @@ dependencies { implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2' runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2' runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' + + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' } tasks.named('test') { diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java new file mode 100644 index 0000000..402cb8c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java @@ -0,0 +1,34 @@ +package modernfarmer.server.farmususer.global.config.s3; + +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.PutObjectRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; + +@Component +@RequiredArgsConstructor +public class AmazonS3ResourceStorage { + @Value("${cloud.aws.s3.bucket}") + private String bucket; + private final AmazonS3Client amazonS3Client; + + public void store(String fullPath, MultipartFile multipartFile) { + File file = new File(MultipartUtil.getLocalHomeDirectory(), fullPath); + try { + multipartFile.transferTo(file); + amazonS3Client.putObject(new PutObjectRequest(bucket, fullPath, file) + .withCannedAcl(CannedAccessControlList.PublicRead)); + } catch (Exception e) { + throw new RuntimeException(); + } finally { + if (file.exists()) { + file.delete(); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java new file mode 100644 index 0000000..f777dfd --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java @@ -0,0 +1,34 @@ +package modernfarmer.server.farmususer.global.config.s3; + +import lombok.*; +import org.springframework.web.multipart.MultipartFile; + +import java.time.LocalDateTime; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +public class FileDetail { + private String id; + private String name; + private String format; + private String path; + private long bytes; + + @Builder.Default + private LocalDateTime createdAt = LocalDateTime.now(); + + public static FileDetail multipartOf(MultipartFile multipartFile) { + final String fileId = MultipartUtil.createFileId(); + final String format = MultipartUtil.getFormat(multipartFile.getContentType()); + return FileDetail.builder() + .id(fileId) + .name(multipartFile.getOriginalFilename()) + .format(format) + .path(MultipartUtil.createPath(fileId, format)) + .bytes(multipartFile.getSize()) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java new file mode 100644 index 0000000..f60f54b --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java @@ -0,0 +1,45 @@ +package modernfarmer.server.farmususer.global.config.s3; + +import org.springframework.util.StringUtils; + +import java.util.UUID; + +public final class MultipartUtil { + private static final String BASE_DIR = "images"; + + /** + * 로컬에서의 사용자 홈 디렉토리 경로를 반환합니다. + */ + public static String getLocalHomeDirectory() { + return System.getProperty("user.home"); + } + + /** + * 새로운 파일 고유 ID를 생성합니다. + * @return 36자리의 UUID + */ + public static String createFileId() { + return UUID.randomUUID().toString(); + } + + /** + * Multipart 의 ContentType 값에서 / 이후 확장자만 잘라냅니다. + * @param contentType ex) image/png + * @return ex) png + */ + public static String getFormat(String contentType) { + if (StringUtils.hasText(contentType)) { + return contentType.substring(contentType.lastIndexOf('/') + 1); + } + return null; + } + + /** + * 파일의 전체 경로를 생성합니다. + * @param fileId 생성된 파일 고유 ID + * @param format 확장자 + */ + public static String createPath(String fileId, String format) { + return String.format("%s/%s.%s", BASE_DIR, fileId, format); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Config.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Config.java new file mode 100644 index 0000000..9d58626 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Config.java @@ -0,0 +1,28 @@ +package modernfarmer.server.farmususer.global.config.s3; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class S3Config { + @Value("${cloud.aws.credentials.access-key}") + private String accessKey; + @Value("${cloud.aws.credentials.secret-key}") + private String secretKey; + @Value("${cloud.aws.region.static}") + private String region; + + @Bean + public AmazonS3Client amazonS3Client() { + BasicAWSCredentials awsCredentials= new BasicAWSCredentials(accessKey, secretKey); + return (AmazonS3Client) AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index ec84c50..5d1abd6 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -1,17 +1,16 @@ package modernfarmer.server.farmususer.user.controller; import lombok.RequiredArgsConstructor; -import lombok.Value; import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; -import modernfarmer.server.farmususer.user.service.AuthService; import modernfarmer.server.farmususer.user.service.UserService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; @@ -24,7 +23,16 @@ public class UserController { private final UserService userService; private final JwtTokenProvider jwtTokenProvider; + @PostMapping(value = "/profileImage") + public ResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile){ + String userId = jwtTokenProvider.getUserId(request); + + ResponseDto responseDto = userService.produceProfileImage(Long.valueOf(userId), multipartFile); + + return responseDto; + + } @GetMapping(value = "/profileImage") public ProfileImageResponseDto selectProfileImage(HttpServletRequest request){ @@ -50,7 +58,7 @@ public ResponseDto deleteUser(HttpServletRequest request){ @PostMapping(value = "/nickname") - public ResponseDto produceNickname(HttpServletRequest request, ProduceNicknameRequest produceNicknameRequest){ + public ResponseDto produceNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ String userId = jwtTokenProvider.getUserId(request); @@ -60,7 +68,7 @@ public ResponseDto produceNickname(HttpServletRequest request, ProduceNicknameRe } @PatchMapping(value = "/nickname") - public ResponseDto updateNickname(HttpServletRequest request, ProduceNicknameRequest produceNicknameRequest){ + public ResponseDto updateNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ String userId = jwtTokenProvider.getUserId(request); diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 88f3b8e..7a31e47 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,36 +1,57 @@ package modernfarmer.server.farmususer.user.service; +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.config.s3.AmazonS3ResourceStorage; +import modernfarmer.server.farmususer.global.config.s3.FileDetail; import modernfarmer.server.farmususer.global.exception.notfound.NotFoundRefreshTokenException; import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; -import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.reactive.function.client.WebClient; -import java.util.Objects; - +@Slf4j @Service public class UserService { public JwtTokenProvider jwtTokenProvider; public RedisTemplate<String, String> redisTemplate; - public UserRepository userRepository; + private final AmazonS3ResourceStorage amazonS3ResourceStorage; - private final WebClient webClient; @Autowired - public UserService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate) { - this.webClient = webClient; + public UserService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate, AmazonS3ResourceStorage amazonS3ResourceStoraget) { + this.userRepository = userRepository; this.jwtTokenProvider = jwtTokenProvider; this.redisTemplate = redisTemplate; + this.amazonS3ResourceStorage = amazonS3ResourceStoraget; + } + + public ResponseDto produceProfileImage(Long userId, MultipartFile multipartFile){ + + + FileDetail fileDetail = FileDetail.multipartOf(multipartFile); + amazonS3ResourceStorage.store(fileDetail.getPath(), multipartFile); + + log.info(String.valueOf(fileDetail)); + + + ResponseDto responseDto = ResponseDto + .builder() + .code(200) + .message("OK") + .build(); + + return responseDto; } public ProfileImageResponseDto selectProfileImage(Long userId){ From cc0d0938649d1ddf75dc266820d188dee85fee17 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 30 Oct 2023 02:18:49 +0900 Subject: [PATCH 31/95] =?UTF-8?q?[fix]=20ci/cd=20=EC=9E=AC=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modernfarmer/server/farmususer/user/service/UserService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 7a31e47..8043a44 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -26,7 +26,6 @@ public class UserService { public UserRepository userRepository; private final AmazonS3ResourceStorage amazonS3ResourceStorage; - @Autowired public UserService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate, AmazonS3ResourceStorage amazonS3ResourceStoraget) { From e86eb104f2109f8d925ec8420b90090efb4c5467 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 30 Oct 2023 02:44:44 +0900 Subject: [PATCH 32/95] =?UTF-8?q?[fix]=20ci/cd=20=EC=9E=AC=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index e1c3968..9f0778b 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_13/카카오,-구글-로그인-수정"] + branches: ["feature_14/-유저-관련-API-구현"] pull_request: branches: ["dev"] From 66518d85379c441434a061b9a61f2fed1e83a97d Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 30 Oct 2023 02:52:16 +0900 Subject: [PATCH 33/95] =?UTF-8?q?[fix]=20ci/cd=20=EC=9E=AC=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modernfarmer/server/farmususer/user/service/UserService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 8043a44..0def733 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -35,6 +35,7 @@ public UserService(WebClient webClient, UserRepository userRepository, JwtTokenP this.amazonS3ResourceStorage = amazonS3ResourceStoraget; } + public ResponseDto produceProfileImage(Long userId, MultipartFile multipartFile){ From 32546c0a4faaae2a6c583b70daad0dae9ad66047 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 30 Oct 2023 14:45:23 +0900 Subject: [PATCH 34/95] =?UTF-8?q?[fix]=20form-data=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/controller/UserController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 5d1abd6..c24faee 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -9,6 +9,7 @@ import modernfarmer.server.farmususer.user.service.UserService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -23,7 +24,7 @@ public class UserController { private final UserService userService; private final JwtTokenProvider jwtTokenProvider; - @PostMapping(value = "/profileImage") + @PostMapping(value = "/profileImage", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile){ String userId = jwtTokenProvider.getUserId(request); From 9066ea365a775ff9ec71629ddf63fe9a2fd2f4d9 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 30 Oct 2023 16:44:36 +0900 Subject: [PATCH 35/95] =?UTF-8?q?[feat]=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20API=20=EB=B0=8F=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20early=20=EB=B3=80=EC=88=98=20=EC=9C=84?= =?UTF-8?q?=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/s3/AmazonS3ResourceStorage.java | 34 ---------- .../global/config/s3/FileDetail.java | 34 ---------- .../global/config/s3/MultipartUtil.java | 45 ------------ .../global/config/s3/S3Uploader.java | 68 +++++++++++++++++++ .../user/controller/UserController.java | 24 +++---- .../user/dto/response/ResponseDto.java | 1 + .../user/repository/UserRepository.java | 13 ++-- .../farmususer/user/service/AuthService.java | 4 +- .../farmususer/user/service/UserService.java | 40 ++++++----- 9 files changed, 107 insertions(+), 156 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Uploader.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java deleted file mode 100644 index 402cb8c..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/config/s3/AmazonS3ResourceStorage.java +++ /dev/null @@ -1,34 +0,0 @@ -package modernfarmer.server.farmususer.global.config.s3; - -import com.amazonaws.services.s3.AmazonS3Client; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import com.amazonaws.services.s3.model.PutObjectRequest; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; - -@Component -@RequiredArgsConstructor -public class AmazonS3ResourceStorage { - @Value("${cloud.aws.s3.bucket}") - private String bucket; - private final AmazonS3Client amazonS3Client; - - public void store(String fullPath, MultipartFile multipartFile) { - File file = new File(MultipartUtil.getLocalHomeDirectory(), fullPath); - try { - multipartFile.transferTo(file); - amazonS3Client.putObject(new PutObjectRequest(bucket, fullPath, file) - .withCannedAcl(CannedAccessControlList.PublicRead)); - } catch (Exception e) { - throw new RuntimeException(); - } finally { - if (file.exists()) { - file.delete(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java deleted file mode 100644 index f777dfd..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/config/s3/FileDetail.java +++ /dev/null @@ -1,34 +0,0 @@ -package modernfarmer.server.farmususer.global.config.s3; - -import lombok.*; -import org.springframework.web.multipart.MultipartFile; - -import java.time.LocalDateTime; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor(access = AccessLevel.PROTECTED) -@Builder -public class FileDetail { - private String id; - private String name; - private String format; - private String path; - private long bytes; - - @Builder.Default - private LocalDateTime createdAt = LocalDateTime.now(); - - public static FileDetail multipartOf(MultipartFile multipartFile) { - final String fileId = MultipartUtil.createFileId(); - final String format = MultipartUtil.getFormat(multipartFile.getContentType()); - return FileDetail.builder() - .id(fileId) - .name(multipartFile.getOriginalFilename()) - .format(format) - .path(MultipartUtil.createPath(fileId, format)) - .bytes(multipartFile.getSize()) - .build(); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java deleted file mode 100644 index f60f54b..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/config/s3/MultipartUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -package modernfarmer.server.farmususer.global.config.s3; - -import org.springframework.util.StringUtils; - -import java.util.UUID; - -public final class MultipartUtil { - private static final String BASE_DIR = "images"; - - /** - * 로컬에서의 사용자 홈 디렉토리 경로를 반환합니다. - */ - public static String getLocalHomeDirectory() { - return System.getProperty("user.home"); - } - - /** - * 새로운 파일 고유 ID를 생성합니다. - * @return 36자리의 UUID - */ - public static String createFileId() { - return UUID.randomUUID().toString(); - } - - /** - * Multipart 의 ContentType 값에서 / 이후 확장자만 잘라냅니다. - * @param contentType ex) image/png - * @return ex) png - */ - public static String getFormat(String contentType) { - if (StringUtils.hasText(contentType)) { - return contentType.substring(contentType.lastIndexOf('/') + 1); - } - return null; - } - - /** - * 파일의 전체 경로를 생성합니다. - * @param fileId 생성된 파일 고유 ID - * @param format 확장자 - */ - public static String createPath(String fileId, String format) { - return String.format("%s/%s.%s", BASE_DIR, fileId, format); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Uploader.java b/src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Uploader.java new file mode 100644 index 0000000..f020922 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/config/s3/S3Uploader.java @@ -0,0 +1,68 @@ +package modernfarmer.server.farmususer.global.config.s3; + +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.PutObjectRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Optional; +import java.util.UUID; + +@Slf4j +@Component +public class S3Uploader { + private final AmazonS3Client amazonS3Client; + + @Value("${cloud.aws.s3.bucket}") + private String bucket; + + public S3Uploader(AmazonS3Client amazonS3Client) { + this.amazonS3Client = amazonS3Client; + } + + public String uploadFiles( + MultipartFile multipartFile, String dirName) throws IOException { + File uploadFile = convert(multipartFile).orElseThrow(() -> + new IllegalArgumentException("error: MultipartFile -> File convert fail")); + return upload(uploadFile, dirName); + } + + public String upload(File uploadFile, String filePath) { + String fileName = filePath + "/" + UUID.randomUUID() + uploadFile.getName(); + String uploadImageUrl = putS3(uploadFile, fileName); + removeNewFile(uploadFile); + return uploadImageUrl; + } + + private String putS3(File uploadFile, String fileName) { + amazonS3Client.putObject( + new PutObjectRequest(bucket, fileName, uploadFile) + .withCannedAcl(CannedAccessControlList.PublicRead)); + return amazonS3Client.getUrl(bucket, fileName).toString(); + } + + private void removeNewFile(File targetFile) { + if (targetFile.delete()) { + System.out.println("File delete success"); + return; + } + System.out.println("File delete fail"); + } + + private Optional<File> convert(MultipartFile file) throws IOException { + File convertFile = new File(System.getProperty("user.dir") + "/" + file.getOriginalFilename()); + if (convertFile.createNewFile()) { + try (FileOutputStream fileOutputStream = new FileOutputStream(convertFile)) { + fileOutputStream.write(file.getBytes()); + } + return Optional.of(convertFile); + } + return Optional.empty(); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index c24faee..f5587cf 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -14,6 +14,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; +import java.io.IOException; @Slf4j @RestController @@ -24,12 +25,12 @@ public class UserController { private final UserService userService; private final JwtTokenProvider jwtTokenProvider; - @PostMapping(value = "/profileImage", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) - public ResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile){ + @PostMapping(value = "/profileImage", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile) throws IOException { String userId = jwtTokenProvider.getUserId(request); - - ResponseDto responseDto = userService.produceProfileImage(Long.valueOf(userId), multipartFile); + log.info(userId); + ResponseDto responseDto = userService.emitProfileImage(Long.valueOf(userId), multipartFile); return responseDto; @@ -40,6 +41,7 @@ public ProfileImageResponseDto selectProfileImage(HttpServletRequest request){ String userId = jwtTokenProvider.getUserId(request); + ProfileImageResponseDto profileImageResponseDto = userService.selectProfileImage(Long.valueOf(userId)); return profileImageResponseDto; @@ -59,21 +61,11 @@ public ResponseDto deleteUser(HttpServletRequest request){ @PostMapping(value = "/nickname") - public ResponseDto produceNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ - - String userId = jwtTokenProvider.getUserId(request); - - ResponseDto responseDto = userService.produceNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); - - return responseDto; - } - - @PatchMapping(value = "/nickname") - public ResponseDto updateNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ + public ResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ String userId = jwtTokenProvider.getUserId(request); - ResponseDto responseDto = userService.produceNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); + ResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); return responseDto; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java index c78237c..d4169cb 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java @@ -7,6 +7,7 @@ @NoArgsConstructor @AllArgsConstructor @SuperBuilder +@Getter public class ResponseDto { private int code; private String message; diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 5dec76e..33c6fc2 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -3,6 +3,7 @@ import io.lettuce.core.dynamic.annotation.Param; import modernfarmer.server.farmususer.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -11,20 +12,22 @@ @Repository public interface UserRepository extends JpaRepository<User, Long> { - - Optional<User> findByUsernumber(String usernumber); @Query("SELECT a.role FROM User AS a WHERE a.id = :userId") String findUserRole(@Param("userId") Long userId); - @Query("update User as u set u = :nickName where u.id = :userId") + @Modifying + @Query("update User as u set u.nickname = :nickName where u.id = :userId") void updateUserNickname(@Param("nickName") String nickName, @Param("userId") Long userId); - - @Query("delete from User as u where u.id = : userId") + @Modifying + @Query("delete from User as u where u.id = :userId") void deleteUser(@Param("userId") Long userId); @Query("select u.profileImage from User as u where u.id = :userId") String selectUserProfileImage(@Param("userId") Long userId); + @Modifying + @Query("update User as u set u.profileImage = :profileImage where u.id = :userId") + void emitUserProfileImage(@Param("userId") Long userId, @Param("profileImage") String profileImage); diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 1b73a5c..9978c2a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -28,7 +28,7 @@ public class AuthService{ public UserRepository userRepository; private final WebClient webClient; - private boolean early = false; + @Autowired public AuthService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate) { @@ -41,6 +41,7 @@ public AuthService(WebClient webClient, UserRepository userRepository, JwtTokenP public TokenResponseDto googleLogin(String accessToken) { User user; + boolean early = false; Mono<GoogleUserResponseDto> userInfoMono = getUserGoogleInfo(accessToken); GoogleUserResponseDto userInfo = userInfoMono.block(); @@ -88,6 +89,7 @@ public TokenResponseDto googleLogin(String accessToken) { public TokenResponseDto kakaoLogin(String accessToken) { User user; + boolean early = false; Mono<KakaoUserResponseDto> userInfoMono = getUserKakaoInfo(accessToken); KakaoUserResponseDto userInfo = userInfoMono.block(); diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 0def733..6cec29c 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,8 +1,7 @@ package modernfarmer.server.farmususer.user.service; import lombok.extern.slf4j.Slf4j; -import modernfarmer.server.farmususer.global.config.s3.AmazonS3ResourceStorage; -import modernfarmer.server.farmususer.global.config.s3.FileDetail; +import modernfarmer.server.farmususer.global.config.s3.S3Uploader; import modernfarmer.server.farmususer.global.exception.notfound.NotFoundRefreshTokenException; import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; @@ -10,12 +9,14 @@ import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.reactive.function.client.WebClient; +import java.io.IOException; + @Slf4j @Service @@ -24,26 +25,27 @@ public class UserService { public JwtTokenProvider jwtTokenProvider; public RedisTemplate<String, String> redisTemplate; public UserRepository userRepository; - private final AmazonS3ResourceStorage amazonS3ResourceStorage; + public final S3Uploader s3Uploader; + @Autowired - public UserService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate, AmazonS3ResourceStorage amazonS3ResourceStoraget) { + public UserService(UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate, + S3Uploader s3Uploader + ) { this.userRepository = userRepository; this.jwtTokenProvider = jwtTokenProvider; this.redisTemplate = redisTemplate; - this.amazonS3ResourceStorage = amazonS3ResourceStoraget; - } - + this.s3Uploader = s3Uploader; - public ResponseDto produceProfileImage(Long userId, MultipartFile multipartFile){ - - - FileDetail fileDetail = FileDetail.multipartOf(multipartFile); - amazonS3ResourceStorage.store(fileDetail.getPath(), multipartFile); + } + @Transactional + public ResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { - log.info(String.valueOf(fileDetail)); + String imageUrl = s3Uploader.uploadFiles(multipartFile, "userprofileimage"); + log.info(imageUrl); + userRepository.emitUserProfileImage(userId, imageUrl); ResponseDto responseDto = ResponseDto .builder() @@ -70,12 +72,7 @@ public ProfileImageResponseDto selectProfileImage(Long userId){ return profileImageResponseDto; } - - - - - - + @Transactional public ResponseDto deleteUser(Long userId){ userRepository.deleteUser(userId); @@ -90,7 +87,8 @@ public ResponseDto deleteUser(Long userId){ } - public ResponseDto produceNickname(Long userId, String nickName){ + @Transactional + public ResponseDto emitNickname(Long userId, String nickName){ userRepository.updateUserNickname(nickName, userId); From a066a36b7b45d1b1121268bd845af9d2a6980160 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Wed, 1 Nov 2023 22:10:31 +0900 Subject: [PATCH 36/95] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20db,=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/FarmusUserApplication.java | 3 ++ .../farmususer/user/entity/BaseEntity.java | 24 ++++++++++ .../server/farmususer/user/entity/User.java | 44 ++++++++++++++----- .../user/entity/UserFirebaseToken.java | 37 ++++++++++++++++ .../user/repository/UserRepository.java | 4 +- .../farmususer/user/service/AuthService.java | 20 ++++----- 6 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java diff --git a/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java b/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java index ecfda07..29944ad 100644 --- a/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java +++ b/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java @@ -2,7 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@EnableJpaAuditing @SpringBootApplication public class FarmusUserApplication { diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java b/src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java new file mode 100644 index 0000000..f3fa8b1 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java @@ -0,0 +1,24 @@ +package modernfarmer.server.farmususer.user.entity; + +import lombok.Data; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import java.time.LocalDateTime; + +@Data +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class BaseEntity { + + @CreatedDate + @Column + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updateAt; +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index 5893b64..d87f53f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -6,6 +6,9 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import java.time.Instant; +import java.util.LinkedHashSet; +import java.util.Set; @Getter @Setter @@ -14,7 +17,7 @@ @NoArgsConstructor @AllArgsConstructor @Table(name = "users") -public class User { +public class User extends BaseEntity{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id", nullable = false) @@ -24,17 +27,6 @@ public class User { @Column(name = "username", length = 45) private String username; - @Size(max = 45) - @NotNull - @Column(name = "usernumber", nullable = false, length = 45) - private String usernumber; - - @Size(max = 45) - @NotNull - @Column(name = "role", nullable = false, length = 45) - private String role; - - @Size(max = 45) @Column(name = "nickname", length = 45) private String nickname; @@ -43,4 +35,32 @@ public class User { @Column(name = "profile_image") private String profileImage; + @Size(max = 6) + @NotNull + @Column(name = "roles", nullable = false, length = 6) + private String roles; + + @Size(max = 30) + @NotNull + @Column(name = "user_number", nullable = false, length = 30) + private String userNumber; + + @Size(max = 100) + @Column(name = "firebase_token", length = 100) + private String firebaseToken; + + @Size(max = 40) + @Column(name = "motivation", length = 40) + private String motivation; + + @Size(max = 10) + @Column(name = "level", length = 10) + private String level; + + + @OneToMany(mappedBy = "user") + private Set<UserFirebaseToken> userFirebaseTokens = new LinkedHashSet<>(); + + + } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java new file mode 100644 index 0000000..5c97fb4 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java @@ -0,0 +1,37 @@ +package modernfarmer.server.farmususer.user.entity; + +import lombok.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.time.Instant; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +@Entity +@Table(name = "user_firebase_token") +public class UserFirebaseToken extends BaseEntity{ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "firebase_token_id", nullable = false) + private Integer id; + + @Size(max = 100) + @NotNull + @Column(name = "token", nullable = false, length = 100) + private String token; + + @NotNull + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 33c6fc2..6bbbf0d 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -12,8 +12,8 @@ @Repository public interface UserRepository extends JpaRepository<User, Long> { - Optional<User> findByUsernumber(String usernumber); - @Query("SELECT a.role FROM User AS a WHERE a.id = :userId") + Optional<User> findByUserNumber(String usernumber); + @Query("SELECT a.roles FROM User AS a WHERE a.id = :userId") String findUserRole(@Param("userId") Long userId); @Modifying diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 9978c2a..c465e16 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -47,7 +47,7 @@ public TokenResponseDto googleLogin(String accessToken) { GoogleUserResponseDto userInfo = userInfoMono.block(); - Optional<User> userData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); log.info(String.valueOf(userInfo.getEmail())); log.info(String.valueOf(userInfo.getPicture())); @@ -55,8 +55,8 @@ public TokenResponseDto googleLogin(String accessToken) { if(userData.isEmpty()){ user = User.builder() - .usernumber(String.valueOf(userInfo.getId())) - .role("USER") + .userNumber(String.valueOf(userInfo.getId())) + .roles("USER") .profileImage(userInfo.getPicture()) .build(); early = true; @@ -64,7 +64,7 @@ public TokenResponseDto googleLogin(String accessToken) { userRepository.save(user); } - Optional<User> userLoginData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + Optional<User> userLoginData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); @@ -75,7 +75,7 @@ public TokenResponseDto googleLogin(String accessToken) { .early(early) .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), - String.valueOf(userLoginData.get().getRole()))) + String.valueOf(userLoginData.get().getRoles()))) .refreshToken(refreshToken) .build(); @@ -99,12 +99,12 @@ public TokenResponseDto kakaoLogin(String accessToken) { log.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); - Optional<User> userData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); if(userData.isEmpty()){ user = User.builder() - .usernumber(String.valueOf(userInfo.getId())) - .role("USER") + .userNumber(String.valueOf(userInfo.getId())) + .roles("USER") .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) .build(); @@ -113,7 +113,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { userRepository.save(user); } - Optional<User> userLoginData = userRepository.findByUsernumber(String.valueOf(userInfo.getId())); + Optional<User> userLoginData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); @@ -124,7 +124,7 @@ public TokenResponseDto kakaoLogin(String accessToken) { .early(early) .accessToken(jwtTokenProvider.createAccessToken( userLoginData.get().getId(), - String.valueOf(userLoginData.get().getRole()))) + String.valueOf(userLoginData.get().getRoles()))) .refreshToken(refreshToken) .build(); From 5e6b3b46de94ed5191d6a95705457d3c50982046 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Wed, 1 Nov 2023 22:11:27 +0900 Subject: [PATCH 37/95] =?UTF-8?q?[feat]=20=EC=9D=B4=EC=A0=84=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B=20ci/cd=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 9f0778b..02c35f8 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_14/-유저-관련-API-구현"] + branches: ["feature_17/유저-db적용-및-온보딩-구현"] pull_request: branches: ["dev"] From 55d6884612ef9acae217e66657e7d040bf0400aa Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 2 Nov 2023 03:35:39 +0900 Subject: [PATCH 38/95] =?UTF-8?q?[feat]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EB=8F=99=EA=B8=B0=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/OnBoardingController.java | 40 +++++++++++++++++++ .../request/OnBoardingMotivationRequest.java | 17 ++++++++ .../user/repository/UserRepository.java | 7 ++++ .../user/service/OnBoardingService.java | 36 +++++++++++++++++ .../farmususer/user/service/UserService.java | 7 ++-- 5 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java new file mode 100644 index 0000000..3c65d7f --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -0,0 +1,40 @@ +package modernfarmer.server.farmususer.user.controller; + + +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; +import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import modernfarmer.server.farmususer.user.service.OnBoardingService; +import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; + +@Slf4j +@RestController +@RequestMapping("/api/user") +public class OnBoardingController { + + private final JwtTokenProvider jwtTokenProvider; + private final OnBoardingService onBoardingService; + + @Autowired + public OnBoardingController( JwtTokenProvider jwtTokenProvider,OnBoardingService onBoardingService){ + this.jwtTokenProvider = jwtTokenProvider; + this.onBoardingService = onBoardingService; + } + + @PostMapping(value = "/motivation") + public ResponseDto onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) { + + String userId = jwtTokenProvider.getUserId(request); + + ResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId), onBoardingMotivationRequest.getMotivation()); + + return responseDto; + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java new file mode 100644 index 0000000..34796c5 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java @@ -0,0 +1,17 @@ +package modernfarmer.server.farmususer.user.dto.request; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import javax.validation.constraints.NotNull; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class OnBoardingMotivationRequest { + + + @NotNull(message = "null 값을 가지면 안됩니다.") + private String motivation; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 6bbbf0d..c4a8f87 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -30,6 +30,13 @@ public interface UserRepository extends JpaRepository<User, Long> { void emitUserProfileImage(@Param("userId") Long userId, @Param("profileImage") String profileImage); + @Modifying + @Query("update User as u set u.motivation= :motivation where u.id = :userId") + void insertUserMotivation(@Param("userId") Long userId, @Param("motivation") String motivation); + + + + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java new file mode 100644 index 0000000..7a9278c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -0,0 +1,36 @@ +package modernfarmer.server.farmususer.user.service; + + +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import modernfarmer.server.farmususer.user.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +import javax.transaction.Transactional; + +@Transactional +@Slf4j +@Service +public class OnBoardingService { + public UserRepository userRepository; + + @Autowired + public OnBoardingService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + public ResponseDto onBoardingMotivation(Long userId, String motivation){ + + userRepository.insertUserMotivation(userId, motivation); + + ResponseDto responseDto = ResponseDto.builder() + .message("OK") + .code(200) + .build(); + + return responseDto; + } + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 6cec29c..32d1407 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -18,6 +18,7 @@ import java.io.IOException; +@Transactional @Slf4j @Service public class UserService { @@ -39,7 +40,7 @@ public UserService(UserRepository userRepository, JwtTokenProvider jwtTokenProvi this.s3Uploader = s3Uploader; } - @Transactional + public ResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { String imageUrl = s3Uploader.uploadFiles(multipartFile, "userprofileimage"); @@ -72,7 +73,7 @@ public ProfileImageResponseDto selectProfileImage(Long userId){ return profileImageResponseDto; } - @Transactional + public ResponseDto deleteUser(Long userId){ userRepository.deleteUser(userId); @@ -87,7 +88,7 @@ public ResponseDto deleteUser(Long userId){ } - @Transactional + public ResponseDto emitNickname(Long userId, String nickName){ userRepository.updateUserNickname(nickName, userId); From e6c50210089059b1a5314d9bce0991142833bd50 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 2 Nov 2023 17:07:47 +0900 Subject: [PATCH 39/95] =?UTF-8?q?[fix]=20BaseResponse=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/fail/ErrorMessage.java | 35 ++++++++++++++ .../exception/success/SuccessMessage.java | 22 +++++++++ .../user/controller/OnBoardingController.java | 5 +- .../user/dto/response/BaseResponseDto.java | 46 +++++++++++++++++++ .../user/dto/response/ResponseDto.java | 2 +- .../user/service/OnBoardingService.java | 16 ++++--- 6 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java new file mode 100644 index 0000000..1dfa6b0 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java @@ -0,0 +1,35 @@ +package modernfarmer.server.farmususer.global.exception.fail; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.*; + +@Getter +public enum ErrorMessage { + + SUCCESS(OK, true, "요청에 성공하였습니다."), + INTERVAL_SERVER_ERROR(INTERNAL_SERVER_ERROR, false, "요청을 처리하는 과정에서 서버가 예상하지 못한 오류가 발생하였습니다."), + USER_NOT_FOUND(NOT_FOUND, false, "해당 회원을 찾을 수 없습니다."), + CATEGORY_NOT_FOUND(NOT_FOUND, false, "해당 회원의 카테고리를 찾을 수 없습니다."), + WRONG_PASSWORD(NOT_FOUND, false, "비밀번호가 맞지 않습니다."), + WRONG_POST(NOT_FOUND, false, "해당 포스트를 찾을 수 없습니다."), + FOLLOW_NOT_FOUND(NOT_FOUND, false, "팔로잉을 찾을 수 없습니다."), + COMMENT_NOT_FOUND(NOT_FOUND, false, "댓글을 찾을 수 없습니다"), + INVALID_FILE_UPLOAD(BAD_REQUEST, false, "파일 업로드에 실패하였습니다."), + INVALID_FORMAT(BAD_REQUEST, false, "형식에 맞지 않습니다."), + POST_NOT_FOUND(NOT_FOUND, false, "포스트를 찾을 수 없습니다."), + ALREADY_SIGNUPED_EMAIL_USER(BAD_REQUEST, false, "이미 회원가입한 유저입니다."), + TOKEN_ERROR(UNAUTHORIZED, false, "잘못된 토큰 정보입니다."); + + + private final int code; + private final boolean isSuccess; + private final String message; + + ErrorMessage(HttpStatus code, boolean isSuccess, String message) { + this.code = code.value(); + this.isSuccess = isSuccess; + this.message = message; + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java new file mode 100644 index 0000000..839ac4a --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java @@ -0,0 +1,22 @@ +package modernfarmer.server.farmususer.global.exception.success; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +import static org.springframework.http.HttpStatus.OK; + +@Getter +public enum SuccessMessage { + SUCCESS(OK, true, "요청에 성공하였습니다."); + + private final int code; + private final boolean isSuccess; + private final String message; + + SuccessMessage(HttpStatus code, boolean isSuccess, String message) { + this.code = code.value(); + this.isSuccess = isSuccess; + this.message = message; + } + +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java index 3c65d7f..fa9dac1 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -3,6 +3,7 @@ import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.service.OnBoardingService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; @@ -29,11 +30,11 @@ public OnBoardingController( JwtTokenProvider jwtTokenProvider,OnBoardingService } @PostMapping(value = "/motivation") - public ResponseDto onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) { + public BaseResponseDto onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) { String userId = jwtTokenProvider.getUserId(request); - ResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId), onBoardingMotivationRequest.getMotivation()); + BaseResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId), onBoardingMotivationRequest.getMotivation()); return responseDto; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java new file mode 100644 index 0000000..e59121a --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java @@ -0,0 +1,46 @@ +package modernfarmer.server.farmususer.user.dto.response; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.Getter; +import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; +import org.springframework.http.HttpStatus; + +import static modernfarmer.server.farmususer.global.exception.success.SuccessMessage.SUCCESS; + + + + +@Getter +@JsonPropertyOrder({"code", "isSuccess", "message", "result"}) +public class BaseResponseDto<T> { + private final int code; + @JsonProperty("isSuccess") + private final Boolean isSuccess; + private final String message; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private T result; + + // 요청에 성공한 경우 + public BaseResponseDto(T result) { + this.code = HttpStatus.OK.value(); + this.isSuccess = SUCCESS.isSuccess(); + this.message = SUCCESS.getMessage(); + this.result = result; + } + + public BaseResponseDto(ErrorMessage errorMessage) { + this.code = errorMessage.getCode(); + this.isSuccess = errorMessage.isSuccess(); + this.message = errorMessage.getMessage(); + } + + public BaseResponseDto(int code, Boolean isSuccess, String errorMessage) { + this.code = code; + this.isSuccess = isSuccess; + this.message = errorMessage; + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java index d4169cb..418f3af 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java @@ -5,7 +5,7 @@ import lombok.experimental.SuperBuilder; @NoArgsConstructor -@AllArgsConstructor +@AllArgsConstructor(staticName = "of") @SuperBuilder @Getter public class ResponseDto { diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index 7a9278c..a963877 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -2,6 +2,8 @@ import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -21,16 +23,18 @@ public OnBoardingService(UserRepository userRepository) { this.userRepository = userRepository; } - public ResponseDto onBoardingMotivation(Long userId, String motivation){ + public BaseResponseDto onBoardingMotivation(Long userId, String motivation){ userRepository.insertUserMotivation(userId, motivation); - ResponseDto responseDto = ResponseDto.builder() - .message("OK") - .code(200) - .build(); +// ResponseDto responseDto = ResponseDto.builder() +// .message("OK") +// .code(200) +// .build(); - return responseDto; + return new BaseResponseDto<>(SuccessMessage.SUCCESS); + + // return responseDto; } } From dc83598091b670080918296a07894ea91922b8d1 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 2 Nov 2023 17:43:51 +0900 Subject: [PATCH 40/95] =?UTF-8?q?[fix]=20BaseResponse=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20isSuccess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/success/SuccessMessage.java | 8 ++++---- .../user/dto/response/BaseResponseDto.java | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java index 839ac4a..b187969 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java @@ -7,15 +7,15 @@ @Getter public enum SuccessMessage { - SUCCESS(OK, true, "요청에 성공하였습니다."); + SUCCESS(OK, "요청에 성공하였습니다."); private final int code; - private final boolean isSuccess; + // private final boolean isSuccess; private final String message; - SuccessMessage(HttpStatus code, boolean isSuccess, String message) { + SuccessMessage(HttpStatus code, String message) { this.code = code.value(); - this.isSuccess = isSuccess; + // this.isSuccess = isSuccess; this.message = message; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java index e59121a..5cef503 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java @@ -14,11 +14,11 @@ @Getter -@JsonPropertyOrder({"code", "isSuccess", "message", "result"}) +@JsonPropertyOrder({"code", "message", "result"}) public class BaseResponseDto<T> { private final int code; - @JsonProperty("isSuccess") - private final Boolean isSuccess; + // @JsonProperty("isSuccess") + // private final Boolean isSuccess; private final String message; @JsonInclude(JsonInclude.Include.NON_NULL) @@ -27,20 +27,24 @@ public class BaseResponseDto<T> { // 요청에 성공한 경우 public BaseResponseDto(T result) { this.code = HttpStatus.OK.value(); - this.isSuccess = SUCCESS.isSuccess(); + // this.isSuccess = SUCCESS.isSuccess(); this.message = SUCCESS.getMessage(); this.result = result; } public BaseResponseDto(ErrorMessage errorMessage) { this.code = errorMessage.getCode(); - this.isSuccess = errorMessage.isSuccess(); + // this.isSuccess = errorMessage.isSuccess(); this.message = errorMessage.getMessage(); } public BaseResponseDto(int code, Boolean isSuccess, String errorMessage) { this.code = code; - this.isSuccess = isSuccess; + // this.isSuccess = isSuccess; this.message = errorMessage; } + + public static <T> BaseResponseDto of(T result){ + return new BaseResponseDto(result); + } } \ No newline at end of file From 36cc4990fc550dbf1d871ca2f7a202af30733a2c Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 3 Nov 2023 16:46:19 +0900 Subject: [PATCH 41/95] =?UTF-8?q?[fix]=20=EB=B9=84=EB=8B=88=EC=A7=80?= =?UTF-8?q?=EC=8A=A4=20=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC,=20=EC=8B=9C?= =?UTF-8?q?=EC=8A=A4=ED=85=9C=20=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 12 ++ .../farmususer/FarmusUserApplication.java | 3 +- .../exception/CustomExceptionContext.java | 21 ---- .../global/exception/ErrorResponse.java | 3 +- .../global/exception/ExceptionContext.java | 11 -- .../exception/GlobalExceptionHandler.java | 53 +++++++-- .../exception/ModernFarmerException.java | 19 ---- .../badrequest/BadRequestException.java | 13 --- .../badrequest/FirebaseConfigException.java | 10 -- .../global/exception/fail/ErrorMessage.java | 22 +--- .../exception/notfound/NotFoundException.java | 16 --- .../notfound/NotFoundMedicineException.java | 12 -- .../NotFoundRefreshTokenException.java | 10 -- .../exception/success/SuccessMessage.java | 11 +- .../user/controller/AuthController.java | 18 ++- .../user/controller/OnBoardingController.java | 8 +- .../user/controller/UserController.java | 27 ++--- .../user/dto/response/BaseResponseDto.java | 40 +++---- .../dto/response/ProfileImageResponseDto.java | 5 +- ...eDto.java => RefreshTokenResponseDto.java} | 14 ++- .../user/dto/response/TokenResponseDto.java | 6 +- .../farmususer/user/service/AuthService.java | 69 ++++++------ .../user/service/OnBoardingService.java | 19 +--- .../farmususer/user/service/UserService.java | 103 +++++------------- 24 files changed, 186 insertions(+), 339 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java rename src/main/java/modernfarmer/server/farmususer/user/dto/response/{ResponseDto.java => RefreshTokenResponseDto.java} (51%) diff --git a/build.gradle b/build.gradle index 0fe7026..63f32d2 100644 --- a/build.gradle +++ b/build.gradle @@ -21,11 +21,17 @@ repositories { mavenCentral() } +ext { + set('springCloudVersion', "2021.0.8") +} + dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' + implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' developmentOnly 'org.springframework.boot:spring-boot-devtools' @@ -43,6 +49,12 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' } +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } +} + tasks.named('test') { useJUnitPlatform() } diff --git a/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java b/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java index 29944ad..b084aee 100644 --- a/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java +++ b/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java @@ -2,10 +2,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; - @EnableJpaAuditing +@EnableDiscoveryClient @SpringBootApplication public class FarmusUserApplication { diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java deleted file mode 100644 index bb79779..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java +++ /dev/null @@ -1,21 +0,0 @@ -package modernfarmer.server.farmususer.global.exception; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; - -@Getter -@RequiredArgsConstructor -public enum CustomExceptionContext implements ExceptionContext{ - - - FIREBASE_CONFIG_EXCEPTION(HttpStatus.BAD_REQUEST, 1005, "파이어베이스 설정 오류입니다."), - NOT_FOUND_MEDICINE_ERROR(HttpStatus.NOT_FOUND, 1006, "해당 약 정보를 찾을 수 없습니다."), - REFRESH_TOKEN_DIFFERENT(HttpStatus.BAD_REQUEST , 1000,"접근이 올바르지 않습니다."); - // DOMAIN PER EXCEPTIONS ... - - - private final HttpStatus httpStatus; - private final int code; - private final String message; -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java index 472b87c..34d9204 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java @@ -1,6 +1,7 @@ package modernfarmer.server.farmususer.global.exception; import lombok.*; +import org.springframework.http.HttpStatus; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -8,6 +9,6 @@ @ToString public class ErrorResponse { - private int code; + private HttpStatus code; private String message; } diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java deleted file mode 100644 index 8f2bbb7..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java +++ /dev/null @@ -1,11 +0,0 @@ -package modernfarmer.server.farmususer.global.exception; - -import org.springframework.http.HttpStatus; - -public interface ExceptionContext { - HttpStatus getHttpStatus(); - - String getMessage(); - - int getCode(); -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java index 17d97cc..7cd1990 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java @@ -2,11 +2,15 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindException; import org.springframework.validation.FieldError; +import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import javax.servlet.http.HttpServletRequest; import java.util.Objects; @@ -15,21 +19,56 @@ @RequiredArgsConstructor @RestControllerAdvice public class GlobalExceptionHandler { - private final int INVALID_PARAMETER_CODE = 400; + private final HttpStatus BAD_REQUEST = HttpStatus.BAD_REQUEST; + @ExceptionHandler(MethodArgumentNotValidException.class) - public ResponseEntity<ErrorResponse> handleInputFieldException(MethodArgumentNotValidException e) { + public ResponseEntity<ErrorResponse> handleInputFieldException(MethodArgumentNotValidException e, HttpServletRequest request) { + log.error("MethodArgumentNotValidException : {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage()); FieldError mainError = e.getFieldErrors().get(0); String[] errorInfo = Objects.requireNonNull(mainError.getDefaultMessage()).split(":"); String message = errorInfo[0]; - return ResponseEntity.badRequest().body(new ErrorResponse(INVALID_PARAMETER_CODE, message)); + return ResponseEntity.badRequest().body(new ErrorResponse(BAD_REQUEST, message)); } - @ExceptionHandler(ModernFarmerException.class) - public ResponseEntity<ErrorResponse> handleModernFarmerException(ModernFarmerException e) { - return ResponseEntity.status(e.getHttpStatus()).body(new ErrorResponse(e.getCode(), e.getMessage())); + @ExceptionHandler(BindException.class) + public ResponseEntity<ErrorResponse> handleBindException(BindException e, HttpServletRequest request) { + log.error("BindException : {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage()); + FieldError mainError = e.getFieldErrors().get(0); + String[] errorInfo = Objects.requireNonNull(mainError.getDefaultMessage()).split(":"); + String message = errorInfo[0]; + return ResponseEntity.badRequest().body(new ErrorResponse(BAD_REQUEST, message)); } + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public ResponseEntity<ErrorResponse> handleMethodArgumentTypeMismatchExceptionException(MethodArgumentTypeMismatchException e, HttpServletRequest request) { + log.error("MethodArgumentTypeMismatchException : {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage()); + return ResponseEntity.badRequest().body(new ErrorResponse(BAD_REQUEST, e.getMessage())); + } + + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public ResponseEntity<ErrorResponse> handleHttpRequestMethodNotSupportedExceptionException(HttpRequestMethodNotSupportedException e, HttpServletRequest request) { + log.error("HttpRequestMethodNotSupportedException : {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage()); + + return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.METHOD_NOT_ALLOWED, e.getMessage())); + } + + + + + @ExceptionHandler(Exception.class) public ResponseEntity<ErrorResponse> unhandledException(Exception e, HttpServletRequest request) { log.error("UnhandledException: {} {} errMessage={}\n", @@ -38,6 +77,6 @@ public ResponseEntity<ErrorResponse> unhandledException(Exception e, HttpServlet e.getMessage() ); return ResponseEntity.internalServerError() - .body(new ErrorResponse(500, "서버와의 접속이 원활하지 않습니다.")); + .body(new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, "서버와의 접속이 원활하지 않습니다.")); } } diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java deleted file mode 100644 index 6a40961..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java +++ /dev/null @@ -1,19 +0,0 @@ -package modernfarmer.server.farmususer.global.exception; - -import lombok.Getter; -import org.springframework.http.HttpStatus; - -@Getter -public class ModernFarmerException extends RuntimeException { - private final HttpStatus httpStatus; - private final String message; - private final int code; - - public ModernFarmerException(HttpStatus httpStatus, String message, int code) { - this.httpStatus = httpStatus; - this.message = message; - this.code = code; - } - - -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java deleted file mode 100644 index b91018d..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java +++ /dev/null @@ -1,13 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.badrequest; - - -import lombok.Getter; -import modernfarmer.server.farmususer.global.exception.ExceptionContext; -import modernfarmer.server.farmususer.global.exception.ModernFarmerException; - -@Getter -public class BadRequestException extends ModernFarmerException { - public BadRequestException(ExceptionContext context){ - super(context.getHttpStatus(), context.getMessage(), context.getCode()); - } -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java deleted file mode 100644 index fa3c385..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java +++ /dev/null @@ -1,10 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.badrequest; - - -import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.FIREBASE_CONFIG_EXCEPTION; - -public class FirebaseConfigException extends BadRequestException { - public FirebaseConfigException(){ - super(FIREBASE_CONFIG_EXCEPTION); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java index 1dfa6b0..6d6748c 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java @@ -8,28 +8,16 @@ @Getter public enum ErrorMessage { - SUCCESS(OK, true, "요청에 성공하였습니다."), - INTERVAL_SERVER_ERROR(INTERNAL_SERVER_ERROR, false, "요청을 처리하는 과정에서 서버가 예상하지 못한 오류가 발생하였습니다."), - USER_NOT_FOUND(NOT_FOUND, false, "해당 회원을 찾을 수 없습니다."), - CATEGORY_NOT_FOUND(NOT_FOUND, false, "해당 회원의 카테고리를 찾을 수 없습니다."), - WRONG_PASSWORD(NOT_FOUND, false, "비밀번호가 맞지 않습니다."), - WRONG_POST(NOT_FOUND, false, "해당 포스트를 찾을 수 없습니다."), - FOLLOW_NOT_FOUND(NOT_FOUND, false, "팔로잉을 찾을 수 없습니다."), - COMMENT_NOT_FOUND(NOT_FOUND, false, "댓글을 찾을 수 없습니다"), - INVALID_FILE_UPLOAD(BAD_REQUEST, false, "파일 업로드에 실패하였습니다."), - INVALID_FORMAT(BAD_REQUEST, false, "형식에 맞지 않습니다."), - POST_NOT_FOUND(NOT_FOUND, false, "포스트를 찾을 수 없습니다."), - ALREADY_SIGNUPED_EMAIL_USER(BAD_REQUEST, false, "이미 회원가입한 유저입니다."), - TOKEN_ERROR(UNAUTHORIZED, false, "잘못된 토큰 정보입니다."); + INTERVAL_SERVER_ERROR(1001, "요청을 처리하는 과정에서 서버가 예상하지 못한 오류가 발생하였습니다."), + REFRESH_NOTIFICATION_ERROR(4017, "Refresh Token 인증 오류"); + private final int code; - private final boolean isSuccess; private final String message; - ErrorMessage(HttpStatus code, boolean isSuccess, String message) { - this.code = code.value(); - this.isSuccess = isSuccess; + ErrorMessage(int code, String message) { + this.code = code; this.message = message; } } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java deleted file mode 100644 index a522576..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java +++ /dev/null @@ -1,16 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.notfound; - - -import lombok.Getter; -import modernfarmer.server.farmususer.global.exception.ExceptionContext; -import modernfarmer.server.farmususer.global.exception.ModernFarmerException; -import org.springframework.http.HttpStatus; - -@Getter -public class NotFoundException extends ModernFarmerException { - public NotFoundException(ExceptionContext context) { - super(context.getHttpStatus(), context.getMessage(), context.getCode()); - } - - -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java deleted file mode 100644 index 2d02c6c..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.notfound; - - -import modernfarmer.server.farmususer.global.exception.ModernFarmerException; - -import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.NOT_FOUND_MEDICINE_ERROR; - -public class NotFoundMedicineException extends NotFoundException { - public NotFoundMedicineException() { - super(NOT_FOUND_MEDICINE_ERROR); - } -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java deleted file mode 100644 index 37e735c..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java +++ /dev/null @@ -1,10 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.notfound; - -import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.REFRESH_TOKEN_DIFFERENT; - -public class NotFoundRefreshTokenException extends NotFoundException{ - - public NotFoundRefreshTokenException() { - super(REFRESH_TOKEN_DIFFERENT); - } -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java index b187969..91a2a86 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/success/SuccessMessage.java @@ -1,21 +1,16 @@ package modernfarmer.server.farmususer.global.exception.success; import lombok.Getter; -import org.springframework.http.HttpStatus; - -import static org.springframework.http.HttpStatus.OK; @Getter public enum SuccessMessage { - SUCCESS(OK, "요청에 성공하였습니다."); + SUCCESS(200, "요청에 성공하였습니다."); private final int code; - // private final boolean isSuccess; private final String message; - SuccessMessage(HttpStatus code, String message) { - this.code = code.value(); - // this.isSuccess = isSuccess; + SuccessMessage(int code, String message) { + this.code = code; this.message = message; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java index 72beb69..056a375 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java @@ -1,6 +1,7 @@ package modernfarmer.server.farmususer.user.controller; -import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import lombok.RequiredArgsConstructor; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.service.AuthService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; @@ -11,6 +12,7 @@ import javax.servlet.http.HttpServletRequest; +@RequiredArgsConstructor @RestController @RequestMapping("/api/user/auth") public class AuthController { @@ -18,18 +20,12 @@ public class AuthController { private final AuthService authService; private final JwtTokenProvider jwtTokenProvider; - @Autowired - public AuthController(AuthService authService, JwtTokenProvider jwtTokenProvider){ - this.authService = authService; - this.jwtTokenProvider = jwtTokenProvider; - } - @PostMapping(value = "/kakao-login") - public TokenResponseDto kakaoLogin(HttpServletRequest request) { + public BaseResponseDto kakaoLogin(HttpServletRequest request) { String accessToken = jwtTokenProvider.resolveToken(request); - TokenResponseDto reissueTokenResponseDto = authService.kakaoLogin(accessToken); + BaseResponseDto reissueTokenResponseDto = authService.kakaoLogin(accessToken); LOGGER.info("카카오 로그인 완료"); @@ -38,11 +34,11 @@ public TokenResponseDto kakaoLogin(HttpServletRequest request) { @PostMapping(value = "/google-login") - public TokenResponseDto googleLogin(HttpServletRequest request) { + public BaseResponseDto googleLogin(HttpServletRequest request) { String accessToken = jwtTokenProvider.resolveToken(request); - TokenResponseDto tokenResponseDto = authService.googleLogin(accessToken); + BaseResponseDto tokenResponseDto = authService.googleLogin(accessToken); LOGGER.info("구글 로그인 완료"); diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java index fa9dac1..14233cf 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -1,10 +1,10 @@ package modernfarmer.server.farmususer.user.controller; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.service.OnBoardingService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; +@RequiredArgsConstructor @Slf4j @RestController @RequestMapping("/api/user") @@ -23,11 +24,6 @@ public class OnBoardingController { private final JwtTokenProvider jwtTokenProvider; private final OnBoardingService onBoardingService; - @Autowired - public OnBoardingController( JwtTokenProvider jwtTokenProvider,OnBoardingService onBoardingService){ - this.jwtTokenProvider = jwtTokenProvider; - this.onBoardingService = onBoardingService; - } @PostMapping(value = "/motivation") public BaseResponseDto onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) { diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index f5587cf..dd7836a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -3,8 +3,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.service.UserService; @@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.IOException; + @Slf4j @RestController @RequestMapping("/api/user") @@ -26,34 +27,34 @@ public class UserController { private final JwtTokenProvider jwtTokenProvider; @PostMapping(value = "/profileImage", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile) throws IOException { + public BaseResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile) throws IOException { String userId = jwtTokenProvider.getUserId(request); log.info(userId); - ResponseDto responseDto = userService.emitProfileImage(Long.valueOf(userId), multipartFile); + BaseResponseDto responseDto = userService.emitProfileImage(Long.valueOf(userId), multipartFile); return responseDto; } @GetMapping(value = "/profileImage") - public ProfileImageResponseDto selectProfileImage(HttpServletRequest request){ + public BaseResponseDto selectProfileImage(HttpServletRequest request){ String userId = jwtTokenProvider.getUserId(request); - ProfileImageResponseDto profileImageResponseDto = userService.selectProfileImage(Long.valueOf(userId)); + BaseResponseDto profileImageResponseDto = userService.selectProfileImage(Long.valueOf(userId)); return profileImageResponseDto; } @DeleteMapping(value = "/delete") - public ResponseDto deleteUser(HttpServletRequest request){ + public BaseResponseDto deleteUser(HttpServletRequest request){ String userId = jwtTokenProvider.getUserId(request); - ResponseDto responseDto = userService.deleteUser(Long.valueOf(userId)); + BaseResponseDto responseDto = userService.deleteUser(Long.valueOf(userId)); return responseDto; } @@ -61,23 +62,23 @@ public ResponseDto deleteUser(HttpServletRequest request){ @PostMapping(value = "/nickname") - public ResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ + public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ String userId = jwtTokenProvider.getUserId(request); - ResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); + BaseResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); return responseDto; } @DeleteMapping("/logout") - public ResponseDto logout(HttpServletRequest request) { + public BaseResponseDto logout(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); - ResponseDto logoutResponseDto = userService.logout(Long.valueOf(userId)); + BaseResponseDto logoutResponseDto = userService.logout(Long.valueOf(userId)); log.info("로그아웃 완료"); @@ -85,12 +86,12 @@ public ResponseDto logout(HttpServletRequest request) { } @GetMapping(value = "/reissue-token") - public TokenResponseDto reissueToken(HttpServletRequest request) { + public BaseResponseDto reissueToken(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); String refreshToken = jwtTokenProvider.resolveToken(request); - TokenResponseDto reissueTokenResponseDto = userService.reissueToken(refreshToken, Long.valueOf(userId)); + BaseResponseDto reissueTokenResponseDto = userService.reissueToken(refreshToken, Long.valueOf(userId)); log.info("토큰 재발급 완료"); diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java index 5cef503..9549773 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java @@ -2,49 +2,37 @@ import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.Builder; import lombok.Getter; import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; -import org.springframework.http.HttpStatus; - -import static modernfarmer.server.farmususer.global.exception.success.SuccessMessage.SUCCESS; - - +import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; @Getter +@Builder @JsonPropertyOrder({"code", "message", "result"}) public class BaseResponseDto<T> { private final int code; - // @JsonProperty("isSuccess") - // private final Boolean isSuccess; private final String message; @JsonInclude(JsonInclude.Include.NON_NULL) private T result; - // 요청에 성공한 경우 - public BaseResponseDto(T result) { - this.code = HttpStatus.OK.value(); - // this.isSuccess = SUCCESS.isSuccess(); - this.message = SUCCESS.getMessage(); - this.result = result; - } + public static <T> BaseResponseDto of(SuccessMessage successMessage, T result){ - public BaseResponseDto(ErrorMessage errorMessage) { - this.code = errorMessage.getCode(); - // this.isSuccess = errorMessage.isSuccess(); - this.message = errorMessage.getMessage(); + return BaseResponseDto.builder() + .code(successMessage.getCode()) + .message(successMessage.getMessage()) + .result(result) + .build(); } - public BaseResponseDto(int code, Boolean isSuccess, String errorMessage) { - this.code = code; - // this.isSuccess = isSuccess; - this.message = errorMessage; - } + public static <T> BaseResponseDto of(ErrorMessage errorMessage){ - public static <T> BaseResponseDto of(T result){ - return new BaseResponseDto(result); + return BaseResponseDto.builder() + .code(errorMessage.getCode()) + .message(errorMessage.getMessage()) + .build(); } } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java index 1ae6158..fb0a7da 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/ProfileImageResponseDto.java @@ -5,10 +5,9 @@ import lombok.experimental.SuperBuilder; @NoArgsConstructor -@AllArgsConstructor +@AllArgsConstructor(staticName = "of") @Getter -@SuperBuilder -public class ProfileImageResponseDto extends ResponseDto{ +public class ProfileImageResponseDto{ private String profileImage; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/RefreshTokenResponseDto.java similarity index 51% rename from src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java rename to src/main/java/modernfarmer/server/farmususer/user/dto/response/RefreshTokenResponseDto.java index 418f3af..a2f9db4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/ResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/RefreshTokenResponseDto.java @@ -2,13 +2,15 @@ import lombok.*; -import lombok.experimental.SuperBuilder; @NoArgsConstructor @AllArgsConstructor(staticName = "of") -@SuperBuilder +@ToString +@Builder @Getter -public class ResponseDto { - private int code; - private String message; -} \ No newline at end of file +public class RefreshTokenResponseDto { + + private String accessToken; + + private String refreshToken; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java index beba6e7..7a3dbec 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java @@ -5,11 +5,11 @@ import lombok.experimental.SuperBuilder; @NoArgsConstructor -@AllArgsConstructor +@AllArgsConstructor(staticName = "of") @ToString -@SuperBuilder +@Builder @Getter -public class TokenResponseDto extends ResponseDto{ +public class TokenResponseDto { private String accessToken; diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index c465e16..0722649 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,7 +1,10 @@ package modernfarmer.server.farmususer.user.service; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; @@ -17,28 +20,22 @@ import java.util.Optional; + +@RequiredArgsConstructor @Slf4j @Service public class AuthService{ - public JwtTokenProvider jwtTokenProvider; - public RedisTemplate<String, String> redisTemplate; + private final JwtTokenProvider jwtTokenProvider; + private final RedisTemplate<String, String> redisTemplate; - public UserRepository userRepository; + private final UserRepository userRepository; private final WebClient webClient; - @Autowired - public AuthService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate) { - this.webClient = webClient; - this.userRepository = userRepository; - this.jwtTokenProvider = jwtTokenProvider; - this.redisTemplate = redisTemplate; - } - - public TokenResponseDto googleLogin(String accessToken) { + public BaseResponseDto googleLogin(String accessToken) { User user; boolean early = false; @@ -46,7 +43,6 @@ public TokenResponseDto googleLogin(String accessToken) { Mono<GoogleUserResponseDto> userInfoMono = getUserGoogleInfo(accessToken); GoogleUserResponseDto userInfo = userInfoMono.block(); - Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); log.info(String.valueOf(userInfo.getEmail())); @@ -69,24 +65,23 @@ public TokenResponseDto googleLogin(String accessToken) { String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); - TokenResponseDto tokenResponseDto = TokenResponseDto.builder() - .message("OK") - .code(200) - .early(early) - .accessToken(jwtTokenProvider.createAccessToken( - userLoginData.get().getId(), - String.valueOf(userLoginData.get().getRoles()))) - .refreshToken(refreshToken) - .build(); - + BaseResponseDto baseResponseDto = BaseResponseDto.of( + SuccessMessage.SUCCESS, + TokenResponseDto.of( + jwtTokenProvider.createAccessToken( + userLoginData.get().getId(), + String.valueOf(userLoginData.get().getRoles())), + refreshToken, + early + ) + ); redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); - - return tokenResponseDto; + return baseResponseDto; } - public TokenResponseDto kakaoLogin(String accessToken) { + public BaseResponseDto kakaoLogin(String accessToken) { User user; boolean early = false; @@ -118,21 +113,21 @@ public TokenResponseDto kakaoLogin(String accessToken) { String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); - TokenResponseDto tokenResponseDto = TokenResponseDto.builder() - .message("OK") - .code(200) - .early(early) - .accessToken(jwtTokenProvider.createAccessToken( - userLoginData.get().getId(), - String.valueOf(userLoginData.get().getRoles()))) - .refreshToken(refreshToken) - .build(); + BaseResponseDto baseResponseDto = BaseResponseDto.of( + SuccessMessage.SUCCESS, + TokenResponseDto.of( + jwtTokenProvider.createAccessToken( + userLoginData.get().getId(), + String.valueOf(userLoginData.get().getRoles())), + refreshToken, + early + ) + ); redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); - - return tokenResponseDto; + return baseResponseDto; } public Mono<KakaoUserResponseDto> getUserKakaoInfo(String accessToken) { diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index a963877..7f566c9 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -1,10 +1,11 @@ package modernfarmer.server.farmususer.user.service; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -12,29 +13,21 @@ import javax.transaction.Transactional; + +@RequiredArgsConstructor @Transactional @Slf4j @Service public class OnBoardingService { - public UserRepository userRepository; + private final UserRepository userRepository; - @Autowired - public OnBoardingService(UserRepository userRepository) { - this.userRepository = userRepository; - } public BaseResponseDto onBoardingMotivation(Long userId, String motivation){ userRepository.insertUserMotivation(userId, motivation); -// ResponseDto responseDto = ResponseDto.builder() -// .message("OK") -// .code(200) -// .build(); - - return new BaseResponseDto<>(SuccessMessage.SUCCESS); + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); - // return responseDto; } } diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 32d1407..231e6ce 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,119 +1,78 @@ package modernfarmer.server.farmususer.user.service; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.global.config.s3.S3Uploader; -import modernfarmer.server.farmususer.global.exception.notfound.NotFoundRefreshTokenException; +import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; +import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ResponseDto; -import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; +import modernfarmer.server.farmususer.user.dto.response.RefreshTokenResponseDto; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.reactive.function.client.WebClient; import java.io.IOException; +@RequiredArgsConstructor @Transactional @Slf4j @Service public class UserService { - public JwtTokenProvider jwtTokenProvider; - public RedisTemplate<String, String> redisTemplate; - public UserRepository userRepository; - public final S3Uploader s3Uploader; + private final JwtTokenProvider jwtTokenProvider; + private final RedisTemplate<String, String> redisTemplate; + private final UserRepository userRepository; + private final S3Uploader s3Uploader; - @Autowired - public UserService(UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate<String, String> redisTemplate, - S3Uploader s3Uploader - ) { - - this.userRepository = userRepository; - this.jwtTokenProvider = jwtTokenProvider; - this.redisTemplate = redisTemplate; - this.s3Uploader = s3Uploader; - - } - - public ResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { + public BaseResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { String imageUrl = s3Uploader.uploadFiles(multipartFile, "userprofileimage"); log.info(imageUrl); userRepository.emitUserProfileImage(userId, imageUrl); - ResponseDto responseDto = ResponseDto - .builder() - .code(200) - .message("OK") - .build(); - - return responseDto; + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public ProfileImageResponseDto selectProfileImage(Long userId){ + public BaseResponseDto selectProfileImage(Long userId){ String userProfileImage = userRepository.selectUserProfileImage(userId); - - ProfileImageResponseDto profileImageResponseDto = ProfileImageResponseDto - .builder() - .code(200) - .message("OK") - .profileImage(userProfileImage) - .build(); - - - return profileImageResponseDto; + return BaseResponseDto.of(SuccessMessage.SUCCESS, ProfileImageResponseDto.of(userProfileImage)); } - public ResponseDto deleteUser(Long userId){ + public BaseResponseDto deleteUser(Long userId){ userRepository.deleteUser(userId); - ResponseDto responseDto = ResponseDto - .builder() - .code(200) - .message("OK") - .build(); - - return responseDto; + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public ResponseDto emitNickname(Long userId, String nickName){ + public BaseResponseDto emitNickname(Long userId, String nickName){ userRepository.updateUserNickname(nickName, userId); - ResponseDto responseDto = ResponseDto.builder() - .code(200) - .message("OK") - .build(); - - return responseDto; + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public ResponseDto logout(Long userId) { + public BaseResponseDto logout(Long userId) { + deleteValueByKey(String.valueOf(userId)); - ResponseDto responseDto = ResponseDto.builder() - .message("OK") - .code(200) - .build(); - return responseDto; + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public TokenResponseDto reissueToken(String refreshToken, Long userId) { - TokenResponseDto reissueTokenResponse; + public BaseResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); @@ -121,20 +80,14 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String userRole = userRepository.findUserRole(userId); - reissueTokenResponse= TokenResponseDto - .builder() - .code(200) - .message("OK") - .accessToken(jwtTokenProvider.createAccessToken(userId, userRole)) - .refreshToken(refreshToken) - .build(); - - return reissueTokenResponse; - + return BaseResponseDto.of(SuccessMessage.SUCCESS, + RefreshTokenResponseDto.of( + jwtTokenProvider.createAccessToken(userId, userRole), + refreshToken + )); } - throw new NotFoundRefreshTokenException(); - + return BaseResponseDto.of(ErrorMessage.REFRESH_NOTIFICATION_ERROR); } public void deleteValueByKey(String key) { From 8c443550fc02a7e354889aea0f5a035efd315be4 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 3 Nov 2023 17:12:37 +0900 Subject: [PATCH 42/95] =?UTF-8?q?[fix]=20=EC=9D=91=EB=8B=B5=20data=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/dto/response/BaseResponseDto.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java index 9549773..85df827 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java @@ -11,20 +11,20 @@ @Getter @Builder -@JsonPropertyOrder({"code", "message", "result"}) +@JsonPropertyOrder({"code", "message", "data"}) public class BaseResponseDto<T> { private final int code; private final String message; @JsonInclude(JsonInclude.Include.NON_NULL) - private T result; + private T data; - public static <T> BaseResponseDto of(SuccessMessage successMessage, T result){ + public static <T> BaseResponseDto of(SuccessMessage successMessage, T data){ return BaseResponseDto.builder() .code(successMessage.getCode()) .message(successMessage.getMessage()) - .result(result) + .data(data) .build(); } From a175a540279c7ae891c77fdfba59719c9b80319f Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 3 Nov 2023 18:30:49 +0900 Subject: [PATCH 43/95] =?UTF-8?q?[feat]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EB=82=9C=EC=9D=B4=EB=8F=84=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/OnBoardingController.java | 11 ++++ .../dto/request/OnBoardingLevelRequest.java | 21 +++++++ .../dto/response/OnBoardingLevelResponse.java | 14 +++++ .../dto/response/RefreshTokenResponseDto.java | 2 - .../user/dto/response/TokenResponseDto.java | 2 - .../user/repository/UserRepository.java | 4 ++ .../user/service/OnBoardingService.java | 60 ++++++++++++++++++- 7 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/OnBoardingLevelResponse.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java index 14233cf..feae1f3 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.request.OnBoardingLevelRequest; import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.service.OnBoardingService; @@ -34,4 +35,14 @@ public BaseResponseDto onBoardingMotivation(HttpServletRequest request, @Validat return responseDto; } + + @PostMapping(value = "/level") + public BaseResponseDto onBoardingLevel(HttpServletRequest request, @Validated @RequestBody OnBoardingLevelRequest onBoardingLevelRequest) { + + String userId = jwtTokenProvider.getUserId(request); + + BaseResponseDto responseDto = onBoardingService.onBoardingLevel(Long.valueOf(userId), onBoardingLevelRequest); + + return responseDto; + } } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java new file mode 100644 index 0000000..95f7874 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java @@ -0,0 +1,21 @@ +package modernfarmer.server.farmususer.user.dto.request; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import java.util.ArrayList; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class OnBoardingLevelRequest { + + @NotNull(message = "null 값을 가지면 안됩니다.") + private int time; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private ArrayList<String> skill; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/OnBoardingLevelResponse.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/OnBoardingLevelResponse.java new file mode 100644 index 0000000..38a4267 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/OnBoardingLevelResponse.java @@ -0,0 +1,14 @@ +package modernfarmer.server.farmususer.user.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class OnBoardingLevelResponse { + + private String level; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/RefreshTokenResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/RefreshTokenResponseDto.java index a2f9db4..e4eaa15 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/RefreshTokenResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/RefreshTokenResponseDto.java @@ -5,8 +5,6 @@ @NoArgsConstructor @AllArgsConstructor(staticName = "of") -@ToString -@Builder @Getter public class RefreshTokenResponseDto { diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java index 7a3dbec..6904d6e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/TokenResponseDto.java @@ -6,8 +6,6 @@ @NoArgsConstructor @AllArgsConstructor(staticName = "of") -@ToString -@Builder @Getter public class TokenResponseDto { diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index c4a8f87..65eb9e4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -34,6 +34,10 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("update User as u set u.motivation= :motivation where u.id = :userId") void insertUserMotivation(@Param("userId") Long userId, @Param("motivation") String motivation); + @Modifying + @Query("update User as u set u.level= :level where u.id = :userId") + void insertUserLevel(@Param("userId") Long userId, @Param("level") String level); + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index 7f566c9..c3e9856 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -5,13 +5,16 @@ import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; +import modernfarmer.server.farmususer.user.dto.request.OnBoardingLevelRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; +import modernfarmer.server.farmususer.user.dto.response.OnBoardingLevelResponse; import modernfarmer.server.farmususer.user.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.transaction.Transactional; +import java.util.ArrayList; @RequiredArgsConstructor @@ -19,8 +22,8 @@ @Slf4j @Service public class OnBoardingService { - private final UserRepository userRepository; + private final UserRepository userRepository; public BaseResponseDto onBoardingMotivation(Long userId, String motivation){ @@ -30,4 +33,59 @@ public BaseResponseDto onBoardingMotivation(Long userId, String motivation){ } + public BaseResponseDto onBoardingLevel(Long userId, OnBoardingLevelRequest onBoardingLevelRequest){ + + String level = recommendAlgorithms(onBoardingLevelRequest.getTime(), onBoardingLevelRequest.getSkill()); + + userRepository.insertUserLevel(userId, level); + + return BaseResponseDto.of(SuccessMessage.SUCCESS, OnBoardingLevelResponse.of(level)); + + } + + private String recommendAlgorithms(int time, ArrayList<String> skills) { + boolean isIntermediate = false; + boolean isAdvanced = false; + boolean isExperienced = false; + boolean isBeginner = false; + + for (String skill : skills) { + if ("중급자".equals(skill)) { + isIntermediate = true; + } else if ("고수".equals(skill)) { + isAdvanced = true; + } else if ("경험자".equals(skill)) { + isExperienced = true; + } else if ("초급자".equals(skill)) { + isBeginner = true; + } + } + + if (time == 2 && (isIntermediate || isAdvanced)) { + return "HARD"; + } else if (time == 2 && (isBeginner || isExperienced)) { + return "NORMAL"; + } else if (time == 1 && isAdvanced) { + return "HARD"; + } else if (time == 1 && (isIntermediate || isExperienced)) { + return "NORMAL"; + } else if (time == 1 && isBeginner) { + return "EASY"; + } else if (time == 0 && isAdvanced) { + return "HARD"; + } else if (time == 0 && (isExperienced || isBeginner)) { + return "EASY"; + } + + return "알 수 없음"; + } + + + + + + + + + } From 705327a53c6f42bedf1e62467c396dd7506f8baf Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 3 Nov 2023 19:23:02 +0900 Subject: [PATCH 44/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=88=98=EC=A0=95(=EB=8F=99=EA=B8=B0=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/entity/User.java | 6 +-- .../user/entity/UserMotivation.java | 38 +++++++++++++++++++ .../user/repository/UserRepository.java | 6 +-- .../user/service/OnBoardingService.java | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index d87f53f..05ee112 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -49,9 +49,6 @@ public class User extends BaseEntity{ @Column(name = "firebase_token", length = 100) private String firebaseToken; - @Size(max = 40) - @Column(name = "motivation", length = 40) - private String motivation; @Size(max = 10) @Column(name = "level", length = 10) @@ -61,6 +58,9 @@ public class User extends BaseEntity{ @OneToMany(mappedBy = "user") private Set<UserFirebaseToken> userFirebaseTokens = new LinkedHashSet<>(); + @OneToMany(mappedBy = "user") + private Set<UserMotivation> userMotivations = new LinkedHashSet<>(); + } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java new file mode 100644 index 0000000..4dbbceb --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java @@ -0,0 +1,38 @@ +package modernfarmer.server.farmususer.user.entity; + +import lombok.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.time.Instant; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +@Entity +@Table(name = "user_motivation") +public class UserMotivation extends BaseEntity{ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_motivation_id", nullable = false) + private Long id; + + @NotNull + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @Size(max = 40) + @NotNull + @Column(name = "user_motivation", nullable = false, length = 40) + private String userMotivation; + + + +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 65eb9e4..b12f0a9 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -30,9 +30,9 @@ public interface UserRepository extends JpaRepository<User, Long> { void emitUserProfileImage(@Param("userId") Long userId, @Param("profileImage") String profileImage); - @Modifying - @Query("update User as u set u.motivation= :motivation where u.id = :userId") - void insertUserMotivation(@Param("userId") Long userId, @Param("motivation") String motivation); +// @Modifying +// @Query("update User as u set u.motivation= :motivation where u.id = :userId") +// void insertUserMotivation(@Param("userId") Long userId, @Param("motivation") String motivation); @Modifying @Query("update User as u set u.level= :level where u.id = :userId") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index c3e9856..6abfec7 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -27,7 +27,7 @@ public class OnBoardingService { public BaseResponseDto onBoardingMotivation(Long userId, String motivation){ - userRepository.insertUserMotivation(userId, motivation); + // userRepository.insertUserMotivation(userId, motivation); return BaseResponseDto.of(SuccessMessage.SUCCESS,null); From 0f37a0fbb70d3c49a15fa83cb29d6d04ed89ea1b Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 3 Nov 2023 21:25:44 +0900 Subject: [PATCH 45/95] =?UTF-8?q?[fix]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EB=82=9C=EC=9D=B4=EB=8F=84=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/OnBoardingService.java | 7 +++++-- .../server/farmususer/user/util/JwtTokenProvider.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index 6abfec7..91fa368 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -71,10 +71,13 @@ private String recommendAlgorithms(int time, ArrayList<String> skills) { return "NORMAL"; } else if (time == 1 && isBeginner) { return "EASY"; + } else if (time == 0 && (isExperienced && isBeginner)) { + return "EASY"; + } else if (time == 0 && isExperienced) { + return "NORMAL"; + } else if (time == 0 && isAdvanced) { return "HARD"; - } else if (time == 0 && (isExperienced || isBeginner)) { - return "EASY"; } return "알 수 없음"; diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 12d657b..4671489 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -26,10 +26,10 @@ public class JwtTokenProvider { private String secretKey; - private final long accessTokenTime = 30L * 1000;; // 1달 토큰 유효 + private final long accessTokenTime = 30L * 1000 * 100; // 1달 토큰 유효 - private final long refreshTokenTime = 30L * 1000 * 2; // 1달 토큰 유효 + private final long refreshTokenTime = 30L * 1000 * 2 * 1000; // 1달 토큰 유효 @PostConstruct protected void init() { From c88304d4421cb006d1711fc848ca29932344299c Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 3 Nov 2023 22:12:58 +0900 Subject: [PATCH 46/95] =?UTF-8?q?[fix]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EB=8F=99=EA=B8=B0=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/OnBoardingController.java | 2 +- .../request/OnBoardingMotivationRequest.java | 3 ++- .../farmususer/user/entity/BaseEntity.java | 2 +- .../repository/UserMotivationRepository.java | 11 ++++++++++ .../user/repository/UserRepository.java | 3 --- .../user/service/OnBoardingService.java | 21 +++++++++++++++++-- 6 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/repository/UserMotivationRepository.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java index feae1f3..447a752 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -31,7 +31,7 @@ public BaseResponseDto onBoardingMotivation(HttpServletRequest request, @Validat String userId = jwtTokenProvider.getUserId(request); - BaseResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId), onBoardingMotivationRequest.getMotivation()); + BaseResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId),onBoardingMotivationRequest); return responseDto; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java index 34796c5..5348364 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingMotivationRequest.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import javax.validation.constraints.NotNull; +import java.util.ArrayList; @Getter @AllArgsConstructor @@ -13,5 +14,5 @@ public class OnBoardingMotivationRequest { @NotNull(message = "null 값을 가지면 안됩니다.") - private String motivation; + private ArrayList<String> motivation; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java b/src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java index f3fa8b1..a3c93bc 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/BaseEntity.java @@ -20,5 +20,5 @@ public class BaseEntity { private LocalDateTime createdAt; @LastModifiedDate - private LocalDateTime updateAt; + private LocalDateTime updatedAt; } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserMotivationRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserMotivationRepository.java new file mode 100644 index 0000000..410998e --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserMotivationRepository.java @@ -0,0 +1,11 @@ +package modernfarmer.server.farmususer.user.repository; + +import modernfarmer.server.farmususer.user.entity.User; +import modernfarmer.server.farmususer.user.entity.UserMotivation; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface UserMotivationRepository extends JpaRepository<UserMotivation, Long> { +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index b12f0a9..0e8c9a7 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -30,9 +30,6 @@ public interface UserRepository extends JpaRepository<User, Long> { void emitUserProfileImage(@Param("userId") Long userId, @Param("profileImage") String profileImage); -// @Modifying -// @Query("update User as u set u.motivation= :motivation where u.id = :userId") -// void insertUserMotivation(@Param("userId") Long userId, @Param("motivation") String motivation); @Modifying @Query("update User as u set u.level= :level where u.id = :userId") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index 91fa368..f02231c 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -6,8 +6,12 @@ import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; import modernfarmer.server.farmususer.user.dto.request.OnBoardingLevelRequest; +import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.OnBoardingLevelResponse; +import modernfarmer.server.farmususer.user.entity.User; +import modernfarmer.server.farmususer.user.entity.UserMotivation; +import modernfarmer.server.farmususer.user.repository.UserMotivationRepository; import modernfarmer.server.farmususer.user.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -25,9 +29,22 @@ public class OnBoardingService { private final UserRepository userRepository; - public BaseResponseDto onBoardingMotivation(Long userId, String motivation){ + private final UserMotivationRepository userMotivationRepository; - // userRepository.insertUserMotivation(userId, motivation); + public BaseResponseDto onBoardingMotivation(Long userId, OnBoardingMotivationRequest onBoardingMotivationRequest){ + + User user = User.builder().id(userId).build(); + + for(String motivations : onBoardingMotivationRequest.getMotivation()){ + + UserMotivation userMotivation = UserMotivation + .builder() + .user(user) + .userMotivation(motivations) + .build(); + + userMotivationRepository.save(userMotivation); + } return BaseResponseDto.of(SuccessMessage.SUCCESS,null); From dbbef1af7c7f14499a6783832ec0fca014a130dd Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 4 Nov 2023 01:25:34 +0900 Subject: [PATCH 47/95] =?UTF-8?q?[fix]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20uri?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=20/user=20->=20/user/on-boarding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/controller/OnBoardingController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java index 447a752..11461cb 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -19,7 +19,7 @@ @RequiredArgsConstructor @Slf4j @RestController -@RequestMapping("/api/user") +@RequestMapping("/api/user/on-boarding") public class OnBoardingController { private final JwtTokenProvider jwtTokenProvider; From 716d9cd17932bbbf14c7e8000dd1650b42e8f737 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 4 Nov 2023 03:08:58 +0900 Subject: [PATCH 48/95] =?UTF-8?q?[feat]=20=EB=8B=89=EB=84=A4=EC=9E=84,=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20API,=EC=9D=B4=EC=A0=84=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20API,=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20API=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 39 +++++++++++------- .../farmususer/user/service/UserService.java | 41 +++++++++++++++---- 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index dd7836a..a2ccd84 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -2,10 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; -import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.service.UserService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; @@ -26,12 +23,34 @@ public class UserController { private final UserService userService; private final JwtTokenProvider jwtTokenProvider; - @PostMapping(value = "/profileImage", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile) throws IOException { +// @PostMapping(value = "/profileImage", produces = MediaType.APPLICATION_JSON_VALUE) +// public BaseResponseDto produceProfileImage(HttpServletRequest request, @RequestPart("file") MultipartFile multipartFile) throws IOException { +// +// String userId = jwtTokenProvider.getUserId(request); +// log.info(userId); +// BaseResponseDto responseDto = userService.emitProfileImage(Long.valueOf(userId), multipartFile); +// +// return responseDto; +// +// } + + +// @PostMapping(value = "/nickname") +// public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ +// +// String userId = jwtTokenProvider.getUserId(request); +// +// BaseResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); +// +// return responseDto; +// } + + @PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE) + public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestParam("file") MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { String userId = jwtTokenProvider.getUserId(request); log.info(userId); - BaseResponseDto responseDto = userService.emitProfileImage(Long.valueOf(userId), multipartFile); + BaseResponseDto responseDto = userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName); return responseDto; @@ -61,15 +80,7 @@ public BaseResponseDto deleteUser(HttpServletRequest request){ - @PostMapping(value = "/nickname") - public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ - String userId = jwtTokenProvider.getUserId(request); - - BaseResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); - - return responseDto; - } @DeleteMapping("/logout") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 231e6ce..54dcffc 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -30,16 +30,44 @@ public class UserService { private final S3Uploader s3Uploader; - public BaseResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { +// public BaseResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { +// +// String imageUrl = s3Uploader.uploadFiles(multipartFile, "userprofileimage"); +// log.info(imageUrl); +// +// userRepository.emitUserProfileImage(userId, imageUrl); +// +// return BaseResponseDto.of(SuccessMessage.SUCCESS,null); +// } - String imageUrl = s3Uploader.uploadFiles(multipartFile, "userprofileimage"); - log.info(imageUrl); - userRepository.emitUserProfileImage(userId, imageUrl); +// public BaseResponseDto emitNickname(Long userId, String nickName){ +// +// userRepository.updateUserNickname(nickName, userId); +// +// return BaseResponseDto.of(SuccessMessage.SUCCESS,null); +// } + + public BaseResponseDto selectProfileImageAndNickname(Long userId,MultipartFile multipartFile, + String nickName) throws IOException { + + if(multipartFile.isEmpty()){ + + userRepository.updateUserNickname(nickName,userId); + + }else{ + String imageUrl = s3Uploader.uploadFiles(multipartFile, "userprofileimage"); + log.info(imageUrl); + userRepository.selectUserProfileAndNickname(userId,imageUrl,nickName); + + } return BaseResponseDto.of(SuccessMessage.SUCCESS,null); + } + + public BaseResponseDto selectProfileImage(Long userId){ String userProfileImage = userRepository.selectUserProfileImage(userId); @@ -57,12 +85,7 @@ public BaseResponseDto deleteUser(Long userId){ - public BaseResponseDto emitNickname(Long userId, String nickName){ - userRepository.updateUserNickname(nickName, userId); - - return BaseResponseDto.of(SuccessMessage.SUCCESS,null); - } public BaseResponseDto logout(Long userId) { From 33faa734efa101d0274901f8b424cb07f06d393e Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 4 Nov 2023 03:09:47 +0900 Subject: [PATCH 49/95] =?UTF-8?q?[fix]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC=20=ED=95=B4=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/repository/UserRepository.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 0e8c9a7..0a3f3dd 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -16,18 +16,27 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("SELECT a.roles FROM User AS a WHERE a.id = :userId") String findUserRole(@Param("userId") Long userId); - @Modifying - @Query("update User as u set u.nickname = :nickName where u.id = :userId") - void updateUserNickname(@Param("nickName") String nickName, @Param("userId") Long userId); + @Modifying @Query("delete from User as u where u.id = :userId") void deleteUser(@Param("userId") Long userId); @Query("select u.profileImage from User as u where u.id = :userId") String selectUserProfileImage(@Param("userId") Long userId); + + @Modifying + @Query("update User as u set u.nickname = :nickName where u.id = :userId") + void updateUserNickname(@Param("nickName") String nickName, @Param("userId") Long userId); + + +// @Modifying +// @Query("update User as u set u.profileImage = :profileImage where u.id = :userId") +// void emitUserProfileImage(@Param("userId") Long userId, @Param("profileImage") String profileImage); + + @Modifying - @Query("update User as u set u.profileImage = :profileImage where u.id = :userId") - void emitUserProfileImage(@Param("userId") Long userId, @Param("profileImage") String profileImage); + @Query("update User as u set u.profileImage = :profileImage, u.nickname = :nickName where u.id = :userId") + void selectUserProfileAndNickname(@Param("userId") Long userId, @Param("profileImage") String profileImage, @Param("nickName") String nickName); From fac1466b1c8845dc9d61c20ac489b84953150265 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 5 Nov 2023 20:15:41 +0900 Subject: [PATCH 50/95] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 02c35f8..5888edf 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -75,4 +75,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + docker run -d -p 8081:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 198a18cd26ca25f1f18c8ce4c8ac6a0067950a7e Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 5 Nov 2023 21:09:26 +0900 Subject: [PATCH 51/95] =?UTF-8?q?[fix]=20redis=20host=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5888edf..e600077 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -52,6 +52,7 @@ jobs: echo "${{ secrets.PROPERTIES_YML }}" > ./application.yml shell: bash + # 빌드(테스트 스킵) - name: Build with Gradle run: ./gradlew build -x test From b6f63e656ed1534d2d4a5ed06e331b94c47b18ae Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Tue, 7 Nov 2023 00:19:19 +0900 Subject: [PATCH 52/95] =?UTF-8?q?[fix]=20ip=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index e600077..11c7c17 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -72,6 +72,7 @@ jobs: username: ubuntu key: ${{ secrets.EC2_PRIVATE_KEY }} script: | + docker stop ModernFarmerUser docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 3a7d159c32db4b793780c1b8e5bf4ff5338f8f6e Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Tue, 7 Nov 2023 00:22:15 +0900 Subject: [PATCH 53/95] =?UTF-8?q?[fix]=20ip=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 11c7c17..e600077 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -72,7 +72,6 @@ jobs: username: ubuntu key: ${{ secrets.EC2_PRIVATE_KEY }} script: | - docker stop ModernFarmerUser docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From a43fdb480a131e5a1f2ff23810240e5d6797a8cc Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Wed, 8 Nov 2023 19:35:58 +0900 Subject: [PATCH 54/95] =?UTF-8?q?[fix]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20API?= =?UTF-8?q?=20early=20=EC=88=98=EC=A0=95=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../server/farmususer/user/entity/User.java | 7 +++---- .../farmususer/user/service/AuthService.java | 15 ++++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index e600077..7a9b8bc 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_17/유저-db적용-및-온보딩-구현"] + branches: ["feature_19/회원,-로그인-API"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index 05ee112..cbc97e9 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -11,7 +11,6 @@ import java.util.Set; @Getter -@Setter @Entity @Builder @NoArgsConstructor @@ -23,9 +22,6 @@ public class User extends BaseEntity{ @Column(name = "user_id", nullable = false) private Long id; - @Size(max = 45) - @Column(name = "username", length = 45) - private String username; @Size(max = 45) @Column(name = "nickname", length = 45) @@ -49,6 +45,9 @@ public class User extends BaseEntity{ @Column(name = "firebase_token", length = 100) private String firebaseToken; + @Column(name = "early") + private boolean early; + @Size(max = 10) @Column(name = "level", length = 10) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 0722649..0c2fb09 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -38,7 +38,7 @@ public class AuthService{ public BaseResponseDto googleLogin(String accessToken) { User user; - boolean early = false; + boolean early; Mono<GoogleUserResponseDto> userInfoMono = getUserGoogleInfo(accessToken); GoogleUserResponseDto userInfo = userInfoMono.block(); @@ -54,17 +54,18 @@ public BaseResponseDto googleLogin(String accessToken) { .userNumber(String.valueOf(userInfo.getId())) .roles("USER") .profileImage(userInfo.getPicture()) + .early(true) .build(); - early = true; userRepository.save(user); } Optional<User> userLoginData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); - String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); + early = userLoginData.get().isEarly(); + BaseResponseDto baseResponseDto = BaseResponseDto.of( SuccessMessage.SUCCESS, TokenResponseDto.of( @@ -84,7 +85,7 @@ public BaseResponseDto googleLogin(String accessToken) { public BaseResponseDto kakaoLogin(String accessToken) { User user; - boolean early = false; + boolean early; Mono<KakaoUserResponseDto> userInfoMono = getUserKakaoInfo(accessToken); KakaoUserResponseDto userInfo = userInfoMono.block(); @@ -96,24 +97,24 @@ public BaseResponseDto kakaoLogin(String accessToken) { Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); + if(userData.isEmpty()){ user = User.builder() .userNumber(String.valueOf(userInfo.getId())) .roles("USER") .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) + .early(true) .build(); - early = true; - userRepository.save(user); } Optional<User> userLoginData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); + early = userLoginData.get().isEarly(); String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); - BaseResponseDto baseResponseDto = BaseResponseDto.of( SuccessMessage.SUCCESS, TokenResponseDto.of( From 7070c956b414e7f5b6d836c6c7a67c26f7962ade Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Wed, 8 Nov 2023 19:49:39 +0900 Subject: [PATCH 55/95] =?UTF-8?q?[feat]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85,=20=EC=98=A8=EB=B3=B4=EB=94=A9=20=EC=99=84=EB=A3=8C?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/controller/UserController.java | 12 ++++++++++++ .../farmususer/user/repository/UserRepository.java | 4 ++++ .../server/farmususer/user/service/UserService.java | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index a2ccd84..8a587de 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -56,6 +56,18 @@ public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, } + @PatchMapping(value = "/sign-up/complete", produces = MediaType.APPLICATION_JSON_VALUE) + public BaseResponseDto signUpComplete(HttpServletRequest request) { + + String userId = jwtTokenProvider.getUserId(request); + + + BaseResponseDto responseDto = userService.signUpComlete(Long.valueOf(userId)); + + return responseDto; + + } + @GetMapping(value = "/profileImage") public BaseResponseDto selectProfileImage(HttpServletRequest request){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 0a3f3dd..88300d6 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -28,6 +28,10 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("update User as u set u.nickname = :nickName where u.id = :userId") void updateUserNickname(@Param("nickName") String nickName, @Param("userId") Long userId); + @Modifying + @Query("update User as u set u.early = 0 where u.id = :userId") + void updateEarly( @Param("userId") Long userId); + // @Modifying // @Query("update User as u set u.profileImage = :profileImage where u.id = :userId") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 54dcffc..01cbc8b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -75,6 +75,13 @@ public BaseResponseDto selectProfileImage(Long userId){ return BaseResponseDto.of(SuccessMessage.SUCCESS, ProfileImageResponseDto.of(userProfileImage)); } + public BaseResponseDto signUpComlete(Long userId){ + + userRepository.updateEarly(userId); + + return BaseResponseDto.of(SuccessMessage.SUCCESS, null); + } + public BaseResponseDto deleteUser(Long userId){ From c3201c9c8657ea0cc9349678390787f2469c14ea Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 9 Nov 2023 16:02:06 +0900 Subject: [PATCH 56/95] =?UTF-8?q?[fix]=20=ED=94=84=EB=A1=9C=ED=95=84,=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=84=A4=EC=A0=95=20api=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20isEmpty=20->=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../server/farmususer/user/service/UserService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 7a9b8bc..31ebba1 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_19/회원,-로그인-API"] + branches: ["dev"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 01cbc8b..a257310 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -52,7 +52,7 @@ public class UserService { public BaseResponseDto selectProfileImageAndNickname(Long userId,MultipartFile multipartFile, String nickName) throws IOException { - if(multipartFile.isEmpty()){ + if(multipartFile == null){ userRepository.updateUserNickname(nickName,userId); From ae19ad137c830bead3b66dd66c23440bb0ad7ce1 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 9 Nov 2023 16:16:51 +0900 Subject: [PATCH 57/95] =?UTF-8?q?[fix]=20=ED=94=84=EB=A1=9C=ED=95=84,=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=84=A4=EC=A0=95=20api=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20null=20->=20isEmpty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index a257310..01cbc8b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -52,7 +52,7 @@ public class UserService { public BaseResponseDto selectProfileImageAndNickname(Long userId,MultipartFile multipartFile, String nickName) throws IOException { - if(multipartFile == null){ + if(multipartFile.isEmpty()){ userRepository.updateUserNickname(nickName,userId); From 4237d021f0bffe3dcae2671d251be97ea2eae109 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 9 Nov 2023 16:34:27 +0900 Subject: [PATCH 58/95] =?UTF-8?q?[fix]=20=ED=94=84=EB=A1=9C=ED=95=84,=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=84=A4=EC=A0=95=20api=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/controller/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 8a587de..eb56748 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -46,7 +46,7 @@ public class UserController { // } @PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestParam("file") MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { + public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { String userId = jwtTokenProvider.getUserId(request); log.info(userId); From b2b0c181fedacce23ac3d376f75ff99f16551fcf Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 9 Nov 2023 17:02:00 +0900 Subject: [PATCH 59/95] =?UTF-8?q?[feat]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20api=20=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 19 ++++++++++--------- .../farmususer/user/service/UserService.java | 12 ++++++------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index eb56748..4c9eeee 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.service.UserService; @@ -35,15 +36,15 @@ public class UserController { // } -// @PostMapping(value = "/nickname") -// public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ -// -// String userId = jwtTokenProvider.getUserId(request); -// -// BaseResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); -// -// return responseDto; -// } + @PostMapping(value = "/nickname") + public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ + + String userId = jwtTokenProvider.getUserId(request); + + BaseResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); + + return responseDto; + } @PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE) public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 01cbc8b..8e20017 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -42,12 +42,12 @@ public class UserService { -// public BaseResponseDto emitNickname(Long userId, String nickName){ -// -// userRepository.updateUserNickname(nickName, userId); -// -// return BaseResponseDto.of(SuccessMessage.SUCCESS,null); -// } + public BaseResponseDto emitNickname(Long userId, String nickName){ + + userRepository.updateUserNickname(nickName, userId); + + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); + } public BaseResponseDto selectProfileImageAndNickname(Long userId,MultipartFile multipartFile, String nickName) throws IOException { From 6304c234d2665bcb5ee242454161dc4cdd109b6f Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 9 Nov 2023 17:58:06 +0900 Subject: [PATCH 60/95] =?UTF-8?q?[fix]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EB=82=9C=EC=9D=B4=EB=8F=84=20=EB=B0=B0=EC=97=B4=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/OnBoardingLevelRequest.java | 2 +- .../user/service/OnBoardingService.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java index 95f7874..dc64cdb 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/request/OnBoardingLevelRequest.java @@ -17,5 +17,5 @@ public class OnBoardingLevelRequest { private int time; @NotNull(message = "null 값을 가지면 안됩니다.") - private ArrayList<String> skill; + private String skill; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index f02231c..a4a287d 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -60,24 +60,24 @@ public BaseResponseDto onBoardingLevel(Long userId, OnBoardingLevelRequest onBoa } - private String recommendAlgorithms(int time, ArrayList<String> skills) { + private String recommendAlgorithms(int time,String skill) { boolean isIntermediate = false; boolean isAdvanced = false; boolean isExperienced = false; boolean isBeginner = false; - for (String skill : skills) { - if ("중급자".equals(skill)) { - isIntermediate = true; - } else if ("고수".equals(skill)) { - isAdvanced = true; - } else if ("경험자".equals(skill)) { - isExperienced = true; - } else if ("초급자".equals(skill)) { - isBeginner = true; - } + + if ("중급자".equals(skill)) { + isIntermediate = true; + } else if ("고수".equals(skill)) { + isAdvanced = true; + } else if ("경험자".equals(skill)) { + isExperienced = true; + } else if ("초급자".equals(skill)) { + isBeginner = true; } + if (time == 2 && (isIntermediate || isAdvanced)) { return "HARD"; } else if (time == 2 && (isBeginner || isExperienced)) { From c0e3f53dabbd900566a8b009a1e08a7f82b166b2 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Thu, 9 Nov 2023 19:10:29 +0900 Subject: [PATCH 61/95] =?UTF-8?q?[fix]=20=EB=82=9C=EC=9D=B4=EB=8F=84=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/OnBoardingService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index a4a287d..6b2f61b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -67,13 +67,13 @@ private String recommendAlgorithms(int time,String skill) { boolean isBeginner = false; - if ("중급자".equals(skill)) { + if ("홈파밍 중급".equals(skill)) { isIntermediate = true; - } else if ("고수".equals(skill)) { + } else if ("홈파밍 고수".equals(skill)) { isAdvanced = true; - } else if ("경험자".equals(skill)) { + } else if ("홈파밍 초보".equals(skill)) { isExperienced = true; - } else if ("초급자".equals(skill)) { + } else if ("홈파밍 입문".equals(skill)) { isBeginner = true; } From fcbf9a7f159eb4f61f31ef8a7706bdd439268810 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 10 Nov 2023 03:46:30 +0900 Subject: [PATCH 62/95] =?UTF-8?q?[feat]=20=EC=98=A4=ED=94=88=ED=8E=98?= =?UTF-8?q?=EC=9D=B8=20=EB=AA=A8=EB=93=A0=20=EC=9C=A0=EC=A0=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/FarmusUserApplication.java | 2 ++ .../user/controller/UserController.java | 8 ++++++++ .../user/dto/response/AllUserDto.java | 19 +++++++++++++++++++ .../user/dto/response/AllUserResponseDto.java | 15 +++++++++++++++ .../server/farmususer/user/entity/User.java | 7 ++----- .../user/repository/UserRepository.java | 6 ++++++ .../farmususer/user/service/UserService.java | 19 ++++++++++++++++--- 7 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserDto.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java b/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java index b084aee..7d8e32d 100644 --- a/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java +++ b/src/main/java/modernfarmer/server/farmususer/FarmusUserApplication.java @@ -3,11 +3,13 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @EnableJpaAuditing @EnableDiscoveryClient @SpringBootApplication +@EnableFeignClients public class FarmusUserApplication { public static void main(String[] args) { diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 4c9eeee..e3198b8 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -122,5 +122,13 @@ public BaseResponseDto reissueToken(HttpServletRequest request) { return reissueTokenResponseDto; } + @GetMapping(value = "/all-user") + public BaseResponseDto allUser() { + + BaseResponseDto reissueTokenResponseDto = userService.allUser(); + + return reissueTokenResponseDto; + } + } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserDto.java new file mode 100644 index 0000000..74e90a8 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserDto.java @@ -0,0 +1,19 @@ +package modernfarmer.server.farmususer.user.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class AllUserDto { + + private Long Id; + private String nickName; + private String imageUrl; + + + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserResponseDto.java new file mode 100644 index 0000000..a7671b4 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/AllUserResponseDto.java @@ -0,0 +1,15 @@ +package modernfarmer.server.farmususer.user.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class AllUserResponseDto { + List<AllUserDto> allUserDtoList; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index cbc97e9..d23471b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -41,9 +41,6 @@ public class User extends BaseEntity{ @Column(name = "user_number", nullable = false, length = 30) private String userNumber; - @Size(max = 100) - @Column(name = "firebase_token", length = 100) - private String firebaseToken; @Column(name = "early") private boolean early; @@ -54,10 +51,10 @@ public class User extends BaseEntity{ private String level; - @OneToMany(mappedBy = "user") + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) private Set<UserFirebaseToken> userFirebaseTokens = new LinkedHashSet<>(); - @OneToMany(mappedBy = "user") + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) private Set<UserMotivation> userMotivations = new LinkedHashSet<>(); diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 88300d6..ff4cf25 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository @@ -49,6 +50,11 @@ public interface UserRepository extends JpaRepository<User, Long> { void insertUserLevel(@Param("userId") Long userId, @Param("level") String level); + //@Query("select u.id, u.nickname, u.profileImage, u.roles, u.userNumber, u.early, u.level from User u") + List<User> findAllBy(); + + + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 8e20017..e1a1253 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -5,9 +5,8 @@ import modernfarmer.server.farmususer.global.config.s3.S3Uploader; import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; -import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ProfileImageResponseDto; -import modernfarmer.server.farmususer.user.dto.response.RefreshTokenResponseDto; +import modernfarmer.server.farmususer.user.dto.response.*; +import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.data.redis.core.RedisTemplate; @@ -16,6 +15,8 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; @RequiredArgsConstructor @@ -92,7 +93,16 @@ public BaseResponseDto deleteUser(Long userId){ + public BaseResponseDto allUser() { + List<User> userList = userRepository.findAllBy(); + List<AllUserDto> userResponseList = userList.stream() + .map(user -> AllUserDto.of(user.getId(), user.getNickname(), user.getProfileImage())) + .collect(Collectors.toList()); + + return BaseResponseDto.of(SuccessMessage.SUCCESS, AllUserResponseDto.of(userResponseList)); + + } public BaseResponseDto logout(Long userId) { @@ -118,8 +128,11 @@ public BaseResponseDto reissueToken(String refreshToken, Long userId) { } return BaseResponseDto.of(ErrorMessage.REFRESH_NOTIFICATION_ERROR); + } + + public void deleteValueByKey(String key) { redisTemplate.delete(key); } From 93cc260b1157ae5e461494b6ecdf5d0e4eada0ac Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 10 Nov 2023 14:03:16 +0900 Subject: [PATCH 63/95] =?UTF-8?q?[feat]=20=EC=98=A4=ED=94=88=ED=8E=98?= =?UTF-8?q?=EC=9D=B8=20=ED=8A=B9=EC=A0=95=20=EC=9C=A0=EC=A0=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/fail/ErrorMessage.java | 3 ++- .../user/controller/UserController.java | 8 ++++++++ .../dto/response/SpecificUserResponseDto.java | 17 +++++++++++++++++ .../user/repository/UserRepository.java | 6 ++++-- .../farmususer/user/service/UserService.java | 19 +++++++++++++++++-- 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/SpecificUserResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java index 6d6748c..d219dc5 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java @@ -9,7 +9,8 @@ public enum ErrorMessage { INTERVAL_SERVER_ERROR(1001, "요청을 처리하는 과정에서 서버가 예상하지 못한 오류가 발생하였습니다."), - REFRESH_NOTIFICATION_ERROR(4017, "Refresh Token 인증 오류"); + REFRESH_NOTIFICATION_ERROR(4017, "Refresh Token 인증 오류"), + NO_USER_DATA(1002, "유저에 대한 정보가 없습니다."); diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index e3198b8..9443dc3 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -130,5 +130,13 @@ public BaseResponseDto allUser() { return reissueTokenResponseDto; } + @GetMapping(value = "/specific-user") + public BaseResponseDto specificUser(@RequestParam("userId") Long userId) { + + // String userId = jwtTokenProvider.getUserId(request); + return userService.specificUser(userId); + } + + } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/SpecificUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/SpecificUserResponseDto.java new file mode 100644 index 0000000..0f53b54 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/SpecificUserResponseDto.java @@ -0,0 +1,17 @@ +package modernfarmer.server.farmususer.user.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class SpecificUserResponseDto { + + private Long Id; + private String nickName; + private String imageUrl; + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index ff4cf25..599e401 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -49,10 +49,12 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("update User as u set u.level= :level where u.id = :userId") void insertUserLevel(@Param("userId") Long userId, @Param("level") String level); - - //@Query("select u.id, u.nickname, u.profileImage, u.roles, u.userNumber, u.early, u.level from User u") List<User> findAllBy(); + Optional<User> findById(Long userId); + + + diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index e1a1253..32a515a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @@ -104,6 +105,22 @@ public BaseResponseDto allUser() { } + public BaseResponseDto specificUser(Long userId) { + + + Optional<User> user = userRepository.findById(userId); + + if(user.isEmpty()){ + return BaseResponseDto.of(ErrorMessage.NO_USER_DATA); + } + + return BaseResponseDto.of(SuccessMessage.SUCCESS, + SpecificUserResponseDto.of(user.get().getId(), + user.get().getNickname(), + user.get().getProfileImage())); + + } + public BaseResponseDto logout(Long userId) { @@ -131,8 +148,6 @@ public BaseResponseDto reissueToken(String refreshToken, Long userId) { } - - public void deleteValueByKey(String key) { redisTemplate.delete(key); } From 022043481d54ec8b1c793846e528bb4eac8c88c9 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 10 Nov 2023 17:41:49 +0900 Subject: [PATCH 64/95] =?UTF-8?q?[fix]=20return=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/controller/UserController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 9443dc3..69e2f8f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -125,9 +125,7 @@ public BaseResponseDto reissueToken(HttpServletRequest request) { @GetMapping(value = "/all-user") public BaseResponseDto allUser() { - BaseResponseDto reissueTokenResponseDto = userService.allUser(); - - return reissueTokenResponseDto; + return userService.allUser(); } @GetMapping(value = "/specific-user") From 004a6e0666cbb8f2d9a43e1fea1eafcb6abc30c2 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 10 Nov 2023 19:33:08 +0900 Subject: [PATCH 65/95] =?UTF-8?q?[fix]=20action.yml=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=ED=81=B4=EB=9D=BC=EC=9A=B0=EB=93=9C=20=EB=B0=B0=ED=8F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 31ebba1..545b7d5 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["dev"] + branches: ["feature_21/-유저-오픈-페인-API"] pull_request: branches: ["dev"] From 4b3efd6542efb2d51fde2a8f01f4cf9075ec1d7c Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 10 Nov 2023 19:53:23 +0900 Subject: [PATCH 66/95] =?UTF-8?q?[fix]=20action.yml=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=ED=81=B4=EB=9D=BC=EC=9A=B0=EB=93=9C=20=EB=B0=B0=ED=8F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 545b7d5..8b0be59 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -72,6 +72,7 @@ jobs: username: ubuntu key: ${{ secrets.EC2_PRIVATE_KEY }} script: | + docker stop ModernFarmerUser docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 65b0f3f78e2517a6077e093c4285a6387c8b8821 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sat, 11 Nov 2023 23:42:40 +0900 Subject: [PATCH 67/95] =?UTF-8?q?[fix]=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EB=82=9C=EC=9D=B4=EB=8F=84=20=EC=B8=A1=EC=A0=95=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/service/OnBoardingService.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index 6b2f61b..9e5766a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -62,39 +62,38 @@ public BaseResponseDto onBoardingLevel(Long userId, OnBoardingLevelRequest onBoa private String recommendAlgorithms(int time,String skill) { boolean isIntermediate = false; - boolean isAdvanced = false; - boolean isExperienced = false; + boolean isMaster = false; + boolean isElementary = false; boolean isBeginner = false; if ("홈파밍 중급".equals(skill)) { isIntermediate = true; } else if ("홈파밍 고수".equals(skill)) { - isAdvanced = true; + isMaster = true; } else if ("홈파밍 초보".equals(skill)) { - isExperienced = true; + isElementary = true; } else if ("홈파밍 입문".equals(skill)) { isBeginner = true; } - if (time == 2 && (isIntermediate || isAdvanced)) { + if (time == 2 && (isIntermediate || isMaster)) { return "HARD"; - } else if (time == 2 && (isBeginner || isExperienced)) { + } else if (time == 2 && (isBeginner || isElementary)) { return "NORMAL"; - } else if (time == 1 && isAdvanced) { + } else if (time == 1 && isMaster) { return "HARD"; - } else if (time == 1 && (isIntermediate || isExperienced)) { + } else if (time == 1 && (isIntermediate || isElementary)) { return "NORMAL"; } else if (time == 1 && isBeginner) { return "EASY"; - } else if (time == 0 && (isExperienced && isBeginner)) { - return "EASY"; - } else if (time == 0 && isExperienced) { - return "NORMAL"; - - } else if (time == 0 && isAdvanced) { + } else if (time == 0 && isMaster) { return "HARD"; + } else if (time == 0 && isIntermediate) { + return "NORMAL"; + } else if (time == 0 && (isElementary || isBeginner)) { + return "EASY"; } return "알 수 없음"; From 811a21cbff17b49289977a3c62c70e6462443944 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 12 Nov 2023 00:02:16 +0900 Subject: [PATCH 68/95] =?UTF-8?q?[fix]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=95=88=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0=20=EC=A4=91=EB=B3=B5=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/service/AuthService.java | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 0c2fb09..2b9e006 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -40,20 +40,15 @@ public BaseResponseDto googleLogin(String accessToken) { User user; boolean early; - Mono<GoogleUserResponseDto> userInfoMono = getUserGoogleInfo(accessToken); + Mono<GoogleUserResponseDto> userInfoMono = getUserInfo(accessToken, "https://www.googleapis.com/oauth2/v2/userinfo", GoogleUserResponseDto.class); GoogleUserResponseDto userInfo = userInfoMono.block(); Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); - log.info(String.valueOf(userInfo.getEmail())); - log.info(String.valueOf(userInfo.getPicture())); - log.info(String.valueOf(userInfo.getId())); - if(userData.isEmpty()){ user = User.builder() .userNumber(String.valueOf(userInfo.getId())) .roles("USER") - .profileImage(userInfo.getPicture()) .early(true) .build(); @@ -86,15 +81,9 @@ public BaseResponseDto kakaoLogin(String accessToken) { User user; boolean early; - Mono<KakaoUserResponseDto> userInfoMono = getUserKakaoInfo(accessToken); + Mono<KakaoUserResponseDto> userInfoMono = getUserInfo(accessToken, "https://kapi.kakao.com/v2/user/me", KakaoUserResponseDto.class); KakaoUserResponseDto userInfo = userInfoMono.block(); - - log.info(String.valueOf(userInfo.getKakao_account().getEmail())); - log.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfile_image_url())); - log.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); - - Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); @@ -102,7 +91,6 @@ public BaseResponseDto kakaoLogin(String accessToken) { user = User.builder() .userNumber(String.valueOf(userInfo.getId())) .roles("USER") - .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) .early(true) .build(); @@ -131,21 +119,13 @@ public BaseResponseDto kakaoLogin(String accessToken) { return baseResponseDto; } - public Mono<KakaoUserResponseDto> getUserKakaoInfo(String accessToken) { + public <T> Mono<T> getUserInfo(String accessToken, String apiUrl, Class<T> responseType) { return webClient .get() - .uri("https://kapi.kakao.com/v2/user/me") // 카카오 사용자 정보 엔드포인트 + .uri(apiUrl) .headers(headers -> headers.setBearerAuth(accessToken)) .retrieve() - .bodyToMono(KakaoUserResponseDto.class); + .bodyToMono(responseType); } - public Mono<GoogleUserResponseDto> getUserGoogleInfo(String accessToken) { - return webClient - .get() - .uri("https://www.googleapis.com/oauth2/v2/userinfo") // 카카오 사용자 정보 엔드포인트 - .headers(headers -> headers.setBearerAuth(accessToken)) - .retrieve() - .bodyToMono(GoogleUserResponseDto.class); - } } \ No newline at end of file From 70809d8cb0b6334d80217808dfa20b1645e7eba3 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 12 Nov 2023 02:46:31 +0900 Subject: [PATCH 69/95] =?UTF-8?q?[fix]=20=EB=8F=99=EA=B8=B0=20=EB=8B=A4?= =?UTF-8?q?=EB=8C=80=EB=8B=A4=20db=20=EC=88=98=EC=A0=95,=20=EB=8F=99?= =?UTF-8?q?=EA=B8=B0=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/fail/ErrorMessage.java | 5 +-- .../farmususer/user/entity/Motivation.java | 33 +++++++++++++++++++ .../user/entity/UserMotivation.java | 16 ++++++--- .../user/repository/MotivationRepository.java | 23 +++++++++++++ .../user/service/OnBoardingService.java | 15 +++++++-- 5 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/repository/MotivationRepository.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java index d219dc5..eb07736 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java @@ -9,8 +9,9 @@ public enum ErrorMessage { INTERVAL_SERVER_ERROR(1001, "요청을 처리하는 과정에서 서버가 예상하지 못한 오류가 발생하였습니다."), - REFRESH_NOTIFICATION_ERROR(4017, "Refresh Token 인증 오류"), - NO_USER_DATA(1002, "유저에 대한 정보가 없습니다."); + REFRESH_NOTIFICATION_ERROR(1002, "Refresh Token 인증 오류"), + NO_USER_DATA(1003, "유저에 대한 정보가 없습니다."), + NO_MOTIVATION_DATA(1004, "동기에 대한 정보가 없습니다."); diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java b/src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java new file mode 100644 index 0000000..4ae5584 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java @@ -0,0 +1,33 @@ +package modernfarmer.server.farmususer.user.entity; + +import lombok.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.util.LinkedHashSet; +import java.util.Set; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Entity +@Table(name = "motivation") +public class Motivation extends BaseEntity{ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "motivation_id", nullable = false) + private Long id; + + + @Column(name = "motivation_reason", nullable = false, length = 40) + private String motivationReason; + + @OneToMany(mappedBy = "motivation", fetch = FetchType.LAZY) + private Set<UserMotivation> userMotivations = new LinkedHashSet<>(); + + + +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java index 4dbbceb..c0d6d0f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java @@ -6,8 +6,6 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import java.time.Instant; @Builder @AllArgsConstructor @@ -28,10 +26,18 @@ public class UserMotivation extends BaseEntity{ @JoinColumn(name = "user_id", nullable = false) private User user; - @Size(max = 40) @NotNull - @Column(name = "user_motivation", nullable = false, length = 40) - private String userMotivation; + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) + @JoinColumn(name = "motivation_id", nullable = false) + private Motivation motivation; + + + + + + + diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/MotivationRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/MotivationRepository.java new file mode 100644 index 0000000..fcb6f50 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/MotivationRepository.java @@ -0,0 +1,23 @@ +package modernfarmer.server.farmususer.user.repository; + + +import modernfarmer.server.farmususer.user.entity.Motivation; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface MotivationRepository extends JpaRepository<Motivation, Long> { + + @Query("select m.id from Motivation as m where m.motivationReason = :motivationReason") + Long getMotivationId(@Param("motivationReason") String motivationReason); + + + Optional<Motivation> findByMotivationReason(String motivationReason); + + + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index 9e5766a..92433e6 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -9,16 +9,17 @@ import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.OnBoardingLevelResponse; +import modernfarmer.server.farmususer.user.entity.Motivation; import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.entity.UserMotivation; +import modernfarmer.server.farmususer.user.repository.MotivationRepository; import modernfarmer.server.farmususer.user.repository.UserMotivationRepository; import modernfarmer.server.farmususer.user.repository.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.transaction.Transactional; -import java.util.ArrayList; +import java.util.Optional; @RequiredArgsConstructor @@ -31,16 +32,24 @@ public class OnBoardingService { private final UserMotivationRepository userMotivationRepository; + private final MotivationRepository motivationRepository; + public BaseResponseDto onBoardingMotivation(Long userId, OnBoardingMotivationRequest onBoardingMotivationRequest){ User user = User.builder().id(userId).build(); for(String motivations : onBoardingMotivationRequest.getMotivation()){ + Optional<Motivation> motivation = motivationRepository.findByMotivationReason(motivations); + + if(motivation.isEmpty()){ + return BaseResponseDto.of(ErrorMessage.NO_MOTIVATION_DATA); + } + UserMotivation userMotivation = UserMotivation .builder() .user(user) - .userMotivation(motivations) + .motivation(motivation.get()) .build(); userMotivationRepository.save(userMotivation); From 38dea3037b6fe487ab6ccf50545c48739ba3eb35 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 12 Nov 2023 03:26:31 +0900 Subject: [PATCH 70/95] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4(+=EA=B0=80=EC=9E=85=20=ED=9B=84=20=EA=B2=BD=EA=B3=BC?= =?UTF-8?q?=20=EA=B8=B0=EA=B0=84)=20API=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 17 ++++++----- .../user/dto/response/GetUserResponseDto.java | 15 ++++++++++ .../farmususer/user/service/UserService.java | 15 ++++++++++ .../farmususer/user/util/TimeCalculator.java | 29 +++++++++++++++++++ 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 69e2f8f..4e7fc56 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -35,6 +35,16 @@ public class UserController { // // } + @GetMapping + public BaseResponseDto getUser(HttpServletRequest request){ + + String userId = jwtTokenProvider.getUserId(request); + + return userService.getUser(Long.valueOf(userId)); + } + + + @PostMapping(value = "/nickname") public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ @@ -91,11 +101,6 @@ public BaseResponseDto deleteUser(HttpServletRequest request){ return responseDto; } - - - - - @DeleteMapping("/logout") public BaseResponseDto logout(HttpServletRequest request) { @@ -135,6 +140,4 @@ public BaseResponseDto specificUser(@RequestParam("userId") Long userId) { return userService.specificUser(userId); } - - } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java new file mode 100644 index 0000000..a773ad2 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java @@ -0,0 +1,15 @@ +package modernfarmer.server.farmususer.user.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class GetUserResponseDto { + + private String nickName; + private String userImageUrl; + private long dDay; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 32a515a..92467e4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -9,6 +9,7 @@ import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import modernfarmer.server.farmususer.user.util.TimeCalculator; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ public class UserService { private final RedisTemplate<String, String> redisTemplate; private final UserRepository userRepository; private final S3Uploader s3Uploader; + private final TimeCalculator timeCalculator; // public BaseResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { @@ -42,6 +44,19 @@ public class UserService { // return BaseResponseDto.of(SuccessMessage.SUCCESS,null); // } + public BaseResponseDto getUser(Long userId){ + + Optional<User> user = userRepository.findById(userId); + + if(user.isEmpty()){ + return BaseResponseDto.of(ErrorMessage.NO_USER_DATA); + } + + long dDay = timeCalculator.calFromToday(user.get().getCreatedAt()); + + return BaseResponseDto.of(SuccessMessage.SUCCESS, GetUserResponseDto.of(user.get().getNickname(),user.get().getProfileImage(),dDay)); + } + public BaseResponseDto emitNickname(Long userId, String nickName){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java b/src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java new file mode 100644 index 0000000..f0bf2f4 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java @@ -0,0 +1,29 @@ +package modernfarmer.server.farmususer.user.util; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; + + +@Component +public class TimeCalculator { + + public long calFromToday(LocalDateTime date){ + + LocalDateTime currentDateTime = LocalDateTime.now(); + + // 날짜 차이 계산 + long daysDifference = ChronoUnit.DAYS.between(date.toLocalDate(), currentDateTime.toLocalDate()); + + + return daysDifference; + + } + + +} From c0588d9398ffe20eea4aca4b6f34e5aa678b2c67 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Sun, 12 Nov 2023 15:34:00 +0900 Subject: [PATCH 71/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=82=AC=EC=A7=84=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EC=8B=9C=20null=20=EC=B2=98=EB=A6=AC=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../server/farmususer/user/controller/UserController.java | 4 ++-- .../server/farmususer/user/service/UserService.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 8b0be59..d743e92 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_21/-유저-오픈-페인-API"] + branches: ["feature_25/유저-정보-조회"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 4e7fc56..f329e32 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -57,10 +57,10 @@ public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody Pro } @PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { + public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { String userId = jwtTokenProvider.getUserId(request); - log.info(userId); + BaseResponseDto responseDto = userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName); return responseDto; diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 92467e4..997e95e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -66,7 +66,7 @@ public BaseResponseDto emitNickname(Long userId, String nickName){ return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public BaseResponseDto selectProfileImageAndNickname(Long userId,MultipartFile multipartFile, + public BaseResponseDto selectProfileImageAndNickname(Long userId, MultipartFile multipartFile, String nickName) throws IOException { if(multipartFile.isEmpty()){ From 93d5f89bfce4c9a19933264437d28e87a0e30371 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Tue, 14 Nov 2023 01:52:04 +0900 Subject: [PATCH 72/95] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=82=AD=EC=A0=9C=20API=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/controller/UserController.java | 9 +++++++++ .../farmususer/user/repository/UserRepository.java | 4 ++++ .../server/farmususer/user/service/UserService.java | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index f329e32..79f4a3f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -127,6 +127,15 @@ public BaseResponseDto reissueToken(HttpServletRequest request) { return reissueTokenResponseDto; } + @PatchMapping(value = "/delete/user-profile") + public BaseResponseDto deleteUserProfile(HttpServletRequest request) { + + String userId = jwtTokenProvider.getUserId(request); + + return userService.deleteUserProfile(Long.valueOf(userId)); + } + + @GetMapping(value = "/all-user") public BaseResponseDto allUser() { diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 599e401..eb2dd76 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -33,6 +33,10 @@ public interface UserRepository extends JpaRepository<User, Long> { @Query("update User as u set u.early = 0 where u.id = :userId") void updateEarly( @Param("userId") Long userId); + @Modifying + @Query("update User as u set u.profileImage = null where u.id = :userId") + void updateUserProfileDefault( @Param("userId") Long userId); + // @Modifying // @Query("update User as u set u.profileImage = :profileImage where u.id = :userId") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 997e95e..d12b9b4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -120,6 +120,15 @@ public BaseResponseDto allUser() { } + public BaseResponseDto deleteUserProfile(Long userId) { + + userRepository.updateUserProfileDefault(userId); + + log.info("유저 프로필 삭제 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, null); + + } + public BaseResponseDto specificUser(Long userId) { From f7a17c3156e9e61145201efcc04a16177bbd724d Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Wed, 15 Nov 2023 15:06:20 +0900 Subject: [PATCH 73/95] =?UTF-8?q?[feat]=20=ED=8C=8C=EC=9D=B4=EC=96=B4?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=ED=86=A0=ED=81=B0=20=EC=82=BD?= =?UTF-8?q?=EC=9E=85=20API=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../user/controller/FirebaseController.java | 33 ++++++++++++++++ .../user/controller/UserController.java | 2 +- .../server/farmususer/user/entity/User.java | 1 - .../user/entity/UserFirebaseToken.java | 2 +- .../UserFirebaseTokenRepository.java | 11 ++++++ .../user/service/FirebaseService.java | 38 +++++++++++++++++++ .../farmususer/user/service/UserService.java | 8 ++++ .../user/util/JwtTokenProvider.java | 8 ++-- 9 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index d743e92..5a4ac71 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_25/유저-정보-조회"] + branches: ["feature_27/파이어베이스-관리"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java new file mode 100644 index 0000000..36af842 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java @@ -0,0 +1,33 @@ +package modernfarmer.server.farmususer.user.controller; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; +import modernfarmer.server.farmususer.user.service.FirebaseService; +import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@Slf4j +@RestController +@RequestMapping("/api/firebase") +@RequiredArgsConstructor +public class FirebaseController { + + private final JwtTokenProvider jwtTokenProvider; + private final FirebaseService firebaseService; + + + @PostMapping(value = "/insert-firebase-token") + public BaseResponseDto insertFirebaseToken(HttpServletRequest request) { + + String userId = jwtTokenProvider.getUserId(request); + String fireBaseToken = jwtTokenProvider.getFirebaseToken(request); + + return firebaseService.insertFirebaseToken(Long.valueOf(userId),fireBaseToken); + } + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 79f4a3f..d14809d 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -145,7 +145,7 @@ public BaseResponseDto allUser() { @GetMapping(value = "/specific-user") public BaseResponseDto specificUser(@RequestParam("userId") Long userId) { - // String userId = jwtTokenProvider.getUserId(request); + return userService.specificUser(userId); } diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index d23471b..a6f3578 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -6,7 +6,6 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import java.time.Instant; import java.util.LinkedHashSet; import java.util.Set; diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java index 5c97fb4..368fa30 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java @@ -20,7 +20,7 @@ public class UserFirebaseToken extends BaseEntity{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "firebase_token_id", nullable = false) - private Integer id; + private Long id; @Size(max = 100) @NotNull diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java new file mode 100644 index 0000000..618227a --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java @@ -0,0 +1,11 @@ +package modernfarmer.server.farmususer.user.repository; + + +import modernfarmer.server.farmususer.user.entity.UserFirebaseToken; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface UserFirebaseTokenRepository extends JpaRepository<UserFirebaseToken, Long> { +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java b/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java new file mode 100644 index 0000000..c640c9c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java @@ -0,0 +1,38 @@ +package modernfarmer.server.farmususer.user.service; + + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.config.s3.S3Uploader; +import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; +import modernfarmer.server.farmususer.user.entity.User; +import modernfarmer.server.farmususer.user.entity.UserFirebaseToken; +import modernfarmer.server.farmususer.user.repository.UserFirebaseTokenRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional +@Slf4j +@Service +public class FirebaseService { + + private final UserFirebaseTokenRepository userFirebaseTokenRepository; + + + public BaseResponseDto insertFirebaseToken(Long userId, String firebaseToken) { + + + UserFirebaseToken userFirebaseToken = UserFirebaseToken.builder() + .user(User.builder().id(userId).build()) + .token(firebaseToken) + .build(); + + + userFirebaseTokenRepository.save(userFirebaseToken); + + return BaseResponseDto.of(SuccessMessage.SUCCESS, null); + + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index d12b9b4..8ddb76b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -172,6 +172,14 @@ public BaseResponseDto reissueToken(String refreshToken, Long userId) { } + + + + + + + + public void deleteValueByKey(String key) { redisTemplate.delete(key); } diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 4671489..9e625a3 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -83,12 +83,12 @@ public String resolveToken(HttpServletRequest request) { } } - public String getUserRole(HttpServletRequest request) { - LOGGER.info("[resolveToken] HTTP 헤더에서 Token 값 추출"); + public String getFirebaseToken(HttpServletRequest request) { + LOGGER.info("[firebaseToken] HTTP 헤더에서 Token 값 추출"); - String tokenRole = request.getHeader("role"); + String firebaseToken = request.getHeader("FirebaseToken"); - return tokenRole; + return firebaseToken; } From 41e5a151beffc96ab87e256686e6a0f2975875c3 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Wed, 15 Nov 2023 19:20:42 +0900 Subject: [PATCH 74/95] =?UTF-8?q?[feat]=20=ED=8C=8C=EC=9D=B4=EC=96=B4?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=ED=86=A0=ED=81=B0=20=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/FirebaseController.java | 13 ++++++++++++- .../repository/UserFirebaseTokenRepository.java | 9 +++++++++ .../user/service/FirebaseService.java | 17 +++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java index 36af842..bea1699 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java @@ -5,6 +5,7 @@ import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.service.FirebaseService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -21,7 +22,7 @@ public class FirebaseController { private final FirebaseService firebaseService; - @PostMapping(value = "/insert-firebase-token") + @PostMapping(value = "/firebase-token") public BaseResponseDto insertFirebaseToken(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); @@ -30,4 +31,14 @@ public BaseResponseDto insertFirebaseToken(HttpServletRequest request) { return firebaseService.insertFirebaseToken(Long.valueOf(userId),fireBaseToken); } + + @DeleteMapping(value = "/firebase-token") + public BaseResponseDto deleteFirebaseToken(HttpServletRequest request) { + + String userId = jwtTokenProvider.getUserId(request); + String fireBaseToken = jwtTokenProvider.getFirebaseToken(request); + + return firebaseService.deleteFirebaseToken(Long.valueOf(userId),fireBaseToken); + } + } diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java index 618227a..6febea8 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserFirebaseTokenRepository.java @@ -1,11 +1,20 @@ package modernfarmer.server.farmususer.user.repository; +import io.lettuce.core.dynamic.annotation.Param; +import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.entity.UserFirebaseToken; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface UserFirebaseTokenRepository extends JpaRepository<UserFirebaseToken, Long> { + + + @Modifying + @Query("delete from UserFirebaseToken as uf where uf.user = :user and uf.token = :firebaseToken ") + void deleteFirebaseToken(@Param("user") User user, @Param("firebaseToken") String firebaseToken); } diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java b/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java index c640c9c..c06b6b5 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java @@ -29,10 +29,23 @@ public BaseResponseDto insertFirebaseToken(Long userId, String firebaseToken) { .token(firebaseToken) .build(); - userFirebaseTokenRepository.save(userFirebaseToken); - + log.info("파이어 베이스 토큰 삽입 완료"); return BaseResponseDto.of(SuccessMessage.SUCCESS, null); + } + + public BaseResponseDto deleteFirebaseToken(Long userId, String firebaseToken) { + + userFirebaseTokenRepository.deleteFirebaseToken( + User.builder() + .id(userId) + .build(), + firebaseToken + ); + + log.info("파이어 베이스 토큰 삭제 완료"); + + return BaseResponseDto.of(SuccessMessage.SUCCESS, null); } } From e2b06440ece3689a9b8939ca8ab39bcb05b830e7 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 17 Nov 2023 11:31:00 +0900 Subject: [PATCH 75/95] =?UTF-8?q?[feat]=20=ED=8C=8C=EC=9D=B4=EC=96=B4?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 ++ .../global/config/Firebase/FcmMessage.java | 31 +++++++++ .../Firebase/FirebaseCloudMessageService.java | 64 +++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FcmMessage.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FirebaseCloudMessageService.java diff --git a/build.gradle b/build.gradle index 63f32d2..1248b44 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,11 @@ dependencies { runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + + // firebase sdk + implementation 'com.google.firebase:firebase-admin:6.8.1' + // okhttp + implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2' } dependencyManagement { diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FcmMessage.java b/src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FcmMessage.java new file mode 100644 index 0000000..f19bfe7 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FcmMessage.java @@ -0,0 +1,31 @@ +package modernfarmer.server.farmususer.global.config.Firebase; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Builder +@AllArgsConstructor +@Getter +public class FcmMessage { + private boolean validate_only; + private Message message; + @Builder + @AllArgsConstructor + @Getter + public static class Message { + + private Notification notification; + + private String token; + } + @Builder + @AllArgsConstructor + @Getter + public static class Notification { + private String title; + private String body; + private String image; + + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FirebaseCloudMessageService.java b/src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FirebaseCloudMessageService.java new file mode 100644 index 0000000..608bded --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/config/Firebase/FirebaseCloudMessageService.java @@ -0,0 +1,64 @@ +package modernfarmer.server.farmususer.global.config.Firebase; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.auth.oauth2.GoogleCredentials; +import lombok.RequiredArgsConstructor; +import okhttp3.*; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.List; + +@Component +@RequiredArgsConstructor +public class FirebaseCloudMessageService { + + private final String API_URL = "https://fcm.googleapis.com/v1/projects/tourcash-13092/messages:send"; // 프론트에서 제공한 url + private final ObjectMapper objectMapper; + + public void sendMessageTo(String targetToken, String title, String body) throws IOException { + String message = makeMessage(targetToken, title, body); + OkHttpClient client = new OkHttpClient(); + RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8")); + Request request = new Request.Builder() + .url(API_URL) + .post(requestBody) + .addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + getAccessToken()) + .addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8") + .build(); + Response response = client.newCall(request) + .execute(); + + System.out.println(response.body().string()); + + } + private String makeMessage(String targetToken, String title, String body) throws JsonProcessingException { + FcmMessage fcmMessage = FcmMessage.builder() + .message(FcmMessage.Message.builder() + .token(targetToken) + .notification(FcmMessage.Notification.builder() + .title(title) + .body(body) + .image(null) + .build() + ).build() + ) + .validate_only(false) + .build(); + return objectMapper.writeValueAsString(fcmMessage); + } + + + private String getAccessToken() throws IOException { + String firebaseConfigPath = "firebase/firebase_service_key.json"; // 프론트에서 받은 파일을 해당 위치에 넣기 + GoogleCredentials googleCredentials = GoogleCredentials + .fromStream(new ClassPathResource(firebaseConfigPath).getInputStream()) + .createScoped(List.of("https://www.googleapis.com/auth/cloud-platform")); + googleCredentials.refreshIfExpired(); + return googleCredentials.getAccessToken().getTokenValue(); + } + +} From 9d7022dc509e7294bdacca1d4262729e4ff06b15 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 17 Nov 2023 12:56:41 +0900 Subject: [PATCH 76/95] =?UTF-8?q?[fix]=20=EC=A0=84=EC=B2=B4=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20(=EA=B2=BD=EA=B3=A0=20=EC=97=86=EC=95=A0=EA=B8=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/fail/ErrorMessage.java | 3 +- .../user/controller/AuthController.java | 26 ++---- .../user/controller/FirebaseController.java | 4 +- .../user/controller/OnBoardingController.java | 14 ++-- .../user/controller/UserController.java | 61 +++++--------- .../user/dto/response/BaseResponseDto.java | 8 +- .../farmususer/user/entity/Motivation.java | 2 +- .../server/farmususer/user/entity/User.java | 2 +- .../user/entity/UserFirebaseToken.java | 2 +- .../user/entity/UserMotivation.java | 2 +- .../user/repository/UserRepository.java | 4 +- .../farmususer/user/service/AuthService.java | 79 +++++++++++-------- .../user/service/FirebaseService.java | 5 +- .../user/service/OnBoardingService.java | 61 +++----------- .../farmususer/user/service/UserService.java | 42 +++++++--- .../farmususer/user/util/CustomerUser.java | 4 - .../user/util/JwtTokenProvider.java | 35 +++----- .../farmususer/user/util/LevelCheck.java | 47 +++++++++++ .../farmususer/user/util/SocialLogin.java | 22 ++++++ 19 files changed, 216 insertions(+), 207 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/user/util/CustomerUser.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/util/LevelCheck.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/util/SocialLogin.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java index eb07736..a38d996 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/fail/ErrorMessage.java @@ -11,7 +11,8 @@ public enum ErrorMessage { INTERVAL_SERVER_ERROR(1001, "요청을 처리하는 과정에서 서버가 예상하지 못한 오류가 발생하였습니다."), REFRESH_NOTIFICATION_ERROR(1002, "Refresh Token 인증 오류"), NO_USER_DATA(1003, "유저에 대한 정보가 없습니다."), - NO_MOTIVATION_DATA(1004, "동기에 대한 정보가 없습니다."); + NO_MOTIVATION_DATA(1004, "동기에 대한 정보가 없습니다."), + FAIL_GET_INFORMATION(1005, "소셜에서 정보를 가져오는데 실패했습니다."); diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java index 056a375..35f4d71 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/AuthController.java @@ -1,52 +1,40 @@ package modernfarmer.server.farmususer.user.controller; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.service.AuthService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; +@Slf4j @RequiredArgsConstructor @RestController @RequestMapping("/api/user/auth") public class AuthController { - private final Logger LOGGER = LoggerFactory.getLogger(AuthController.class); + private final AuthService authService; private final JwtTokenProvider jwtTokenProvider; @PostMapping(value = "/kakao-login") - public BaseResponseDto kakaoLogin(HttpServletRequest request) { + public BaseResponseDto<TokenResponseDto> kakaoLogin(HttpServletRequest request) { String accessToken = jwtTokenProvider.resolveToken(request); - BaseResponseDto reissueTokenResponseDto = authService.kakaoLogin(accessToken); - - LOGGER.info("카카오 로그인 완료"); - - return reissueTokenResponseDto; + return authService.kakaoLogin(accessToken); } @PostMapping(value = "/google-login") - public BaseResponseDto googleLogin(HttpServletRequest request) { + public BaseResponseDto<TokenResponseDto> googleLogin(HttpServletRequest request) { String accessToken = jwtTokenProvider.resolveToken(request); - BaseResponseDto tokenResponseDto = authService.googleLogin(accessToken); - - LOGGER.info("구글 로그인 완료"); - - return tokenResponseDto; + return authService.googleLogin(accessToken); } - - - } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java index bea1699..088a485 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/FirebaseController.java @@ -23,7 +23,7 @@ public class FirebaseController { @PostMapping(value = "/firebase-token") - public BaseResponseDto insertFirebaseToken(HttpServletRequest request) { + public BaseResponseDto<Void> insertFirebaseToken(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); String fireBaseToken = jwtTokenProvider.getFirebaseToken(request); @@ -33,7 +33,7 @@ public BaseResponseDto insertFirebaseToken(HttpServletRequest request) { @DeleteMapping(value = "/firebase-token") - public BaseResponseDto deleteFirebaseToken(HttpServletRequest request) { + public BaseResponseDto<Void> deleteFirebaseToken(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); String fireBaseToken = jwtTokenProvider.getFirebaseToken(request); diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java index 11461cb..7457f4d 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/OnBoardingController.java @@ -6,9 +6,9 @@ import modernfarmer.server.farmususer.user.dto.request.OnBoardingLevelRequest; import modernfarmer.server.farmususer.user.dto.request.OnBoardingMotivationRequest; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; +import modernfarmer.server.farmususer.user.dto.response.OnBoardingLevelResponse; import modernfarmer.server.farmususer.user.service.OnBoardingService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -27,22 +27,18 @@ public class OnBoardingController { @PostMapping(value = "/motivation") - public BaseResponseDto onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) { + public BaseResponseDto<Void> onBoardingMotivation(HttpServletRequest request, @Validated @RequestBody OnBoardingMotivationRequest onBoardingMotivationRequest) { String userId = jwtTokenProvider.getUserId(request); - BaseResponseDto responseDto = onBoardingService.onBoardingMotivation(Long.valueOf(userId),onBoardingMotivationRequest); - - return responseDto; + return onBoardingService.onBoardingMotivation(Long.valueOf(userId),onBoardingMotivationRequest); } @PostMapping(value = "/level") - public BaseResponseDto onBoardingLevel(HttpServletRequest request, @Validated @RequestBody OnBoardingLevelRequest onBoardingLevelRequest) { + public BaseResponseDto<OnBoardingLevelResponse> onBoardingLevel(HttpServletRequest request, @Validated @RequestBody OnBoardingLevelRequest onBoardingLevelRequest) { String userId = jwtTokenProvider.getUserId(request); - BaseResponseDto responseDto = onBoardingService.onBoardingLevel(Long.valueOf(userId), onBoardingLevelRequest); - - return responseDto; + return onBoardingService.onBoardingLevel(Long.valueOf(userId), onBoardingLevelRequest); } } diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index d14809d..00ba905 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -3,7 +3,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; -import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; +import modernfarmer.server.farmususer.user.dto.response.*; import modernfarmer.server.farmususer.user.service.UserService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; @@ -36,7 +36,7 @@ public class UserController { // } @GetMapping - public BaseResponseDto getUser(HttpServletRequest request){ + public BaseResponseDto<GetUserResponseDto> getUser(HttpServletRequest request){ String userId = jwtTokenProvider.getUserId(request); @@ -45,90 +45,68 @@ public BaseResponseDto getUser(HttpServletRequest request){ - @PostMapping(value = "/nickname") - public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ + public BaseResponseDto<Void> emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ String userId = jwtTokenProvider.getUserId(request); - BaseResponseDto responseDto = userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); - - return responseDto; + return userService.emitNickname(Long.valueOf(userId), produceNicknameRequest.getNickName()); } @PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { + public BaseResponseDto<Void> selectProfileImageAndNickname(HttpServletRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { String userId = jwtTokenProvider.getUserId(request); - BaseResponseDto responseDto = userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName); - - return responseDto; + return userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName); } @PatchMapping(value = "/sign-up/complete", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto signUpComplete(HttpServletRequest request) { + public BaseResponseDto<Void> signUpComplete(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); - - BaseResponseDto responseDto = userService.signUpComlete(Long.valueOf(userId)); - - return responseDto; + return userService.signUpComlete(Long.valueOf(userId)); } @GetMapping(value = "/profileImage") - public BaseResponseDto selectProfileImage(HttpServletRequest request){ + public BaseResponseDto<ProfileImageResponseDto> selectProfileImage(HttpServletRequest request){ String userId = jwtTokenProvider.getUserId(request); - - BaseResponseDto profileImageResponseDto = userService.selectProfileImage(Long.valueOf(userId)); - - return profileImageResponseDto; + return userService.selectProfileImage(Long.valueOf(userId)); } @DeleteMapping(value = "/delete") - public BaseResponseDto deleteUser(HttpServletRequest request){ + public BaseResponseDto<Void> deleteUser(HttpServletRequest request){ String userId = jwtTokenProvider.getUserId(request); - BaseResponseDto responseDto = userService.deleteUser(Long.valueOf(userId)); - - return responseDto; + return userService.deleteUser(Long.valueOf(userId)); } @DeleteMapping("/logout") - public BaseResponseDto logout(HttpServletRequest request) { - + public BaseResponseDto<Void> logout(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); - BaseResponseDto logoutResponseDto = userService.logout(Long.valueOf(userId)); - - log.info("로그아웃 완료"); - - return logoutResponseDto; + return userService.logout(Long.valueOf(userId)); } @GetMapping(value = "/reissue-token") - public BaseResponseDto reissueToken(HttpServletRequest request) { + public BaseResponseDto<RefreshTokenResponseDto> reissueToken(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); String refreshToken = jwtTokenProvider.resolveToken(request); - BaseResponseDto reissueTokenResponseDto = userService.reissueToken(refreshToken, Long.valueOf(userId)); - - log.info("토큰 재발급 완료"); - - return reissueTokenResponseDto; + return userService.reissueToken(refreshToken, Long.valueOf(userId)); } @PatchMapping(value = "/delete/user-profile") - public BaseResponseDto deleteUserProfile(HttpServletRequest request) { + public BaseResponseDto<Void> deleteUserProfile(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); @@ -137,14 +115,13 @@ public BaseResponseDto deleteUserProfile(HttpServletRequest request) { @GetMapping(value = "/all-user") - public BaseResponseDto allUser() { + public BaseResponseDto<AllUserResponseDto> allUser() { return userService.allUser(); } @GetMapping(value = "/specific-user") - public BaseResponseDto specificUser(@RequestParam("userId") Long userId) { - + public BaseResponseDto<SpecificUserResponseDto> specificUser(@RequestParam("userId") Long userId) { return userService.specificUser(userId); } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java index 85df827..1fb57da 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/BaseResponseDto.java @@ -19,18 +19,18 @@ public class BaseResponseDto<T> { @JsonInclude(JsonInclude.Include.NON_NULL) private T data; - public static <T> BaseResponseDto of(SuccessMessage successMessage, T data){ + public static <T> BaseResponseDto<T> of(SuccessMessage successMessage, T data){ - return BaseResponseDto.builder() + return BaseResponseDto.<T>builder() .code(successMessage.getCode()) .message(successMessage.getMessage()) .data(data) .build(); } - public static <T> BaseResponseDto of(ErrorMessage errorMessage){ + public static <T> BaseResponseDto<T> of(ErrorMessage errorMessage){ - return BaseResponseDto.builder() + return BaseResponseDto.<T>builder() .code(errorMessage.getCode()) .message(errorMessage.getMessage()) .build(); diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java b/src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java index 4ae5584..273f867 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/Motivation.java @@ -11,7 +11,7 @@ @Builder @AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Entity @Table(name = "motivation") diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java index a6f3578..4e40753 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/User.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/User.java @@ -12,7 +12,7 @@ @Getter @Entity @Builder -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Table(name = "users") public class User extends BaseEntity{ diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java index 368fa30..d9ad3cb 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java @@ -11,7 +11,7 @@ @Builder @AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Setter @Entity diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java index c0d6d0f..9c5d852 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java @@ -9,7 +9,7 @@ @Builder @AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Setter @Entity diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index eb2dd76..122251f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -2,6 +2,7 @@ import io.lettuce.core.dynamic.annotation.Param; import modernfarmer.server.farmususer.user.entity.User; +import org.jetbrains.annotations.NotNull; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -55,7 +56,8 @@ public interface UserRepository extends JpaRepository<User, Long> { List<User> findAllBy(); - Optional<User> findById(Long userId); + @NotNull + Optional<User> findById(@NotNull Long userId); diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 2b9e006..edebd64 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; @@ -11,10 +12,9 @@ import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; -import org.springframework.beans.factory.annotation.Autowired; +import modernfarmer.server.farmususer.user.util.SocialLogin; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; -import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; import java.util.Optional; @@ -28,21 +28,28 @@ public class AuthService{ private final JwtTokenProvider jwtTokenProvider; + private final RedisTemplate<String, String> redisTemplate; private final UserRepository userRepository; - private final WebClient webClient; + private final SocialLogin socialLogin; - public BaseResponseDto googleLogin(String accessToken) { + public BaseResponseDto<TokenResponseDto> googleLogin(String accessToken) { User user; boolean early; - Mono<GoogleUserResponseDto> userInfoMono = getUserInfo(accessToken, "https://www.googleapis.com/oauth2/v2/userinfo", GoogleUserResponseDto.class); + Mono<GoogleUserResponseDto> userInfoMono = socialLogin.getUserInfo(accessToken, "https://www.googleapis.com/oauth2/v2/userinfo", GoogleUserResponseDto.class); GoogleUserResponseDto userInfo = userInfoMono.block(); + if(userInfo == null){ + + return BaseResponseDto.of(ErrorMessage.FAIL_GET_INFORMATION); + + } + Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); if(userData.isEmpty()){ @@ -57,11 +64,21 @@ public BaseResponseDto googleLogin(String accessToken) { Optional<User> userLoginData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); + if(userLoginData.isEmpty()){ + + return BaseResponseDto.of(ErrorMessage.FAIL_GET_INFORMATION); + + } + String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); early = userLoginData.get().isEarly(); - BaseResponseDto baseResponseDto = BaseResponseDto.of( + redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); + + log.info("구글 로그인 완료"); + + return BaseResponseDto.of( SuccessMessage.SUCCESS, TokenResponseDto.of( jwtTokenProvider.createAccessToken( @@ -71,19 +88,21 @@ public BaseResponseDto googleLogin(String accessToken) { early ) ); - - redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); - - return baseResponseDto; } - public BaseResponseDto kakaoLogin(String accessToken) { + public BaseResponseDto<TokenResponseDto> kakaoLogin(String accessToken) { User user; boolean early; - Mono<KakaoUserResponseDto> userInfoMono = getUserInfo(accessToken, "https://kapi.kakao.com/v2/user/me", KakaoUserResponseDto.class); + Mono<KakaoUserResponseDto> userInfoMono = socialLogin.getUserInfo(accessToken, "https://kapi.kakao.com/v2/user/me", KakaoUserResponseDto.class); KakaoUserResponseDto userInfo = userInfoMono.block(); + if(userInfo == null){ + + return BaseResponseDto.of(ErrorMessage.FAIL_GET_INFORMATION); + + } + Optional<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); @@ -99,33 +118,31 @@ public BaseResponseDto kakaoLogin(String accessToken) { Optional<User> userLoginData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); + if(userLoginData.isEmpty()){ + + return BaseResponseDto.of(ErrorMessage.FAIL_GET_INFORMATION); + + } + early = userLoginData.get().isEarly(); String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); - BaseResponseDto baseResponseDto = BaseResponseDto.of( - SuccessMessage.SUCCESS, - TokenResponseDto.of( - jwtTokenProvider.createAccessToken( - userLoginData.get().getId(), - String.valueOf(userLoginData.get().getRoles())), - refreshToken, - early - ) - ); redisTemplate.opsForValue().set(String.valueOf(userLoginData.get().getId()),refreshToken); - return baseResponseDto; - } + log.info("카카오 로그인 완료"); - public <T> Mono<T> getUserInfo(String accessToken, String apiUrl, Class<T> responseType) { - return webClient - .get() - .uri(apiUrl) - .headers(headers -> headers.setBearerAuth(accessToken)) - .retrieve() - .bodyToMono(responseType); + return BaseResponseDto.of( + SuccessMessage.SUCCESS, + TokenResponseDto.of( + jwtTokenProvider.createAccessToken( + userLoginData.get().getId(), + String.valueOf(userLoginData.get().getRoles())), + refreshToken, + early + ) + ); } } \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java b/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java index c06b6b5..60531b5 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/FirebaseService.java @@ -3,7 +3,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import modernfarmer.server.farmususer.global.config.s3.S3Uploader; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; import modernfarmer.server.farmususer.user.entity.User; @@ -21,7 +20,7 @@ public class FirebaseService { private final UserFirebaseTokenRepository userFirebaseTokenRepository; - public BaseResponseDto insertFirebaseToken(Long userId, String firebaseToken) { + public BaseResponseDto<Void> insertFirebaseToken(Long userId, String firebaseToken) { UserFirebaseToken userFirebaseToken = UserFirebaseToken.builder() @@ -34,7 +33,7 @@ public BaseResponseDto insertFirebaseToken(Long userId, String firebaseToken) { return BaseResponseDto.of(SuccessMessage.SUCCESS, null); } - public BaseResponseDto deleteFirebaseToken(Long userId, String firebaseToken) { + public BaseResponseDto<Void> deleteFirebaseToken(Long userId, String firebaseToken) { userFirebaseTokenRepository.deleteFirebaseToken( diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java index 92433e6..12a9ae6 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/OnBoardingService.java @@ -15,6 +15,7 @@ import modernfarmer.server.farmususer.user.repository.MotivationRepository; import modernfarmer.server.farmususer.user.repository.UserMotivationRepository; import modernfarmer.server.farmususer.user.repository.UserRepository; +import modernfarmer.server.farmususer.user.util.LevelCheck; import org.springframework.stereotype.Service; @@ -34,7 +35,9 @@ public class OnBoardingService { private final MotivationRepository motivationRepository; - public BaseResponseDto onBoardingMotivation(Long userId, OnBoardingMotivationRequest onBoardingMotivationRequest){ + private final LevelCheck levelCheck; + + public BaseResponseDto<Void> onBoardingMotivation(Long userId, OnBoardingMotivationRequest onBoardingMotivationRequest){ User user = User.builder().id(userId).build(); @@ -55,65 +58,21 @@ public BaseResponseDto onBoardingMotivation(Long userId, OnBoardingMotivationReq userMotivationRepository.save(userMotivation); } + log.info("동기 데이터 삽입 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public BaseResponseDto onBoardingLevel(Long userId, OnBoardingLevelRequest onBoardingLevelRequest){ + public BaseResponseDto<OnBoardingLevelResponse> onBoardingLevel(Long userId, OnBoardingLevelRequest onBoardingLevelRequest){ - String level = recommendAlgorithms(onBoardingLevelRequest.getTime(), onBoardingLevelRequest.getSkill()); + String level = levelCheck.recommendAlgorithms(onBoardingLevelRequest.getTime(), onBoardingLevelRequest.getSkill()); userRepository.insertUserLevel(userId, level); - return BaseResponseDto.of(SuccessMessage.SUCCESS, OnBoardingLevelResponse.of(level)); - - } - - private String recommendAlgorithms(int time,String skill) { - boolean isIntermediate = false; - boolean isMaster = false; - boolean isElementary = false; - boolean isBeginner = false; - - - if ("홈파밍 중급".equals(skill)) { - isIntermediate = true; - } else if ("홈파밍 고수".equals(skill)) { - isMaster = true; - } else if ("홈파밍 초보".equals(skill)) { - isElementary = true; - } else if ("홈파밍 입문".equals(skill)) { - isBeginner = true; - } - + log.info("난이도 데이터 삽입 완료"); - if (time == 2 && (isIntermediate || isMaster)) { - return "HARD"; - } else if (time == 2 && (isBeginner || isElementary)) { - return "NORMAL"; - } else if (time == 1 && isMaster) { - return "HARD"; - } else if (time == 1 && (isIntermediate || isElementary)) { - return "NORMAL"; - } else if (time == 1 && isBeginner) { - return "EASY"; - } else if (time == 0 && isMaster) { - return "HARD"; - } else if (time == 0 && isIntermediate) { - return "NORMAL"; - } else if (time == 0 && (isElementary || isBeginner)) { - return "EASY"; - } + return BaseResponseDto.of(SuccessMessage.SUCCESS, OnBoardingLevelResponse.of(level)); - return "알 수 없음"; } - - - - - - - - - } diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 8ddb76b..00863e1 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -44,7 +44,7 @@ public class UserService { // return BaseResponseDto.of(SuccessMessage.SUCCESS,null); // } - public BaseResponseDto getUser(Long userId){ + public BaseResponseDto<GetUserResponseDto> getUser(Long userId){ Optional<User> user = userRepository.findById(userId); @@ -54,19 +54,23 @@ public BaseResponseDto getUser(Long userId){ long dDay = timeCalculator.calFromToday(user.get().getCreatedAt()); + log.info("특정 유저 정보 가져오기 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, GetUserResponseDto.of(user.get().getNickname(),user.get().getProfileImage(),dDay)); } - public BaseResponseDto emitNickname(Long userId, String nickName){ + public BaseResponseDto<Void> emitNickname(Long userId, String nickName){ userRepository.updateUserNickname(nickName, userId); + log.info("닉네임 수정 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public BaseResponseDto selectProfileImageAndNickname(Long userId, MultipartFile multipartFile, + public BaseResponseDto<Void> selectProfileImageAndNickname(Long userId, MultipartFile multipartFile, String nickName) throws IOException { if(multipartFile.isEmpty()){ @@ -79,48 +83,58 @@ public BaseResponseDto selectProfileImageAndNickname(Long userId, MultipartFile userRepository.selectUserProfileAndNickname(userId,imageUrl,nickName); } + + log.info("유저 프로필 정보 수정 완료"); return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public BaseResponseDto selectProfileImage(Long userId){ + public BaseResponseDto<ProfileImageResponseDto> selectProfileImage(Long userId){ String userProfileImage = userRepository.selectUserProfileImage(userId); + log.info("유저 프로필 이미지 조회 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, ProfileImageResponseDto.of(userProfileImage)); } - public BaseResponseDto signUpComlete(Long userId){ + public BaseResponseDto<Void> signUpComlete(Long userId){ userRepository.updateEarly(userId); + log.info("유저 최종 회원가입 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, null); } - public BaseResponseDto deleteUser(Long userId){ + public BaseResponseDto<Void> deleteUser(Long userId){ userRepository.deleteUser(userId); + log.info("유저 계정 삭제 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public BaseResponseDto allUser() { + public BaseResponseDto<AllUserResponseDto> allUser() { List<User> userList = userRepository.findAllBy(); List<AllUserDto> userResponseList = userList.stream() .map(user -> AllUserDto.of(user.getId(), user.getNickname(), user.getProfileImage())) .collect(Collectors.toList()); + log.info("모든 유저 데이터 조회 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, AllUserResponseDto.of(userResponseList)); } - public BaseResponseDto deleteUserProfile(Long userId) { + public BaseResponseDto<Void> deleteUserProfile(Long userId) { userRepository.updateUserProfileDefault(userId); @@ -129,7 +143,7 @@ public BaseResponseDto deleteUserProfile(Long userId) { } - public BaseResponseDto specificUser(Long userId) { + public BaseResponseDto<SpecificUserResponseDto> specificUser(Long userId) { Optional<User> user = userRepository.findById(userId); @@ -138,6 +152,8 @@ public BaseResponseDto specificUser(Long userId) { return BaseResponseDto.of(ErrorMessage.NO_USER_DATA); } + log.info("특정 유저 정보 조회 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, SpecificUserResponseDto.of(user.get().getId(), user.get().getNickname(), @@ -146,14 +162,16 @@ public BaseResponseDto specificUser(Long userId) { } - public BaseResponseDto logout(Long userId) { + public BaseResponseDto<Void> logout(Long userId) { deleteValueByKey(String.valueOf(userId)); + log.info("로그아웃 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public BaseResponseDto reissueToken(String refreshToken, Long userId) { + public BaseResponseDto<RefreshTokenResponseDto> reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); @@ -161,6 +179,8 @@ public BaseResponseDto reissueToken(String refreshToken, Long userId) { String userRole = userRepository.findUserRole(userId); + log.info("토큰 재발급 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, RefreshTokenResponseDto.of( jwtTokenProvider.createAccessToken(userId, userRole), diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/CustomerUser.java b/src/main/java/modernfarmer/server/farmususer/user/util/CustomerUser.java deleted file mode 100644 index 06665f0..0000000 --- a/src/main/java/modernfarmer/server/farmususer/user/util/CustomerUser.java +++ /dev/null @@ -1,4 +0,0 @@ -package modernfarmer.server.farmususer.user.util; - -public class CustomerUser { -} diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 9e625a3..3a82efc 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -5,6 +5,7 @@ import io.jsonwebtoken.Jws; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -16,10 +17,11 @@ import java.util.Base64; import java.util.Date; + +@Slf4j @Component public class JwtTokenProvider { - private final Logger LOGGER = LoggerFactory.getLogger(JwtTokenProvider.class); @Value("${jwt.secret}") @@ -33,9 +35,9 @@ public class JwtTokenProvider { @PostConstruct protected void init() { - LOGGER.info("[init] JwtTokenProvider 내 secretKey 초기화 시작", StandardCharsets.UTF_8); + log.info("[init] JwtTokenProvider 내 secretKey 초기화 시작"); secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes(StandardCharsets.UTF_8)); - LOGGER.info("[init] JwtTokenProvider 내 secretKey 초기화 완료"); + log.info("[init] JwtTokenProvider 내 secretKey 초기화 완료"); } public String createAccessToken(Long userId, String roles) { // 토큰 생성 @@ -48,10 +50,10 @@ public String createAccessToken(Long userId, String roles) { // 토 .setClaims(claims) .setIssuedAt(now) .setExpiration(new Date(now.getTime() + accessTokenTime)) - .signWith(SignatureAlgorithm.HS256, secretKey) // 암호화 알고리즘, secret 값 세팅 + .signWith(SignatureAlgorithm.HS256, secretKey) .compact(); - LOGGER.info("[createToken] 토큰 생성 완료"); + log.info("[createToken] 토큰 생성 완료"); return token; } @@ -66,12 +68,11 @@ public String createRefreshToken(Long userId) { // 토큰 생성 .signWith(SignatureAlgorithm.HS256, secretKey) // 암호화 알고리즘, secret 값 세팅 .compact(); - LOGGER.info("[createToken] 토큰 생성 완료"); + log.info("[createToken] 토큰 생성 완료"); return token; } public String resolveToken(HttpServletRequest request) { - LOGGER.info("[resolveToken] HTTP 헤더에서 Token 값 추출"); String tokenHeader = request.getHeader("Authorization"); @@ -84,33 +85,17 @@ public String resolveToken(HttpServletRequest request) { } public String getFirebaseToken(HttpServletRequest request) { - LOGGER.info("[firebaseToken] HTTP 헤더에서 Token 값 추출"); - String firebaseToken = request.getHeader("FirebaseToken"); - - return firebaseToken; + return request.getHeader("FirebaseToken"); } public String getUserId(HttpServletRequest request) { - LOGGER.info("[resolveToken] HTTP 헤더에서 Token 값 추출"); - - String tokenUser = request.getHeader("user"); - return tokenUser; + return request.getHeader("user"); } - public boolean validateRefreshToken(String token) { // 토큰 유효성 확인 - LOGGER.info("[validateRefreshToken] 토큰 유효 체크 시작"); - Jws<Claims> claims = Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token); - - if (!claims.getBody().isEmpty()) { - LOGGER.info("[validateRefreshToken] 토큰 유효 체크 완료"); - return true; - } - return false; - } } diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/LevelCheck.java b/src/main/java/modernfarmer/server/farmususer/user/util/LevelCheck.java new file mode 100644 index 0000000..44008f5 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/util/LevelCheck.java @@ -0,0 +1,47 @@ +package modernfarmer.server.farmususer.user.util; + + +import org.springframework.stereotype.Component; + +@Component +public class LevelCheck { + + public String recommendAlgorithms(int time,String skill) { + boolean isIntermediate = false; + boolean isMaster = false; + boolean isElementary = false; + boolean isBeginner = false; + + + if ("홈파밍 중급".equals(skill)) { + isIntermediate = true; + } else if ("홈파밍 고수".equals(skill)) { + isMaster = true; + } else if ("홈파밍 초보".equals(skill)) { + isElementary = true; + } else if ("홈파밍 입문".equals(skill)) { + isBeginner = true; + } + + + if (time == 2 && (isIntermediate || isMaster)) { + return "HARD"; + } else if (time == 2 && (isBeginner || isElementary)) { + return "NORMAL"; + } else if (time == 1 && isMaster) { + return "HARD"; + } else if (time == 1 && (isIntermediate || isElementary)) { + return "NORMAL"; + } else if (time == 1 && isBeginner) { + return "EASY"; + } else if (time == 0 && isMaster) { + return "HARD"; + } else if (time == 0 && isIntermediate) { + return "NORMAL"; + } else if (time == 0 && (isElementary || isBeginner)) { + return "EASY"; + } + + return "알 수 없음"; + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/SocialLogin.java b/src/main/java/modernfarmer/server/farmususer/user/util/SocialLogin.java new file mode 100644 index 0000000..d9199ed --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/util/SocialLogin.java @@ -0,0 +1,22 @@ +package modernfarmer.server.farmususer.user.util; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +@Component +public class SocialLogin { + + private final WebClient webClient; + + public <T> Mono<T> getUserInfo(String accessToken, String apiUrl, Class<T> responseType) { + return webClient + .get() + .uri(apiUrl) + .headers(headers -> headers.setBearerAuth(accessToken)) + .retrieve() + .bodyToMono(responseType); + } +} From 72004f0ddd6feb428a6defeb9b6641acbbaeaa12 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 17 Nov 2023 12:58:14 +0900 Subject: [PATCH 77/95] =?UTF-8?q?[fix]=20=EB=B0=B0=ED=8F=AC=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5a4ac71..1aba6a3 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_27/파이어베이스-관리"] + branches: ["feature_29/코드-정리"] pull_request: branches: ["dev"] From 5245dd8df9b443a307d9436a6fd10f296884773b Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Fri, 17 Nov 2023 13:21:18 +0900 Subject: [PATCH 78/95] =?UTF-8?q?[fix]=20config=20redis=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/global/config/redis/RedisConfig.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/global/config/redis/RedisConfig.java b/src/main/java/modernfarmer/server/farmususer/global/config/redis/RedisConfig.java index 721dceb..8e60cd9 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/config/redis/RedisConfig.java +++ b/src/main/java/modernfarmer/server/farmususer/global/config/redis/RedisConfig.java @@ -24,8 +24,7 @@ public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); redisStandaloneConfiguration.setHostName(redisHost); redisStandaloneConfiguration.setPort(Integer.parseInt(redisPort)); - LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration); - return lettuceConnectionFactory; + return new LettuceConnectionFactory(redisStandaloneConfiguration); } @Bean From 87c5d15cbee431d8efb6270c8debccb52aa93da6 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 20 Nov 2023 13:37:46 +0900 Subject: [PATCH 79/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EB=A0=88=EC=B9=B4=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5a4ac71..af2b10a 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -7,6 +7,7 @@ on: pull_request: branches: ["dev"] + permissions: contents: read From 103f4eb47e7863cd9f616bfd2b5a4850f5fc6a9d Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 20 Nov 2023 15:40:07 +0900 Subject: [PATCH 80/95] =?UTF-8?q?[feat]=20farm,=20community=20=EC=98=A4?= =?UTF-8?q?=ED=94=88=20=ED=8E=98=EC=9D=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/CommunityServiceFeignClient.java | 18 ++++++++++++++++++ .../farm/FarmServiceFeignClient.java | 14 ++++++++++++++ .../farmususer/user/service/UserService.java | 11 +++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java create mode 100644 src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java diff --git a/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java new file mode 100644 index 0000000..4ecc013 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java @@ -0,0 +1,18 @@ +package modernfarmer.server.farmususer.community; + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient(name = "community-service") +public interface CommunityServiceFeignClient { + + @DeleteMapping("/api/community/posting/all-posting") + Void deleteAllPosting(Long userId); + + + + +} diff --git a/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java new file mode 100644 index 0000000..a39f7ab --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java @@ -0,0 +1,14 @@ +package modernfarmer.server.farmususer.farm; + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient(name = "farm-service") +public interface FarmServiceFeignClient { + + @DeleteMapping("/api/veggie/{userId}") + Void deleteAllFarm(@PathVariable("userId") Long userId); + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 00863e1..85d5da8 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -2,6 +2,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.community.CommunityServiceFeignClient; +import modernfarmer.server.farmususer.farm.FarmServiceFeignClient; import modernfarmer.server.farmususer.global.config.s3.S3Uploader; import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; @@ -32,6 +34,8 @@ public class UserService { private final UserRepository userRepository; private final S3Uploader s3Uploader; private final TimeCalculator timeCalculator; + private final CommunityServiceFeignClient communityServiceFeignClient; + private final FarmServiceFeignClient farmServiceFeignClient; // public BaseResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { @@ -114,6 +118,13 @@ public BaseResponseDto<Void> deleteUser(Long userId){ userRepository.deleteUser(userId); + farmServiceFeignClient.deleteAllFarm(userId); + + communityServiceFeignClient.deleteAllPosting(userId); + + + + log.info("유저 계정 삭제 완료"); return BaseResponseDto.of(SuccessMessage.SUCCESS,null); From 6129d9a0a492da1c0b4e866e43fa4a39ba8cc568 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 20 Nov 2023 15:44:42 +0900 Subject: [PATCH 81/95] =?UTF-8?q?[feat]=20farm,=20community=20=EC=98=A4?= =?UTF-8?q?=ED=94=88=20=ED=8E=98=EC=9D=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index b64cef6..9b13c4d 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_29/코드-정리"] + branches: ["feature_32/계정-삭제-api"] pull_request: branches: ["dev"] From 6ee84f3caf947cd007844103da36875fda780bfb Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 20 Nov 2023 16:09:18 +0900 Subject: [PATCH 82/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EB=A0=88=EC=B9=B4=20?= =?UTF-8?q?=ED=95=B4=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/community/CommunityServiceFeignClient.java | 2 +- .../server/farmususer/farm/FarmServiceFeignClient.java | 2 +- .../server/farmususer/user/service/UserService.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java index 4ecc013..9b2cc3a 100644 --- a/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java +++ b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java @@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; -@FeignClient(name = "community-service") +@FeignClient(name = "community-service", url = "http://3.38.2.59:8082") public interface CommunityServiceFeignClient { @DeleteMapping("/api/community/posting/all-posting") diff --git a/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java index a39f7ab..3dedfb3 100644 --- a/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java +++ b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; -@FeignClient(name = "farm-service") +@FeignClient(name = "farm-service", url = "http://3.36.221.140:8081") public interface FarmServiceFeignClient { @DeleteMapping("/api/veggie/{userId}") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 85d5da8..9469e87 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -117,10 +117,10 @@ public BaseResponseDto<Void> signUpComlete(Long userId){ public BaseResponseDto<Void> deleteUser(Long userId){ userRepository.deleteUser(userId); - + communityServiceFeignClient.deleteAllPosting(userId); farmServiceFeignClient.deleteAllFarm(userId); - communityServiceFeignClient.deleteAllPosting(userId); + From 3060bed82223f606d6720b724344f2a153448f02 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 20 Nov 2023 16:58:37 +0900 Subject: [PATCH 83/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EB=A0=88=EC=B9=B4=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/community/CommunityServiceFeignClient.java | 8 +++++--- .../server/farmususer/farm/FarmServiceFeignClient.java | 4 ++-- .../server/farmususer/user/service/UserService.java | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java index 9b2cc3a..5973a2d 100644 --- a/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java +++ b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java @@ -1,16 +1,18 @@ package modernfarmer.server.farmususer.community; +import modernfarmer.server.farmususer.user.dto.response.BaseResponseDto; +import modernfarmer.server.farmususer.user.entity.BaseEntity; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; -@FeignClient(name = "community-service", url = "http://3.38.2.59:8082") +@FeignClient(name = "community-service") public interface CommunityServiceFeignClient { - @DeleteMapping("/api/community/posting/all-posting") - Void deleteAllPosting(Long userId); + @DeleteMapping("/api/community/posting/all-posting/{userId}") + void deleteAllPosting(@PathVariable("userId") Long userId); diff --git a/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java index 3dedfb3..7954bae 100644 --- a/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java +++ b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java @@ -5,10 +5,10 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; -@FeignClient(name = "farm-service", url = "http://3.36.221.140:8081") +@FeignClient(name = "farm-service") public interface FarmServiceFeignClient { @DeleteMapping("/api/veggie/{userId}") - Void deleteAllFarm(@PathVariable("userId") Long userId); + void deleteAllVeggies(@PathVariable("userId") Long userId); } diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 9469e87..d6eea49 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -118,7 +118,7 @@ public BaseResponseDto<Void> deleteUser(Long userId){ userRepository.deleteUser(userId); communityServiceFeignClient.deleteAllPosting(userId); - farmServiceFeignClient.deleteAllFarm(userId); + farmServiceFeignClient.deleteAllVeggies(userId); From 608f44f3e5c565293eb5b3dad85c787f6e5712cb Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 20 Nov 2023 18:28:35 +0900 Subject: [PATCH 84/95] =?UTF-8?q?[fix]=20=ED=8C=9C=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index d6eea49..a87fedf 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -118,7 +118,7 @@ public BaseResponseDto<Void> deleteUser(Long userId){ userRepository.deleteUser(userId); communityServiceFeignClient.deleteAllPosting(userId); - farmServiceFeignClient.deleteAllVeggies(userId); + // farmServiceFeignClient.deleteAllVeggies(userId); From f5c01d2ca9297e4b8742d3ad2f828f0de3a6e537 Mon Sep 17 00:00:00 2001 From: seungryeol <opop0421@naver.com> Date: Mon, 20 Nov 2023 19:22:48 +0900 Subject: [PATCH 85/95] =?UTF-8?q?[fix]=20entity=20cascade=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/entity/UserFirebaseToken.java | 3 +-- .../server/farmususer/user/entity/UserMotivation.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java index d9ad3cb..6f6968f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserFirebaseToken.java @@ -28,8 +28,7 @@ public class UserFirebaseToken extends BaseEntity{ private String token; @NotNull - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @OnDelete(action = OnDeleteAction.CASCADE) + @ManyToOne(fetch = FetchType.LAZY, optional = false, cascade = CascadeType.REMOVE) @JoinColumn(name = "user_id", nullable = false) private User user; diff --git a/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java index 9c5d852..1a7e9c6 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java +++ b/src/main/java/modernfarmer/server/farmususer/user/entity/UserMotivation.java @@ -27,8 +27,7 @@ public class UserMotivation extends BaseEntity{ private User user; @NotNull - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @OnDelete(action = OnDeleteAction.CASCADE) + @ManyToOne(fetch = FetchType.LAZY, optional = false, cascade = CascadeType.REMOVE) @JoinColumn(name = "motivation_id", nullable = false) private Motivation motivation; From 8e4eb8ff689173f1555609a4afcab382669d2d93 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Tue, 21 Nov 2023 02:48:33 +0900 Subject: [PATCH 86/95] =?UTF-8?q?[feat]=20=ED=8E=98=EC=9D=B8=EC=9A=A9=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=82=9C=EC=9D=B4=EB=8F=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/controller/UserController.java | 6 +++++- .../server/farmususer/user/service/UserService.java | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 00ba905..f245b6f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; import modernfarmer.server.farmususer.user.dto.response.*; @@ -43,7 +44,10 @@ public BaseResponseDto<GetUserResponseDto> getUser(HttpServletRequest request){ return userService.getUser(Long.valueOf(userId)); } - + @GetMapping("/level") + public String getUserLevel(@RequestHeader("user") Long userId){ + return userService.getUserLevel(userId); + } @PostMapping(value = "/nickname") public BaseResponseDto<Void> emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 00863e1..a1ce8ca 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -192,7 +192,12 @@ public BaseResponseDto<RefreshTokenResponseDto> reissueToken(String refreshToken } + public String getUserLevel(Long userId) { + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); + + return user.getLevel(); + } From 2629ab7ce9816c54b0854c0fa18c610ad0edafa2 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Tue, 21 Nov 2023 03:21:12 +0900 Subject: [PATCH 87/95] =?UTF-8?q?[feat]=20=ED=8E=98=EC=9D=B8=EC=9A=A9=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=82=9C=EC=9D=B4=EB=8F=84=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B3=84=EB=AA=85=20=EC=A1=B0=ED=9A=8C=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/controller/UserController.java | 5 +++++ .../GetUserLevelAndNicknameResponseDto.java | 14 ++++++++++++++ .../farmususer/user/service/UserService.java | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index f245b6f..99a6a81 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -49,6 +49,11 @@ public String getUserLevel(@RequestHeader("user") Long userId){ return userService.getUserLevel(userId); } + @GetMapping("/info") + public GetUserLevelAndNicknameResponseDto getUserLevelAndNickname(@RequestHeader("user") Long userId){ + return userService.getUserLevelAndNickname(userId); + } + @PostMapping(value = "/nickname") public BaseResponseDto<Void> emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java new file mode 100644 index 0000000..7c98608 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java @@ -0,0 +1,14 @@ +package modernfarmer.server.farmususer.user.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor(staticName = "of") +@NoArgsConstructor +@Getter +public class GetUserLevelAndNicknameResponseDto { + + private String level; + private String nickname; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index a1ce8ca..43cc7ad 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -195,10 +195,15 @@ public BaseResponseDto<RefreshTokenResponseDto> reissueToken(String refreshToken public String getUserLevel(Long userId) { User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); - return user.getLevel(); } + public GetUserLevelAndNicknameResponseDto getUserLevelAndNickname(Long userId) { + + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); + return GetUserLevelAndNicknameResponseDto.of(user.getLevel(), user.getNickname()); + } + From 32d26b18fc162a8d9fb8a8e9e00da38beaa2864d Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Tue, 21 Nov 2023 19:07:06 +0900 Subject: [PATCH 88/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=EC=95=A1?= =?UTF-8?q?=EC=84=B8=EC=8A=A4=20=ED=86=A0=ED=81=B0=20=EA=B8=B0=ED=95=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/util/JwtTokenProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 3a82efc..b7f1c7e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -28,7 +28,7 @@ public class JwtTokenProvider { private String secretKey; - private final long accessTokenTime = 30L * 1000 * 100; // 1달 토큰 유효 + private final long accessTokenTime = 365L * 24 * 60 * 60 * 1000; // 1달 토큰 유효 private final long refreshTokenTime = 30L * 1000 * 2 * 1000; // 1달 토큰 유효 From 7641dd701f41c398e348b71878ed83715b6cbfd3 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Tue, 21 Nov 2023 02:48:33 +0900 Subject: [PATCH 89/95] =?UTF-8?q?[feat]=20=ED=8E=98=EC=9D=B8=EC=9A=A9=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=82=9C=EC=9D=B4=EB=8F=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/controller/UserController.java | 6 +++++- .../server/farmususer/user/service/UserService.java | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 00ba905..f245b6f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; import modernfarmer.server.farmususer.user.dto.request.ProduceNicknameRequest; import modernfarmer.server.farmususer.user.dto.response.*; @@ -43,7 +44,10 @@ public BaseResponseDto<GetUserResponseDto> getUser(HttpServletRequest request){ return userService.getUser(Long.valueOf(userId)); } - + @GetMapping("/level") + public String getUserLevel(@RequestHeader("user") Long userId){ + return userService.getUserLevel(userId); + } @PostMapping(value = "/nickname") public BaseResponseDto<Void> emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index a87fedf..a601c40 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -203,7 +203,12 @@ public BaseResponseDto<RefreshTokenResponseDto> reissueToken(String refreshToken } + public String getUserLevel(Long userId) { + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); + + return user.getLevel(); + } From 5e91ee821b8f2affd795e954df8e04d9e9708d03 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Tue, 21 Nov 2023 03:21:12 +0900 Subject: [PATCH 90/95] =?UTF-8?q?[feat]=20=ED=8E=98=EC=9D=B8=EC=9A=A9=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=82=9C=EC=9D=B4=EB=8F=84=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B3=84=EB=AA=85=20=EC=A1=B0=ED=9A=8C=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/controller/UserController.java | 5 +++++ .../GetUserLevelAndNicknameResponseDto.java | 14 ++++++++++++++ .../farmususer/user/service/UserService.java | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index f245b6f..99a6a81 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -49,6 +49,11 @@ public String getUserLevel(@RequestHeader("user") Long userId){ return userService.getUserLevel(userId); } + @GetMapping("/info") + public GetUserLevelAndNicknameResponseDto getUserLevelAndNickname(@RequestHeader("user") Long userId){ + return userService.getUserLevelAndNickname(userId); + } + @PostMapping(value = "/nickname") public BaseResponseDto<Void> emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java new file mode 100644 index 0000000..7c98608 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java @@ -0,0 +1,14 @@ +package modernfarmer.server.farmususer.user.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor(staticName = "of") +@NoArgsConstructor +@Getter +public class GetUserLevelAndNicknameResponseDto { + + private String level; + private String nickname; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index a601c40..b75560e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -206,10 +206,15 @@ public BaseResponseDto<RefreshTokenResponseDto> reissueToken(String refreshToken public String getUserLevel(Long userId) { User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); - return user.getLevel(); } + public GetUserLevelAndNicknameResponseDto getUserLevelAndNickname(Long userId) { + + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); + return GetUserLevelAndNicknameResponseDto.of(user.getLevel(), user.getNickname()); + } + From 3ef369483fb19bbe7c7d57fe9a7cbb17517f952f Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Tue, 21 Nov 2023 19:07:06 +0900 Subject: [PATCH 91/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=EC=95=A1?= =?UTF-8?q?=EC=84=B8=EC=8A=A4=20=ED=86=A0=ED=81=B0=20=EA=B8=B0=ED=95=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/util/JwtTokenProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 3a82efc..b7f1c7e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -28,7 +28,7 @@ public class JwtTokenProvider { private String secretKey; - private final long accessTokenTime = 30L * 1000 * 100; // 1달 토큰 유효 + private final long accessTokenTime = 365L * 24 * 60 * 60 * 1000; // 1달 토큰 유효 private final long refreshTokenTime = 30L * 1000 * 2 * 1000; // 1달 토큰 유효 From 9cfea3584b1b37a50687f4cbb6949890fa78cf4b Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Tue, 21 Nov 2023 22:51:45 +0900 Subject: [PATCH 92/95] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=8B=9C=20=EA=B2=8C=EC=8B=9C=EA=B8=80=EA=B3=BC=20?= =?UTF-8?q?=EC=B1=84=EC=86=8C=20=EC=A0=84=EB=B6=80=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/community/CommunityServiceFeignClient.java | 2 +- .../server/farmususer/farm/FarmServiceFeignClient.java | 2 +- .../server/farmususer/user/service/UserService.java | 7 +------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java index 5973a2d..8046079 100644 --- a/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java +++ b/src/main/java/modernfarmer/server/farmususer/community/CommunityServiceFeignClient.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; -@FeignClient(name = "community-service") +@FeignClient(url = "http://3.38.2.59:8082", name = "community-service") public interface CommunityServiceFeignClient { @DeleteMapping("/api/community/posting/all-posting/{userId}") diff --git a/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java index 7954bae..667dcf9 100644 --- a/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java +++ b/src/main/java/modernfarmer/server/farmususer/farm/FarmServiceFeignClient.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; -@FeignClient(name = "farm-service") +@FeignClient(url = "http://3.36.221.140:8081", name = "farm-service") public interface FarmServiceFeignClient { @DeleteMapping("/api/veggie/{userId}") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index b75560e..be251bf 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -118,12 +118,7 @@ public BaseResponseDto<Void> deleteUser(Long userId){ userRepository.deleteUser(userId); communityServiceFeignClient.deleteAllPosting(userId); - // farmServiceFeignClient.deleteAllVeggies(userId); - - - - - + farmServiceFeignClient.deleteAllVeggies(userId); log.info("유저 계정 삭제 완료"); From e97844d86e7f5546779a3345d4711b0cd39a0fe1 Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Thu, 23 Nov 2023 18:27:41 +0900 Subject: [PATCH 93/95] =?UTF-8?q?[feat]=20=EB=8F=99=EA=B8=B0=EB=B6=80?= =?UTF-8?q?=EC=97=AC=20=EB=A9=94=EC=84=B8=EC=A7=80=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/global/enums/Motivations.java | 54 +++++++++++++++++++ .../user/controller/UserController.java | 6 +++ .../GetUserLevelAndNicknameResponseDto.java | 1 + .../response/UserMotivationResponseDto.java | 13 +++++ .../farmususer/user/service/UserService.java | 37 +++++++++++-- 5 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/UserMotivationResponseDto.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java b/src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java new file mode 100644 index 0000000..18d8883 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java @@ -0,0 +1,54 @@ +package modernfarmer.server.farmususer.global.enums; + +public class Motivations { + + public enum Motive_1 { + MOTIVE1_1("채소를 직접 길러\n식비를 줄여보세요!"), + MOTIVE1_2("직접 기른 채소로\n알뜰하고 현명한 식사를 해봐요!"), + MOTIVE1_3("오늘도 채솟값\n알뜰하게 아끼는 중!"), + MOTIVE1_4("홈파밍으로 지출은 줄이고\n성취감은 더해봐요"), + MOTIVE1_5("직접 기른 채소로\n매일 알뜰하게, 매일 특별하게!"); + + private final String motive1; + + Motive_1(String motive1) { + this.motive1 = motive1; + } + + public String getMotive() { + return motive1; + } + } + public enum Motive_2 { + MOTIVE2_1("직접 기른 채소를\n먹을 수 있는 그날까지!"), + MOTIVE2_2("신선함으로 가득 채워지는 식탁, \n 늘 함께할게요!"), + MOTIVE2_3("눈으로 보는 재미, 입으로 맛보는\n홈파밍의 즐거움!"); + + private final String motive2; + + Motive_2(String motive2) { + this.motive2 = motive2; + } + + public String getMotive() { + return motive2; + } + } + public enum Motive_3 { + MOTIVE3_1("바쁜 일상에서 잠깐 벗어나\n텃밭을 가꿔봐요"), + MOTIVE3_2("홈파밍을 하며\n마음의 안정을 느껴봐요!"), + MOTIVE3_3("스트레스 받는 하루, \n 홈파밍으로 힐링하세요"), + MOTIVE3_4("나만의 채소를 키우며\n소소한 성취감을 느껴보세요"), + MOTIVE3_5("성취감은 꾸준함에서! \n 오늘도 함께 성장해요"); + + private final String motive3; + + Motive_3(String motive3) { + this.motive3 = motive3; + } + + public String getMotive() { + return motive3; + } + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 99a6a81..0c46347 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -135,4 +135,10 @@ public BaseResponseDto<SpecificUserResponseDto> specificUser(@RequestParam("user return userService.specificUser(userId); } + @GetMapping("/motivation") + public BaseResponseDto<UserMotivationResponseDto> getMotivation( + @RequestHeader("user") Long userId + ){ + return BaseResponseDto.of(SuccessMessage.SUCCESS, userService.getUserMotivation(userId)); + } } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java index 7c98608..1ec9d00 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserLevelAndNicknameResponseDto.java @@ -11,4 +11,5 @@ public class GetUserLevelAndNicknameResponseDto { private String level; private String nickname; + private String motivation; } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/UserMotivationResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/UserMotivationResponseDto.java new file mode 100644 index 0000000..65ca41f --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/UserMotivationResponseDto.java @@ -0,0 +1,13 @@ +package modernfarmer.server.farmususer.user.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor(staticName = "of") +@NoArgsConstructor +@Getter +public class UserMotivationResponseDto { + + private String motivation; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index be251bf..4d4c109 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -5,10 +5,12 @@ import modernfarmer.server.farmususer.community.CommunityServiceFeignClient; import modernfarmer.server.farmususer.farm.FarmServiceFeignClient; import modernfarmer.server.farmususer.global.config.s3.S3Uploader; +import modernfarmer.server.farmususer.global.enums.Motivations; import modernfarmer.server.farmususer.global.exception.fail.ErrorMessage; import modernfarmer.server.farmususer.global.exception.success.SuccessMessage; import modernfarmer.server.farmususer.user.dto.response.*; import modernfarmer.server.farmususer.user.entity.User; +import modernfarmer.server.farmususer.user.entity.UserMotivation; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import modernfarmer.server.farmususer.user.util.TimeCalculator; @@ -18,8 +20,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; @@ -207,10 +208,40 @@ public String getUserLevel(Long userId) { public GetUserLevelAndNicknameResponseDto getUserLevelAndNickname(Long userId) { User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); - return GetUserLevelAndNicknameResponseDto.of(user.getLevel(), user.getNickname()); + return GetUserLevelAndNicknameResponseDto.of(user.getLevel(), user.getNickname(), getUserMotivation(userId).getMotivation()); } + public UserMotivationResponseDto getUserMotivation(Long userId) { + User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); + + Set<UserMotivation> motivations = user.getUserMotivations(); + + log.info(motivations.toString()); + + List<Long> result = motivations.stream() + .map(um -> { return um.getMotivation().getId(); } ) + .collect(Collectors.toList()); + + List<String> motivationResult = new ArrayList<>(); + + log.info(result.toString()); + + for (Long l : result) { + if (l == 1) { + Arrays.stream(Motivations.Motive_1.values()).forEach(m -> motivationResult.add(m.getMotive())); + } else if (l == 2) { + Arrays.stream(Motivations.Motive_2.values()).forEach(m -> motivationResult.add(m.getMotive())); + } else { + Arrays.stream(Motivations.Motive_3.values()).forEach(m -> motivationResult.add(m.getMotive())); + } + } + + log.info(motivationResult.toString()); + + // motivationResult에서 랜덤으로 하나를 뽑아서 리턴 + return UserMotivationResponseDto.of(motivationResult.get((int) (Math.random() * motivationResult.size()))); + } From 37c45464b23f87f976163251bcff1abfb5fadbd2 Mon Sep 17 00:00:00 2001 From: Lee Eun Seob <107783650+MinchoGreenT@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:32:38 +0900 Subject: [PATCH 94/95] Update actions.yml --- .github/workflows/actions.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 9b13c4d..7eb83f2 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,11 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_32/계정-삭제-api"] - - pull_request: - branches: ["dev"] - + branches: ["feature_32/계정-삭제-api", "dev"] permissions: contents: read From 4d906eaa64a4c1da27bb1b95177a31bf285fd70e Mon Sep 17 00:00:00 2001 From: MinchoGreenT <dldmstjq99@gmail.com> Date: Thu, 23 Nov 2023 23:33:08 +0900 Subject: [PATCH 95/95] =?UTF-8?q?[feat]=20=EB=8F=99=EA=B8=B0=EB=B6=80?= =?UTF-8?q?=EC=97=AC=20=EB=A9=94=EC=84=B8=EC=A7=80=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/global/enums/Motivations.java | 6 +++--- .../server/farmususer/user/service/UserService.java | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java b/src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java index 18d8883..9027ad4 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java +++ b/src/main/java/modernfarmer/server/farmususer/global/enums/Motivations.java @@ -21,7 +21,7 @@ public String getMotive() { } public enum Motive_2 { MOTIVE2_1("직접 기른 채소를\n먹을 수 있는 그날까지!"), - MOTIVE2_2("신선함으로 가득 채워지는 식탁, \n 늘 함께할게요!"), + MOTIVE2_2("신선함으로 가득 채워지는 식탁, \n늘 함께할게요!"), MOTIVE2_3("눈으로 보는 재미, 입으로 맛보는\n홈파밍의 즐거움!"); private final String motive2; @@ -37,9 +37,9 @@ public String getMotive() { public enum Motive_3 { MOTIVE3_1("바쁜 일상에서 잠깐 벗어나\n텃밭을 가꿔봐요"), MOTIVE3_2("홈파밍을 하며\n마음의 안정을 느껴봐요!"), - MOTIVE3_3("스트레스 받는 하루, \n 홈파밍으로 힐링하세요"), + MOTIVE3_3("스트레스 받는 하루, \n홈파밍으로 힐링하세요"), MOTIVE3_4("나만의 채소를 키우며\n소소한 성취감을 느껴보세요"), - MOTIVE3_5("성취감은 꾸준함에서! \n 오늘도 함께 성장해요"); + MOTIVE3_5("성취감은 꾸준함에서! \n오늘도 함께 성장해요"); private final String motive3; diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 4d4c109..cf63aad 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -215,18 +215,15 @@ public UserMotivationResponseDto getUserMotivation(Long userId) { User user = userRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. id=" + userId)); - Set<UserMotivation> motivations = user.getUserMotivations(); + List<Long> result = new ArrayList<>(); + result.add(1L); + result.add(2L); + result.add(3L); - log.info(motivations.toString()); - - List<Long> result = motivations.stream() - .map(um -> { return um.getMotivation().getId(); } ) - .collect(Collectors.toList()); + log.info(result.toString()); List<String> motivationResult = new ArrayList<>(); - log.info(result.toString()); - for (Long l : result) { if (l == 1) { Arrays.stream(Motivations.Motive_1.values()).forEach(m -> motivationResult.add(m.getMotive()));