From fe139cdb481c6f344376870db30dab497c654d40 Mon Sep 17 00:00:00 2001 From: JIHO LEE <161289673+GitJIHO@users.noreply.github.com> Date: Mon, 4 Nov 2024 23:04:04 +0900 Subject: [PATCH] =?UTF-8?q?HotFix:=20swagger=20server=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EC=83=81=EC=88=98=ED=99=94=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(#154)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * swagger 환경변수 확인하여 다른 server에서 try it out 하도록 구현 * refactor: 구별용 url 상수화 * fix: 테스트코드 오류 수정 --- .../sinitto/auth/service/KakaoApiService.java | 11 +++++++---- .../sinitto/common/config/SwaggerConfig.java | 19 +++++++++++++++++++ .../service/HelloCallServiceTest.java | 10 ++++++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java b/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java index d3721539..cfae5c0c 100644 --- a/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java +++ b/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java @@ -19,6 +19,9 @@ public class KakaoApiService { private static final String KAKAO_AUTH_BASE_URL = "https://kauth.kakao.com/oauth"; private static final String KAKAO_API_BASE_URL = "https://kapi.kakao.com/v2/user"; + private static final String LOCALHOST_URL = "localhost:5173"; + private static final String FRONT_URL = "sinitto.s3-website.ap-northeast-2.amazonaws.com"; + private final RestTemplate restTemplate; private final KakaoProperties kakaoProperties; @@ -34,9 +37,9 @@ public String getAuthorizationUrl(HttpServletRequest httpServletRequest) { } String redirectUri; - if (requestUrl.contains("localhost:5173")) { + if (requestUrl.contains(LOCALHOST_URL)) { redirectUri = kakaoProperties.devRedirectUri(); - } else if (requestUrl.contains("sinitto.s3-website.ap-northeast-2.amazonaws.com")) { + } else if (requestUrl.contains(FRONT_URL)) { redirectUri = kakaoProperties.redirectUri(); } else { throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); @@ -57,9 +60,9 @@ public KakaoTokenResponse getAccessToken(String authorizationCode, HttpServletRe } String redirectUri; - if (requestUrl.contains("localhost:5173")) { + if (requestUrl.contains(LOCALHOST_URL)) { redirectUri = kakaoProperties.devRedirectUri(); - } else if (requestUrl.contains("sinitto.s3-website.ap-northeast-2.amazonaws.com")) { + } else if (requestUrl.contains(FRONT_URL)) { redirectUri = kakaoProperties.redirectUri(); } else { throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); diff --git a/src/main/java/com/example/sinitto/common/config/SwaggerConfig.java b/src/main/java/com/example/sinitto/common/config/SwaggerConfig.java index 114e54c6..9e7a9e76 100644 --- a/src/main/java/com/example/sinitto/common/config/SwaggerConfig.java +++ b/src/main/java/com/example/sinitto/common/config/SwaggerConfig.java @@ -3,16 +3,34 @@ import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.core.env.Profiles; @Configuration public class SwaggerConfig { + private final Environment environment; + + private static final String LOCAL_SERVER_URL = "http://localhost:8080"; + private static final String PROD_SERVER_URL = "https://sinitto.site"; + + public SwaggerConfig(Environment environment) { + this.environment = environment; + } + @Bean public OpenAPI openAPI() { + String serverUrl = LOCAL_SERVER_URL; + + if (environment.acceptsProfiles(Profiles.of("prod"))) { + serverUrl = PROD_SERVER_URL; + } + return new OpenAPI() .components(new Components() .addSecuritySchemes("bearerAuth", @@ -21,6 +39,7 @@ public OpenAPI openAPI() { .scheme("bearer") .bearerFormat("JWT"))) .info(apiInfo()) + .addServersItem(new Server().url(serverUrl)) .addSecurityItem(new SecurityRequirement().addList("bearerAuth")); } diff --git a/src/test/java/com/example/sinitto/hellocall/service/HelloCallServiceTest.java b/src/test/java/com/example/sinitto/hellocall/service/HelloCallServiceTest.java index e287ccd6..90d60588 100644 --- a/src/test/java/com/example/sinitto/hellocall/service/HelloCallServiceTest.java +++ b/src/test/java/com/example/sinitto/hellocall/service/HelloCallServiceTest.java @@ -152,7 +152,10 @@ void createHelloCallByGuardWhenPointIsNotExist() { case DayOfWeek.SUNDAY -> dayName = "일"; } - timeSlots.add(new HelloCallRequest.TimeSlot(dayName, LocalTime.now().plusHours(1), LocalTime.now().plusHours(2))); + LocalTime startTime = LocalTime.of(10, 0); + LocalTime endTime = LocalTime.of(11, 0); + + timeSlots.add(new HelloCallRequest.TimeSlot(dayName, startTime, endTime)); HelloCallRequest helloCallRequest = new HelloCallRequest(senior.getId(), LocalDate.now(), LocalDate.now().plusDays(7), timeSlots, 1000, 10, "testRequirement"); when(seniorRepository.findByIdAndMemberId(helloCallRequest.seniorId(), memberId)).thenReturn(Optional.of(senior)); @@ -183,7 +186,10 @@ void createHelloCallByGuardWhenPointIsLessThanPrice() { case DayOfWeek.SATURDAY -> dayName = "토"; case DayOfWeek.SUNDAY -> dayName = "일"; } - timeSlots.add(new HelloCallRequest.TimeSlot(dayName, LocalTime.now(), LocalTime.now().plusHours(2))); + LocalTime startTime = LocalTime.of(10, 0); + LocalTime endTime = LocalTime.of(12, 0); + + timeSlots.add(new HelloCallRequest.TimeSlot(dayName, startTime, endTime)); HelloCallRequest helloCallRequest = new HelloCallRequest(senior.getId(), LocalDate.now(), LocalDate.now().plusDays(7), timeSlots, 1000, 10, "testRequirement"); Point point = new Point(100, member);