Skip to content

Commit

Permalink
Merge pull request #43 from dnd-side-project/feature/#42
Browse files Browse the repository at this point in the history
응답값 및 param 리팩토링 /#42
  • Loading branch information
woo0doo authored Feb 20, 2024
2 parents d1f0eb3 + 586fd8a commit e5d061b
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static FeedbackDetailResponseDto from(Feedback feedback) {
project.getId(),
project.getTitle(),
project.getFieldName().getName(),
project.getProgress().toString()
project.getProgress().getValue()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ public record FeedbackResponseDto(
@JsonFormat(pattern = "yyyy.MM.dd")
LocalDate endedAt,
boolean isFinished,
boolean isAuthor,
boolean isSubmitted
) {
public static FeedbackResponseDto of(Feedback feedback, boolean isAuthor, boolean isSubmitted) {
public static FeedbackResponseDto of(Feedback feedback, boolean isSubmitted) {
return new FeedbackResponseDto(
feedback.getId(),
feedback.getTitle(),
feedback.getRewardMessage(),
feedback.getStartedAt(),
feedback.getEndedAt(),
feedback.isFinished(),
isAuthor,
isSubmitted
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
import java.util.List;

public record GetFeedbacksResponse(
List<FeedbackResponseDto> feedbacks
List<FeedbackResponseDto> feedbacks,
boolean isAuthor
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ public GetFeedbacksResponse getFeedbacks(Long userId, Long projectId) {

if (userId == null) {
List<FeedbackResponseDto> feedbackResponsDtos = feedbacks.stream()
.map(feedback -> FeedbackResponseDto.of(feedback, false, false)).toList();
return new GetFeedbacksResponse(feedbackResponsDtos);
.map(feedback -> FeedbackResponseDto.of(feedback, false)).toList();
return new GetFeedbacksResponse(feedbackResponsDtos, false);
}

User loginUser = userService.getUserById(userId);
boolean isAuthor = project.isAuthor(loginUser);

List<FeedbackResponseDto> feedbackResponsDtos = feedbacks.stream()
.map(feedback -> FeedbackResponseDto.of(feedback, isAuthor, checkSubmit(loginUser, feedback)))
.map(feedback -> FeedbackResponseDto.of(feedback, checkSubmit(loginUser, feedback)))
.toList();

return new GetFeedbacksResponse(feedbackResponsDtos);
return new GetFeedbacksResponse(feedbackResponsDtos, isAuthor);
}

private boolean checkSubmit(User loginUser, Feedback feedback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ApiResponse<CustomPage<GetProjectsResponseDto>> getProjects(
@PageableDefault(page = 1, size = 5) Pageable pageable,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String field,
@RequestParam(name = "is-finished", required = false) Boolean isFinished,
@RequestParam(required = false) Boolean isFinished,
@RequestParam(required = false) Long sort
) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ public void success() throws Exception {
.description("코드"),
fieldWithPath("data").type(JsonFieldType.OBJECT).description("데이터"),
fieldWithPath("data.feedbacks").type(JsonFieldType.ARRAY).description("피드백 리스트"),
fieldWithPath("data.isAuthor").type(JsonFieldType.BOOLEAN).description("작성자 여부"),
fieldWithPath("data.feedbacks[].feedbackId").type(JsonFieldType.NUMBER).description("피드백 ID"),
fieldWithPath("data.feedbacks[].title").type(JsonFieldType.STRING).description("제목"),
fieldWithPath("data.feedbacks[].rewardMessage").type(JsonFieldType.STRING).description("추가 리워드"),
Expand All @@ -278,29 +279,27 @@ public void success() throws Exception {
fieldWithPath("data.feedbacks[].endedAt").type(JsonFieldType.STRING).description("끝나는 날짜")
.attributes(Attributes.key("format").value("yyyy.MM.dd")),
fieldWithPath("data.feedbacks[].isFinished").type(JsonFieldType.BOOLEAN).description("피드백 종료 여부"),
fieldWithPath("data.feedbacks[].isAuthor").type(JsonFieldType.BOOLEAN).description("작성자 여부"),
fieldWithPath("data.feedbacks[].isSubmitted").type(JsonFieldType.BOOLEAN).description("제출 여부"),
fieldWithPath("message").type(JsonFieldType.STRING)
.description("메시지")
)))
.andExpect(jsonPath("$.code").value("200"))
.andExpect(jsonPath("$.message").value("성공"))
.andExpect(jsonPath("$.data.feedbacks").isArray())
.andExpect(jsonPath("$.data.isAuthor").value(false))
.andExpect(jsonPath("$.data.feedbacks[0].feedbackId").value(MOCK_FEEDBACK_RESPONSE_DTO_A.feedbackId()))
.andExpect(jsonPath("$.data.feedbacks[0].title").value(MOCK_FEEDBACK_RESPONSE_DTO_A.title()))
.andExpect(jsonPath("$.data.feedbacks[0].rewardMessage").value(MOCK_FEEDBACK_RESPONSE_DTO_A.rewardMessage()))
.andExpect(jsonPath("$.data.feedbacks[0].startedAt").value(MOCK_FEEDBACK_RESPONSE_DTO_A.startedAt().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))))
.andExpect(jsonPath("$.data.feedbacks[0].endedAt").value(MOCK_FEEDBACK_RESPONSE_DTO_A.endedAt().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))))
.andExpect(jsonPath("$.data.feedbacks[0].isFinished").value(MOCK_FEEDBACK_RESPONSE_DTO_A.isFinished()))
.andExpect(jsonPath("$.data.feedbacks[0].isAuthor").value(MOCK_FEEDBACK_RESPONSE_DTO_A.isAuthor()))
.andExpect(jsonPath("$.data.feedbacks[0].isSubmitted").value(MOCK_FEEDBACK_RESPONSE_DTO_A.isSubmitted()))
.andExpect(jsonPath("$.data.feedbacks[1].feedbackId").value(MOCK_FEEDBACK_RESPONSE_DTO_B.feedbackId()))
.andExpect(jsonPath("$.data.feedbacks[1].title").value(MOCK_FEEDBACK_RESPONSE_DTO_B.title()))
.andExpect(jsonPath("$.data.feedbacks[1].rewardMessage").value(MOCK_FEEDBACK_RESPONSE_DTO_B.rewardMessage()))
.andExpect(jsonPath("$.data.feedbacks[1].startedAt").value(MOCK_FEEDBACK_RESPONSE_DTO_B.startedAt().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))))
.andExpect(jsonPath("$.data.feedbacks[1].endedAt").value(MOCK_FEEDBACK_RESPONSE_DTO_B.endedAt().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))))
.andExpect(jsonPath("$.data.feedbacks[1].isFinished").value(MOCK_FEEDBACK_RESPONSE_DTO_B.isFinished()))
.andExpect(jsonPath("$.data.feedbacks[1].isAuthor").value(MOCK_FEEDBACK_RESPONSE_DTO_B.isAuthor()))
.andExpect(jsonPath("$.data.feedbacks[1].isSubmitted").value(MOCK_FEEDBACK_RESPONSE_DTO_B.isSubmitted()))
.andExpect(status().isOk());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public class FeedbackFixture {
public static final FeedbackResponseDto MOCK_FEEDBACK_RESPONSE_DTO_A = new FeedbackResponseDto(
1L, "기획 피드백 부탁해요", "아메리카노 5개",
LocalDate.of(2024, 1, 12),
LocalDate.of(2024, 1, 15), false, false, false
LocalDate.of(2024, 1, 15), false, false
);

public static final FeedbackResponseDto MOCK_FEEDBACK_RESPONSE_DTO_B = new FeedbackResponseDto(
2L, "와이어 프레임 피드백 부탁해요", "빙수 5개",
LocalDate.of(2024, 1, 15),
LocalDate.of(2024, 1, 18), true, true, false
LocalDate.of(2024, 1, 18), true, true
);

public static final GetFeedbacksResponse MOCK_GET_FEEDBACK_RESPONSE = new GetFeedbacksResponse(
List.of(MOCK_FEEDBACK_RESPONSE_DTO_A, MOCK_FEEDBACK_RESPONSE_DTO_B)
List.of(MOCK_FEEDBACK_RESPONSE_DTO_A, MOCK_FEEDBACK_RESPONSE_DTO_B), false
);

public static FeedbackSubmit createDummyFeedbackSubmit(User user, Feedback feedback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void success_anonymous() throws Exception {
assertThat(feedbackResponseDto.feedbackId()).isEqualTo(1L);
assertThat(feedbackResponseDto.title()).isEqualTo(feedback.getTitle());
assertThat(feedbackResponseDto.rewardMessage()).isEqualTo(feedback.getRewardMessage());
assertThat(feedbackResponseDto.isAuthor()).isEqualTo(false);
assertThat(feedbackResponseDto.isSubmitted()).isEqualTo(false);

}
Expand All @@ -115,10 +114,8 @@ public void success() throws Exception {
assertThat(feedbackResponseDto.feedbackId()).isEqualTo(1L);
assertThat(feedbackResponseDto.title()).isEqualTo(feedback.getTitle());
assertThat(feedbackResponseDto.rewardMessage()).isEqualTo(feedback.getRewardMessage());
assertThat(feedbackResponseDto.isAuthor()).isEqualTo(true);
assertThat(feedbackResponseDto.isSubmitted()).isEqualTo(true);


}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ProjectControllerTest extends ControllerTest {
class getProjects {

GetProjectsResponseDto getProjectsResponseDto = MOCK_GET_PROJECTS_RESPONSE_DTO;

@Test
@WithMockCustomUser
@DisplayName("정상적인 요청일 시 성공을 반환한다.")
Expand All @@ -75,7 +76,7 @@ public void success() throws Exception {
.param("size", "5")
.param("keyword", "재미있는")
.param("field", "게임")
.param("is-finished", "true")
.param("isFinished", "true")
.param("sort", "0"))
.andDo(print());

Expand All @@ -89,7 +90,7 @@ public void success() throws Exception {
parameterWithName("size").description("사이즈"),
parameterWithName("keyword").description("검색 키워드"),
parameterWithName("field").description("분야"),
parameterWithName("is-finished").description("종료 여부"),
parameterWithName("isFinished").description("종료 여부"),
parameterWithName("sort").description("정렬 기준")

),
Expand Down

0 comments on commit e5d061b

Please sign in to comment.