diff --git a/application/app-api/build.gradle b/application/app-api/build.gradle index 0295c53..2ba355f 100644 --- a/application/app-api/build.gradle +++ b/application/app-api/build.gradle @@ -14,8 +14,6 @@ dependencies { //aop implementation 'org.springframework.boot:spring-boot-starter-aop' - - //spring-json implementation 'org.springframework.boot:spring-boot-configuration-processor' //JWT diff --git a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApi.java b/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApi.java index ed1292f..6be1d2a 100644 --- a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApi.java +++ b/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApi.java @@ -1,7 +1,7 @@ package core.startup.mealtoktok.api.auth; -import core.startup.mealtoktok.api.auth.request.SignupRequest; -import core.startup.mealtoktok.api.auth.response.OAuthLogin; +import core.startup.mealtoktok.api.dto.SignupRequest; +import core.startup.mealtoktok.api.dto.OAuthLoginResponse; import core.startup.mealtoktok.common.dto.Response; import core.startup.mealtoktok.domain.auth.AuthService; import core.startup.mealtoktok.domain.auth.JwtTokens; @@ -9,11 +9,13 @@ import core.startup.mealtoktok.api.global.security.JwtTokenizer; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/auth") +@Slf4j public class AuthApi implements AuthApiDocs { private final AuthService authService; @@ -38,13 +40,13 @@ public Response signUp(@RequestBody SignupRequest signupRequest, HttpServl } @GetMapping("/oauth/login/link") - public Response oauthLoginLink() { - OAuthLogin oAuthLogin = OAuthLogin.from(authService.getKakaoLoginLink()); - return Response.success(oAuthLogin); + public Response oauthLoginLink() { + OAuthLoginResponse oAuthLoginResponse = OAuthLoginResponse.from(authService.getKakaoLoginLink()); + return Response.success(oAuthLoginResponse); } @GetMapping("/login/oauth2/code/kakao") - public Response credentialTest(@RequestParam String code) { + public Response credentialTest(@RequestParam("code") String code) { authService.getCredentialTest(code); return Response.success("테스트 성공"); } diff --git a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApiDocs.java b/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApiDocs.java index 71c24b3..9be99de 100644 --- a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApiDocs.java +++ b/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/AuthApiDocs.java @@ -1,7 +1,7 @@ package core.startup.mealtoktok.api.auth; -import core.startup.mealtoktok.api.auth.request.SignupRequest; -import core.startup.mealtoktok.api.auth.response.OAuthLogin; +import core.startup.mealtoktok.api.dto.SignupRequest; +import core.startup.mealtoktok.api.dto.OAuthLoginResponse; import core.startup.mealtoktok.common.dto.Response; import core.startup.mealtoktok.domain.auth.OAuthTokens; import io.swagger.v3.oas.annotations.Operation; @@ -22,7 +22,7 @@ public interface AuthApiDocs { Response login(OAuthTokens oAuthTokens, HttpServletResponse response); @Operation(summary = "OAuth 링크발급(백엔드 개발 테스트용입니다)") - Response oauthLoginLink(); + Response oauthLoginLink(); @Operation(summary = "OAuth code를 통한 테스트(백엔드 개발 테스트용입니다)") Response credentialTest(@RequestParam String code); diff --git a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/response/OAuthLogin.java b/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/response/OAuthLogin.java deleted file mode 100644 index 55f170d..0000000 --- a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/response/OAuthLogin.java +++ /dev/null @@ -1,9 +0,0 @@ -package core.startup.mealtoktok.api.auth.response; - -public record OAuthLogin( - String link -) { - public static OAuthLogin from(String link) { - return new OAuthLogin(link); - } -} diff --git a/application/app-api/src/main/java/core/startup/mealtoktok/api/dto/OAuthLoginResponse.java b/application/app-api/src/main/java/core/startup/mealtoktok/api/dto/OAuthLoginResponse.java new file mode 100644 index 0000000..8755922 --- /dev/null +++ b/application/app-api/src/main/java/core/startup/mealtoktok/api/dto/OAuthLoginResponse.java @@ -0,0 +1,9 @@ +package core.startup.mealtoktok.api.dto; + +public record OAuthLoginResponse( + String link +) { + public static OAuthLoginResponse from(String link) { + return new OAuthLoginResponse(link); + } +} diff --git a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/request/SignupRequest.java b/application/app-api/src/main/java/core/startup/mealtoktok/api/dto/SignupRequest.java similarity index 91% rename from application/app-api/src/main/java/core/startup/mealtoktok/api/auth/request/SignupRequest.java rename to application/app-api/src/main/java/core/startup/mealtoktok/api/dto/SignupRequest.java index 8abf8c2..da719d1 100644 --- a/application/app-api/src/main/java/core/startup/mealtoktok/api/auth/request/SignupRequest.java +++ b/application/app-api/src/main/java/core/startup/mealtoktok/api/dto/SignupRequest.java @@ -1,4 +1,4 @@ -package core.startup.mealtoktok.api.auth.request; +package core.startup.mealtoktok.api.dto; import core.startup.mealtoktok.domain.auth.OAuthTokens; import core.startup.mealtoktok.domain.user.AddressWithCoordinate; diff --git a/common/src/main/java/core/startup/mealtoktok/common/properties/OauthProperties.java b/common/src/main/java/core/startup/mealtoktok/common/properties/OauthProperties.java index c50e222..69affc9 100644 --- a/common/src/main/java/core/startup/mealtoktok/common/properties/OauthProperties.java +++ b/common/src/main/java/core/startup/mealtoktok/common/properties/OauthProperties.java @@ -8,7 +8,9 @@ public class OauthProperties { public static String BASE_URL; public static String CLIENT_ID; + public static String TEST_CLIENT_ID; public static String REDIRECT_URL; + public static String TEST_REDIRECT_URL; public static String APP_ID; public static String ADMIN_KEY; public static String SERVICE_KEY; @@ -30,11 +32,21 @@ public void setClientId(String clientId) { OauthProperties.CLIENT_ID = clientId; } + @Value("${oauth.kakao.test-client-id}") + public void setTestClientId(String testClientId) { + OauthProperties.TEST_CLIENT_ID = testClientId; + } + @Value("${oauth.kakao.redirect-url}") public void setRedirectUrl(String redirectUrl) { OauthProperties.REDIRECT_URL = redirectUrl; } + @Value("${oauth.kakao.test-redirect-url}") + public void setTestRedirectUrl(String testRedirectUrl) { + OauthProperties.TEST_REDIRECT_URL = testRedirectUrl; + } + @Value("${oauth.kakao.app-id}") public void setAppId(String appId) { OauthProperties.APP_ID = appId; diff --git a/common/src/main/resources/application-common.yml b/common/src/main/resources/application-common.yml index 2b2755e..1b4f112 100644 --- a/common/src/main/resources/application-common.yml +++ b/common/src/main/resources/application-common.yml @@ -6,10 +6,13 @@ oauth: kakao: base-url: https://kauth.kakao.com client-id: ${KAKAO_REST_API_KEY} + test-client-id: ${KAKAO_TEST_CLIENT_ID} redirect-url: ${KAKAO_REDIRECT} + test-redirect-url: ${KAKAO_TEST_REDIRECT} app-id: ${KAKAO_APP_ID} admin-key: ${KAKAO_ADMIN_KEY} service-key: ${KAKAO_REST_API_KEY} + --- spring: config: @@ -19,7 +22,9 @@ oauth: kakao: base-url: https://kauth.kakao.com client-id: ${KAKAO_REST_API_KEY} + test-client-id: ${KAKAO_TEST_CLIENT_ID} redirect-url: ${KAKAO_REDIRECT} + test-redirect-url: ${KAKAO_TEST_REDIRECT} app-id: ${KAKAO_APP_ID} admin-key: ${KAKAO_ADMIN_KEY} service-key: ${KAKAO_APP_ID} \ No newline at end of file diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/auth/AuthService.java b/domain/src/main/java/core/startup/mealtoktok/domain/auth/AuthService.java index 43083c8..d6a5cc1 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/auth/AuthService.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/auth/AuthService.java @@ -41,13 +41,13 @@ public String getKakaoLoginLink() { return BASE_URL + String.format( KAKAO_OAUTH_QUERY_STRING, - CLIENT_ID, - REDIRECT_URL + TEST_CLIENT_ID, + TEST_REDIRECT_URL ); } public void getCredentialTest(String code) { - OAuthTokens authToken = oAuthClient.auth(CLIENT_ID, REDIRECT_URL, code); + OAuthTokens authToken = oAuthClient.auth(TEST_CLIENT_ID, TEST_REDIRECT_URL, code); signUp(authToken, AddressWithCoordinate.of("충청북도 흥덕구 봉명동 2300-1", 36.629, 127.456)); } diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/user/UserReader.java b/domain/src/main/java/core/startup/mealtoktok/domain/user/UserReader.java index dbaa204..658a884 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/user/UserReader.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/user/UserReader.java @@ -12,9 +12,11 @@ public class UserReader { private final UserCacheManager userCacheManager; public User read(TargetUser targetUser) { - return userCacheManager.read(targetUser).orElseGet( () -> - userRepository.findById(targetUser) - ); + return userCacheManager.read(targetUser).orElseGet( () ->{ + User user = userRepository.findById(targetUser); + userCacheManager.cache(user); + return user; + }); } public boolean isAlreadyRegistered(OAuthInfo oAuthInfo) { diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/user/config/RedisConfig.java b/infra/src/main/java/core/startup/mealtoktok/infra/user/config/RedisConfig.java index 1ff3c6d..faf98f6 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/user/config/RedisConfig.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/user/config/RedisConfig.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; @@ -58,6 +59,7 @@ public RedisTemplate tokenRedisTemplate() { } @Bean + @Primary public RedisTemplate banTokenRedisTemplate() { RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory());