Skip to content

Commit

Permalink
HotFix: swagger server 환경따라 변경 및 도메인 상수화 구현 (#154)
Browse files Browse the repository at this point in the history
* swagger 환경변수 확인하여 다른 server에서 try it out 하도록 구현

* refactor: 구별용 url 상수화

* fix: 테스트코드 오류 수정
  • Loading branch information
GitJIHO authored Nov 4, 2024
1 parent 2cbe7e1 commit fe139cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/example/sinitto/common/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -21,6 +39,7 @@ public OpenAPI openAPI() {
.scheme("bearer")
.bearerFormat("JWT")))
.info(apiInfo())
.addServersItem(new Server().url(serverUrl))
.addSecurityItem(new SecurityRequirement().addList("bearerAuth"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit fe139cd

Please sign in to comment.