Skip to content

Commit

Permalink
CORS 설정 및 Profile을 RunnerProfile로 변경 (#120)
Browse files Browse the repository at this point in the history
* feat: cors 설정

* refactor: MemberProfile 을 RunnerProfile 로 수정

* feat: cors HttpMethod 에 PATCH 추가
  • Loading branch information
hyena0608 authored Jul 27, 2023
1 parent 63b978d commit 8d2d732
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 63 deletions.
25 changes: 25 additions & 0 deletions backend/baton/src/main/java/touch/baton/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package touch.baton.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static org.springframework.http.HttpHeaders.LOCATION;
import static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.OPTIONS;
import static org.springframework.http.HttpMethod.PATCH;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.PUT;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(final CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowCredentials(false)
.allowedMethods(GET.name(), POST.name(), PUT.name(), PATCH.name(), DELETE.name(), OPTIONS.name())
.exposedHeaders(LOCATION)
.maxAge(3600);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import touch.baton.domain.runnerpost.RunnerPost;
import touch.baton.domain.runnerpost.vo.ReviewStatus;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -10,56 +11,64 @@ public record RunnerPostResponse() {

public record Detail(Long runnerPostId,
String title,
String contents,
String pullRequestUrl,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm", timezone = "Asia/Seoul")
LocalDateTime deadline,
List<String> tags,
String contents,
Integer chattingCount,
Integer watchedCount,
Integer chattingCount,
ReviewStatus reviewStatus,
boolean isOwner,
ProfileResponse.Detail profile
RunnerProfileResponse.Detail runnerProfile,
List<String> tags
) {

public static Detail from(final RunnerPost runnerPost) {
return new Detail(
runnerPost.getId(),
runnerPost.getTitle().getValue(),
runnerPost.getDeadline().getValue(),
convertToTags(runnerPost),
runnerPost.getContents().getValue(),
runnerPost.getChattingCount().getValue(),
runnerPost.getPullRequestUrl().getValue(),
runnerPost.getDeadline().getValue(),
runnerPost.getWatchedCount().getValue(),
runnerPost.getChattingCount().getValue(),
runnerPost.getReviewStatus(),
true,
ProfileResponse.Detail.from(runnerPost.getRunner().getMember())
RunnerProfileResponse.Detail.from(runnerPost.getRunner()),
convertToTags(runnerPost)
);
}
}


public record DetailVersionTest(Long runnerPostId,
String title,
String contents,
String pullRequestUrl,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm", timezone = "Asia/Seoul")
LocalDateTime deadline,
List<String> tags,
String contents,
boolean isOwner,
Integer chattingCount,
Integer watchedCount,
ProfileResponse.Detail profile,
SupporterResponseTestVersion.Simple supporter
Integer chattingCount,
ReviewStatus reviewStatus,
RunnerProfileResponse.Detail runnerProfile,
SupporterResponseTestVersion.Simple supporterProfile,
boolean isOwner,
List<String> tags
) {
public static DetailVersionTest fromVersionTest(final RunnerPost runnerPost) {
return new DetailVersionTest(
runnerPost.getId(),
runnerPost.getTitle().getValue(),
runnerPost.getDeadline().getValue(),
convertToTags(runnerPost),
runnerPost.getContents().getValue(),
true,
runnerPost.getChattingCount().getValue(),
runnerPost.getPullRequestUrl().getValue(),
runnerPost.getDeadline().getValue(),
runnerPost.getWatchedCount().getValue(),
ProfileResponse.Detail.from(runnerPost.getRunner().getMember()),
SupporterResponseTestVersion.Simple.fromTestVersion(runnerPost.getSupporter())
runnerPost.getChattingCount().getValue(),
runnerPost.getReviewStatus(),
RunnerProfileResponse.Detail.from(runnerPost.getRunner()),
SupporterResponseTestVersion.Simple.fromTestVersion(runnerPost.getSupporter()),
true,
convertToTags(runnerPost)
);
}
}
Expand All @@ -68,23 +77,23 @@ public record Simple(Long runnerPostId,
String title,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm", timezone = "Asia/Seoul")
LocalDateTime deadline,
List<String> tags,
ProfileResponse.Simple profile,
int watchedCount,
int chattingCount,
String reviewStatus
String reviewStatus,
RunnerProfileResponse.Simple runnerProfile,
List<String> tags
) {

public static Simple from(final RunnerPost runnerPost) {
return new Simple(
runnerPost.getId(),
runnerPost.getTitle().getValue(),
runnerPost.getDeadline().getValue(),
convertToTags(runnerPost),
ProfileResponse.Simple.from(runnerPost.getRunner().getMember()),
runnerPost.getWatchedCount().getValue(),
runnerPost.getChattingCount().getValue(),
runnerPost.getReviewStatus().name()
runnerPost.getReviewStatus().name(),
RunnerProfileResponse.Simple.from(runnerPost.getRunner()),
convertToTags(runnerPost)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package touch.baton.domain.runnerpost.controller.response;

import touch.baton.domain.runner.Runner;

public record RunnerProfileResponse() {

public record Detail(Long runnerId,
String name,
String company,
String imageUrl
) {

public static Detail from(final Runner runner) {
return new Detail(
runner.getId(),
runner.getMember().getMemberName().getValue(),
runner.getMember().getCompany().getValue(),
runner.getMember().getImageUrl().getValue()
);
}
}

public record Simple(String name, String imageUrl) {

public static Simple from(final Runner runner) {
return new Simple(
runner.getMember().getMemberName().getValue(),
runner.getMember().getImageUrl().getValue()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public RunnerPostServerResponseBuilder(final ExtractableResponse<Response> respo
() -> assertThat(actual.contents()).isEqualTo(러너_게시글_응답.contents()),
() -> assertThat(actual.tags()).isEqualTo(러너_게시글_응답.tags()),
() -> assertThat(actual.deadline()).isEqualToIgnoringSeconds(러너_게시글_응답.deadline()),
() -> assertThat(actual.profile().name()).isEqualTo(러너_게시글_응답.profile().name()),
() -> assertThat(actual.profile().company()).isEqualTo(러너_게시글_응답.profile().company()),
() -> assertThat(actual.profile().imageUrl()).isEqualTo(러너_게시글_응답.profile().imageUrl()),
() -> assertThat(actual.profile().memberId()).isEqualTo(러너_게시글_응답.profile().memberId()),
() -> assertThat(actual.runnerProfile().name()).isEqualTo(러너_게시글_응답.runnerProfile().name()),
() -> assertThat(actual.runnerProfile().company()).isEqualTo(러너_게시글_응답.runnerProfile().company()),
() -> assertThat(actual.runnerProfile().imageUrl()).isEqualTo(러너_게시글_응답.runnerProfile().imageUrl()),
() -> assertThat(actual.runnerProfile().runnerId()).isEqualTo(러너_게시글_응답.runnerProfile().runnerId()),
() -> assertThat(actual.chattingCount()).isEqualTo(러너_게시글_응답.chattingCount()),
() -> assertThat(actual.watchedCount()).isEqualTo(러너_게시글_응답.watchedCount()),
() -> assertThat(actual.runnerPostId()).isEqualTo(러너_게시글_응답.runnerPostId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void success() {
).doesNotThrowAnyException();
}

@DisplayName("supporter 에 null 이 들어간 경우 아직 리뷰어 할당이 되지 않은 것이다.")
@DisplayName("supporterProfile 에 null 이 들어간 경우 아직 리뷰어 할당이 되지 않은 것이다.")
@Test
void success_if_supporter_is_null() {
assertThatCode(() -> RunnerPost.builder()
Expand Down

0 comments on commit 8d2d732

Please sign in to comment.