Skip to content

Commit

Permalink
chore : dev 환경도 테스트가 동작하도록 변수 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
JiwonKKang committed Jul 25, 2024
1 parent 1dc3bde commit 9e57638
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 27 deletions.
2 changes: 0 additions & 2 deletions application/app-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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;
import core.startup.mealtoktok.domain.auth.OAuthTokens;
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;
Expand All @@ -38,13 +40,13 @@ public Response<Void> signUp(@RequestBody SignupRequest signupRequest, HttpServl
}

@GetMapping("/oauth/login/link")
public Response<OAuthLogin> oauthLoginLink() {
OAuthLogin oAuthLogin = OAuthLogin.from(authService.getKakaoLoginLink());
return Response.success(oAuthLogin);
public Response<OAuthLoginResponse> oauthLoginLink() {
OAuthLoginResponse oAuthLoginResponse = OAuthLoginResponse.from(authService.getKakaoLoginLink());
return Response.success(oAuthLoginResponse);
}

@GetMapping("/login/oauth2/code/kakao")
public Response<Void> credentialTest(@RequestParam String code) {
public Response<Void> credentialTest(@RequestParam("code") String code) {
authService.getCredentialTest(code);
return Response.success("테스트 성공");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,7 +22,7 @@ public interface AuthApiDocs {
Response<Void> login(OAuthTokens oAuthTokens, HttpServletResponse response);

@Operation(summary = "OAuth 링크발급(백엔드 개발 테스트용입니다)")
Response<OAuthLogin> oauthLoginLink();
Response<OAuthLoginResponse> oauthLoginLink();

@Operation(summary = "OAuth code를 통한 테스트(백엔드 개발 테스트용입니다)")
Response<Void> credentialTest(@RequestParam String code);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/resources/application-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +59,7 @@ public RedisTemplate<String, RefreshToken> tokenRedisTemplate() {
}

@Bean
@Primary
public RedisTemplate<String, String> banTokenRedisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
Expand Down

0 comments on commit 9e57638

Please sign in to comment.