From b371347201581651f9a722dcd76785abfb791ecb Mon Sep 17 00:00:00 2001 From: SJ70 Date: Mon, 1 Jul 2024 02:35:26 +0900 Subject: [PATCH] =?UTF-8?q?rename:=20=EA=B3=84=EC=B8=B5=ED=98=95=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=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 --- .../auth/oauth/service/OAuthService.java | 9 --------- .../j9/bestmoments/config/SecurityConfig.java | 4 ++-- .../{auth => controller}/AuthController.java | 20 +++++++++---------- .../{member => domain}/Member.java | 2 +- .../{member => domain}/MemberRole.java | 2 +- .../response/JwtTokenDto.java} | 4 ++-- .../response}/OAuthUserInfoDto.java | 2 +- .../jwt/JwtAuthenticationFilter.java | 2 +- .../{auth => }/jwt/JwtTokenProvider.java | 9 +++++---- .../MemberRepository.java | 3 ++- .../oauth => }/service/GoogleAuthService.java | 4 ++-- .../{member => service}/MemberService.java | 7 +++++-- .../j9/bestmoments/service/OAuthService.java | 9 +++++++++ 13 files changed, 41 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/com/j9/bestmoments/auth/oauth/service/OAuthService.java rename src/main/java/com/j9/bestmoments/{auth => controller}/AuthController.java (70%) rename src/main/java/com/j9/bestmoments/{member => domain}/Member.java (98%) rename src/main/java/com/j9/bestmoments/{member => domain}/MemberRole.java (85%) rename src/main/java/com/j9/bestmoments/{auth/jwt/JwtToken.java => dto/response/JwtTokenDto.java} (56%) rename src/main/java/com/j9/bestmoments/{auth/oauth/dto/request => dto/response}/OAuthUserInfoDto.java (78%) rename src/main/java/com/j9/bestmoments/{auth => }/jwt/JwtAuthenticationFilter.java (97%) rename src/main/java/com/j9/bestmoments/{auth => }/jwt/JwtTokenProvider.java (93%) rename src/main/java/com/j9/bestmoments/{member => repository}/MemberRepository.java (80%) rename src/main/java/com/j9/bestmoments/{auth/oauth => }/service/GoogleAuthService.java (96%) rename src/main/java/com/j9/bestmoments/{member => service}/MemberService.java (82%) create mode 100644 src/main/java/com/j9/bestmoments/service/OAuthService.java diff --git a/src/main/java/com/j9/bestmoments/auth/oauth/service/OAuthService.java b/src/main/java/com/j9/bestmoments/auth/oauth/service/OAuthService.java deleted file mode 100644 index f038d3b..0000000 --- a/src/main/java/com/j9/bestmoments/auth/oauth/service/OAuthService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.j9.bestmoments.auth.oauth.service; - -import com.j9.bestmoments.auth.oauth.dto.request.OAuthUserInfoDto; - -public interface OAuthService { - - OAuthUserInfoDto getUserInfo(String code); - -} diff --git a/src/main/java/com/j9/bestmoments/config/SecurityConfig.java b/src/main/java/com/j9/bestmoments/config/SecurityConfig.java index ec9c9e4..9b9ff84 100644 --- a/src/main/java/com/j9/bestmoments/config/SecurityConfig.java +++ b/src/main/java/com/j9/bestmoments/config/SecurityConfig.java @@ -1,7 +1,7 @@ package com.j9.bestmoments.config; -import com.j9.bestmoments.auth.jwt.JwtAuthenticationFilter; -import com.j9.bestmoments.auth.jwt.JwtTokenProvider; +import com.j9.bestmoments.jwt.JwtAuthenticationFilter; +import com.j9.bestmoments.jwt.JwtTokenProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/j9/bestmoments/auth/AuthController.java b/src/main/java/com/j9/bestmoments/controller/AuthController.java similarity index 70% rename from src/main/java/com/j9/bestmoments/auth/AuthController.java rename to src/main/java/com/j9/bestmoments/controller/AuthController.java index 071317b..3f745d0 100644 --- a/src/main/java/com/j9/bestmoments/auth/AuthController.java +++ b/src/main/java/com/j9/bestmoments/controller/AuthController.java @@ -1,12 +1,12 @@ -package com.j9.bestmoments.auth; +package com.j9.bestmoments.controller; -import com.j9.bestmoments.auth.jwt.JwtToken; -import com.j9.bestmoments.auth.jwt.JwtTokenProvider; -import com.j9.bestmoments.auth.oauth.dto.request.OAuthUserInfoDto; -import com.j9.bestmoments.auth.oauth.service.GoogleAuthService; -import com.j9.bestmoments.auth.oauth.service.OAuthService; -import com.j9.bestmoments.member.Member; -import com.j9.bestmoments.member.MemberService; +import com.j9.bestmoments.dto.response.JwtTokenDto; +import com.j9.bestmoments.jwt.JwtTokenProvider; +import com.j9.bestmoments.dto.response.OAuthUserInfoDto; +import com.j9.bestmoments.service.GoogleAuthService; +import com.j9.bestmoments.service.OAuthService; +import com.j9.bestmoments.domain.Member; +import com.j9.bestmoments.service.MemberService; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -30,7 +30,7 @@ public class AuthController { @GetMapping("/login/{oAuthProvider}") @Operation(summary = "OAuth 인증코드로 로그인/회원가입", description = "oAuthProvider: google") - public ResponseEntity login(@PathVariable String oAuthProvider, @RequestParam String code) { + public ResponseEntity login(@PathVariable String oAuthProvider, @RequestParam String code) { OAuthService oAuthService = switch (oAuthProvider) { case "google" -> googleAuthService; default -> throw new OAuth2AuthenticationException("존재하지 않는 OAuth 인증 방식입니다."); @@ -38,7 +38,7 @@ public ResponseEntity login(@PathVariable String oAuthProvider, @Reque OAuthUserInfoDto oAuthUserInfo = oAuthService.getUserInfo(code); Member member = memberService.findOrSaveByOAuthInfo(oAuthUserInfo); - JwtToken jwtToken = jwtTokenProvider.generateToken(member); + JwtTokenDto jwtToken = jwtTokenProvider.generateToken(member); return ResponseEntity.ok(jwtToken); } diff --git a/src/main/java/com/j9/bestmoments/member/Member.java b/src/main/java/com/j9/bestmoments/domain/Member.java similarity index 98% rename from src/main/java/com/j9/bestmoments/member/Member.java rename to src/main/java/com/j9/bestmoments/domain/Member.java index 219ddad..5866d5f 100644 --- a/src/main/java/com/j9/bestmoments/member/Member.java +++ b/src/main/java/com/j9/bestmoments/domain/Member.java @@ -1,4 +1,4 @@ -package com.j9.bestmoments.member; +package com.j9.bestmoments.domain; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/j9/bestmoments/member/MemberRole.java b/src/main/java/com/j9/bestmoments/domain/MemberRole.java similarity index 85% rename from src/main/java/com/j9/bestmoments/member/MemberRole.java rename to src/main/java/com/j9/bestmoments/domain/MemberRole.java index ec3caeb..a0f2451 100644 --- a/src/main/java/com/j9/bestmoments/member/MemberRole.java +++ b/src/main/java/com/j9/bestmoments/domain/MemberRole.java @@ -1,4 +1,4 @@ -package com.j9.bestmoments.member; +package com.j9.bestmoments.domain; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/j9/bestmoments/auth/jwt/JwtToken.java b/src/main/java/com/j9/bestmoments/dto/response/JwtTokenDto.java similarity index 56% rename from src/main/java/com/j9/bestmoments/auth/jwt/JwtToken.java rename to src/main/java/com/j9/bestmoments/dto/response/JwtTokenDto.java index 52aa970..be6c9df 100644 --- a/src/main/java/com/j9/bestmoments/auth/jwt/JwtToken.java +++ b/src/main/java/com/j9/bestmoments/dto/response/JwtTokenDto.java @@ -1,6 +1,6 @@ -package com.j9.bestmoments.auth.jwt; +package com.j9.bestmoments.dto.response; -public record JwtToken( +public record JwtTokenDto( String grantType, String accessToken, String refreshToken diff --git a/src/main/java/com/j9/bestmoments/auth/oauth/dto/request/OAuthUserInfoDto.java b/src/main/java/com/j9/bestmoments/dto/response/OAuthUserInfoDto.java similarity index 78% rename from src/main/java/com/j9/bestmoments/auth/oauth/dto/request/OAuthUserInfoDto.java rename to src/main/java/com/j9/bestmoments/dto/response/OAuthUserInfoDto.java index 3406105..d0eef98 100644 --- a/src/main/java/com/j9/bestmoments/auth/oauth/dto/request/OAuthUserInfoDto.java +++ b/src/main/java/com/j9/bestmoments/dto/response/OAuthUserInfoDto.java @@ -1,4 +1,4 @@ -package com.j9.bestmoments.auth.oauth.dto.request; +package com.j9.bestmoments.dto.response; import lombok.Builder; diff --git a/src/main/java/com/j9/bestmoments/auth/jwt/JwtAuthenticationFilter.java b/src/main/java/com/j9/bestmoments/jwt/JwtAuthenticationFilter.java similarity index 97% rename from src/main/java/com/j9/bestmoments/auth/jwt/JwtAuthenticationFilter.java rename to src/main/java/com/j9/bestmoments/jwt/JwtAuthenticationFilter.java index 1f7f2be..011a48f 100644 --- a/src/main/java/com/j9/bestmoments/auth/jwt/JwtAuthenticationFilter.java +++ b/src/main/java/com/j9/bestmoments/jwt/JwtAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.j9.bestmoments.auth.jwt; +package com.j9.bestmoments.jwt; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; diff --git a/src/main/java/com/j9/bestmoments/auth/jwt/JwtTokenProvider.java b/src/main/java/com/j9/bestmoments/jwt/JwtTokenProvider.java similarity index 93% rename from src/main/java/com/j9/bestmoments/auth/jwt/JwtTokenProvider.java rename to src/main/java/com/j9/bestmoments/jwt/JwtTokenProvider.java index 3ed5eb0..7320e99 100644 --- a/src/main/java/com/j9/bestmoments/auth/jwt/JwtTokenProvider.java +++ b/src/main/java/com/j9/bestmoments/jwt/JwtTokenProvider.java @@ -1,6 +1,7 @@ -package com.j9.bestmoments.auth.jwt; +package com.j9.bestmoments.jwt; -import com.j9.bestmoments.member.Member; +import com.j9.bestmoments.dto.response.JwtTokenDto; +import com.j9.bestmoments.domain.Member; import com.sun.security.auth.UserPrincipal; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -38,7 +39,7 @@ public JwtTokenProvider(@Value("${jwt.secret}") String secretKey) { this.key = Keys.hmacShaKeyFor(keyBytes); } - public JwtToken generateToken(Member member) { + public JwtTokenDto generateToken(Member member) { Date now = new Date(); Date accessTokenExpiresIn = new Date(now.getTime() + accessTokenExpirationMs); @@ -61,7 +62,7 @@ public JwtToken generateToken(Member member) { .signWith(key, SignatureAlgorithm.HS256) .compact(); - return new JwtToken("Bearer", accessToken, refreshToken); + return new JwtTokenDto("Bearer", accessToken, refreshToken); } // 토큰을 복호화하여 인증 정보 추출 diff --git a/src/main/java/com/j9/bestmoments/member/MemberRepository.java b/src/main/java/com/j9/bestmoments/repository/MemberRepository.java similarity index 80% rename from src/main/java/com/j9/bestmoments/member/MemberRepository.java rename to src/main/java/com/j9/bestmoments/repository/MemberRepository.java index 33f9f82..4cc29be 100644 --- a/src/main/java/com/j9/bestmoments/member/MemberRepository.java +++ b/src/main/java/com/j9/bestmoments/repository/MemberRepository.java @@ -1,5 +1,6 @@ -package com.j9.bestmoments.member; +package com.j9.bestmoments.repository; +import com.j9.bestmoments.domain.Member; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/com/j9/bestmoments/auth/oauth/service/GoogleAuthService.java b/src/main/java/com/j9/bestmoments/service/GoogleAuthService.java similarity index 96% rename from src/main/java/com/j9/bestmoments/auth/oauth/service/GoogleAuthService.java rename to src/main/java/com/j9/bestmoments/service/GoogleAuthService.java index 3fa22e2..ed96f49 100644 --- a/src/main/java/com/j9/bestmoments/auth/oauth/service/GoogleAuthService.java +++ b/src/main/java/com/j9/bestmoments/service/GoogleAuthService.java @@ -1,7 +1,7 @@ -package com.j9.bestmoments.auth.oauth.service; +package com.j9.bestmoments.service; import com.fasterxml.jackson.databind.JsonNode; -import com.j9.bestmoments.auth.oauth.dto.request.OAuthUserInfoDto; +import com.j9.bestmoments.dto.response.OAuthUserInfoDto; import java.util.Collections; import java.util.Map; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/j9/bestmoments/member/MemberService.java b/src/main/java/com/j9/bestmoments/service/MemberService.java similarity index 82% rename from src/main/java/com/j9/bestmoments/member/MemberService.java rename to src/main/java/com/j9/bestmoments/service/MemberService.java index 1d94dfa..9fd5e5a 100644 --- a/src/main/java/com/j9/bestmoments/member/MemberService.java +++ b/src/main/java/com/j9/bestmoments/service/MemberService.java @@ -1,6 +1,9 @@ -package com.j9.bestmoments.member; +package com.j9.bestmoments.service; -import com.j9.bestmoments.auth.oauth.dto.request.OAuthUserInfoDto; +import com.j9.bestmoments.dto.response.OAuthUserInfoDto; +import com.j9.bestmoments.domain.MemberRole; +import com.j9.bestmoments.domain.Member; +import com.j9.bestmoments.repository.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/j9/bestmoments/service/OAuthService.java b/src/main/java/com/j9/bestmoments/service/OAuthService.java new file mode 100644 index 0000000..56ca9ca --- /dev/null +++ b/src/main/java/com/j9/bestmoments/service/OAuthService.java @@ -0,0 +1,9 @@ +package com.j9.bestmoments.service; + +import com.j9.bestmoments.dto.response.OAuthUserInfoDto; + +public interface OAuthService { + + OAuthUserInfoDto getUserInfo(String code); + +}