Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HotFix: swagger server 환경따라 변경 및 도메인 상수화 구현 (중복) #155

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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