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

feat: 리뷰 옵션 조회 API 수정 #298

Merged
merged 1 commit into from
Dec 16, 2023
Merged
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 @@ -10,7 +10,6 @@
import io.perfume.api.review.adapter.in.http.dto.GetReviewCommentsRequestDto;
import io.perfume.api.review.adapter.in.http.dto.GetReviewCommentsResponseDto;
import io.perfume.api.review.adapter.in.http.dto.GetReviewDetailResponseDto;
import io.perfume.api.review.adapter.in.http.dto.GetReviewOptionItemRequestDto;
import io.perfume.api.review.adapter.in.http.dto.GetReviewOptionItemResponseDto;
import io.perfume.api.review.adapter.in.http.dto.GetReviewsRequestDto;
import io.perfume.api.review.adapter.in.http.dto.GetReviewsResponseDto;
Expand Down Expand Up @@ -157,14 +156,9 @@ public ResponseEntity<ReviewLikeResponseDto> likeReview(
return ResponseEntity.status(HttpStatus.OK).body(new ReviewLikeResponseDto(id));
}

@PreAuthorize("isAuthenticated()")
@GetMapping("/options")
public ResponseEntity<List<GetReviewOptionItemResponseDto>> getReviewCategories(
final GetReviewOptionItemRequestDto type) {
return switch (type.type()) {
case STRENGTH -> ResponseEntity.ok(GetReviewOptionItemResponseDto.getStrength());
case SEASON -> ResponseEntity.ok(GetReviewOptionItemResponseDto.getSeason());
case DURATION -> ResponseEntity.ok(GetReviewOptionItemResponseDto.getDuration());
case DAY_TYPE -> ResponseEntity.ok(GetReviewOptionItemResponseDto.getDayType());
};
public GetReviewOptionItemResponseDto getReviewCategories() {
return GetReviewOptionItemResponseDto.get();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
package io.perfume.api.review.adapter.in.http.dto;

import io.perfume.api.review.domain.ReviewOption;
import io.perfume.api.review.domain.type.DayType;
import io.perfume.api.review.domain.type.Duration;
import io.perfume.api.review.domain.type.Season;
import io.perfume.api.review.domain.type.Strength;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;

public record GetReviewOptionItemResponseDto(String name, String code) {
public record GetReviewOptionItemResponseDto(
List<ReviewOption> strength,
List<ReviewOption> season,
List<ReviewOption> duration,
List<ReviewOption> dayType) {

public static List<GetReviewOptionItemResponseDto> getStrength() {
return Arrays.stream(Strength.values())
.map(
strength ->
new GetReviewOptionItemResponseDto(strength.getDescription(), strength.name()))
.toList();
}
public static GetReviewOptionItemResponseDto get() {

public static List<GetReviewOptionItemResponseDto> getSeason() {
return Arrays.stream(Strength.values())
.map(
strength ->
new GetReviewOptionItemResponseDto(strength.getDescription(), strength.name()))
.toList();
}
List<ReviewOption> strength =
EnumSet.allOf(Strength.class).stream()
.map(enumValue -> new ReviewOption(enumValue.name(), enumValue.getDescription()))
.toList();

public static List<GetReviewOptionItemResponseDto> getDuration() {
return Arrays.stream(Strength.values())
.map(
strength ->
new GetReviewOptionItemResponseDto(strength.getDescription(), strength.name()))
.toList();
}
List<ReviewOption> season =
EnumSet.allOf(Season.class).stream()
.map(enumValue -> new ReviewOption(enumValue.name(), enumValue.getDescription()))
.toList();

List<ReviewOption> duration =
EnumSet.allOf(Duration.class).stream()
.map(enumValue -> new ReviewOption(enumValue.name(), enumValue.getDescription()))
.toList();

List<ReviewOption> dayType =
EnumSet.allOf(DayType.class).stream()
.map(enumValue -> new ReviewOption(enumValue.name(), enumValue.getDescription()))
.toList();

public static List<GetReviewOptionItemResponseDto> getDayType() {
return Arrays.stream(Strength.values())
.map(
strength ->
new GetReviewOptionItemResponseDto(strength.getDescription(), strength.name()))
.toList();
return new GetReviewOptionItemResponseDto(strength, season, duration, dayType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.perfume.api.review.domain;

public record ReviewOption(String name, String code) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.queryParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -521,23 +520,43 @@ void testGetReviewDetail() throws Exception {
}

@Test
void 리뷰_항목_조회() throws Exception {
@WithMockUser(username = "2", roles = "USER")
void 리뷰_옵션_목록_조회() throws Exception {
// when & then
mockMvc
.perform(
RestDocumentationRequestBuilders.get("/v1/reviews/options?type=DAY_TYPE")
RestDocumentationRequestBuilders.get("/v1/reviews/options")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andDo(
document(
"get-review-options",
queryParameters(
parameterWithName("type")
.description("리뷰 항목 타입 (STRENGTH, SEASON, DURATION, DAY_TYPE)")),
responseFields(
fieldWithPath("[].code").type(JsonFieldType.STRING).description("리뷰 항목 코드"),
fieldWithPath("[].name").type(JsonFieldType.STRING).description("리뷰 항목 이름"))));
fieldWithPath("strength[].name")
.type(JsonFieldType.STRING)
.description("향수 강도 이름"),
fieldWithPath("strength[].code")
.type(JsonFieldType.STRING)
.description("향수 강도 코드"),
fieldWithPath("season[].name")
.type(JsonFieldType.STRING)
.description("향수 강도 이름"),
fieldWithPath("season[].code")
.type(JsonFieldType.STRING)
.description("향수 강도 코드"),
fieldWithPath("duration[].name")
.type(JsonFieldType.STRING)
.description("향수 지속력 이름"),
fieldWithPath("duration[].code")
.type(JsonFieldType.STRING)
.description("향수 지속력 코드"),
fieldWithPath("dayType[].name")
.type(JsonFieldType.STRING)
.description("어울리는 상황 이름"),
fieldWithPath("dayType[].code")
.type(JsonFieldType.STRING)
.description("어울리는 상황 코드"))));
}
}
Loading