-
Notifications
You must be signed in to change notification settings - Fork 0
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
♻️ change package for category recipe search #112
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import net.pengcook.category.dto.RecipeOfCategoryRequest; | ||
import net.pengcook.category.repository.CategoryRecipeRepository; | ||
import net.pengcook.recipe.domain.RecipeStep; | ||
import net.pengcook.recipe.dto.AuthorResponse; | ||
import net.pengcook.recipe.dto.CategoryResponse; | ||
|
@@ -24,6 +26,7 @@ public class RecipeService { | |
|
||
private final RecipeRepository recipeRepository; | ||
private final RecipeStepRepository recipeStepRepository; | ||
private final CategoryRecipeRepository categoryRecipeRepository; | ||
|
||
public List<MainRecipeResponse> readRecipes(int pageNumber, int pageSize) { | ||
Pageable pageable = PageRequest.of(pageNumber, pageSize); | ||
|
@@ -38,6 +41,15 @@ public List<RecipeStepResponse> readRecipeSteps(long id) { | |
return convertToRecipeStepResponses(recipeSteps); | ||
} | ||
|
||
public List<MainRecipeResponse> readRecipesOfCategory(RecipeOfCategoryRequest request) { | ||
String categoryName = request.category(); | ||
Pageable pageable = PageRequest.of(request.pageNumber(), request.pageSize()); | ||
List<Long> recipeIds = categoryRecipeRepository.findRecipeIdsByCategoryName(categoryName, pageable); | ||
|
||
List<RecipeDataResponse> recipeDataResponses = recipeRepository.findRecipeData(recipeIds); | ||
return convertToMainRecipeResponses(recipeDataResponses); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 카테고리별 조회 로직이 recipe 패키지에 포함돼서 convert 메서드 접근제어자는 다시 private로 바꾸면 좋을 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 생각이에요!! |
||
} | ||
|
||
private List<RecipeStepResponse> convertToRecipeStepResponses(List<RecipeStep> recipeSteps) { | ||
return recipeSteps.stream() | ||
.map(RecipeStepResponse::new) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,21 +29,21 @@ void findRecipeIds() { | |
|
||
List<Long> recipeIds = repository.findRecipeIds(pageable); | ||
|
||
assertThat(recipeIds).containsExactly(4L, 3L, 2L); | ||
assertThat(recipeIds).containsExactly(15L, 14L, 13L); | ||
} | ||
|
||
@Test | ||
@DisplayName("레시피 id에 해당되는 세부 정보를 반환한다.") | ||
void findRecipeData() { | ||
List<Long> recipeIds = List.of(4L, 3L); | ||
RecipeDataResponse expectedData = new RecipeDataResponse(4, "흰쌀밥", 1, "loki", "loki.jpg", LocalTime.of(0, 40), | ||
"흰쌀밥이미지.jpg", 2, 4, "흰쌀밥 조리법", 3, "채식", 2, "쌀", REQUIRED | ||
RecipeDataResponse expectedData = new RecipeDataResponse(4, "토마토스파게티", 1, "loki", "loki.jpg", LocalTime.of(0, 30), | ||
"토마토스파게티이미지.jpg", 3, 2, "토마토스파게티 조리법", 2, "양식", 2, "쌀", REQUIRED | ||
); | ||
|
||
List<RecipeDataResponse> recipeData = repository.findRecipeData(recipeIds); | ||
|
||
assertAll( | ||
() -> assertThat(recipeData).hasSize(8), | ||
() -> assertThat(recipeData).hasSize(6 + 3), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 작성했던 부분이지만 다시 봐도 검증 방식이 애매하긴 하네요. 🥲 데이터 가져오는 방식이나 쿼리문을 향후 개선하기는 해야할 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해석하느라 초큼 힘들었습니다 |
||
() -> assertThat(recipeData).contains(expectedData) | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이제 슬슬 해당 DTO 안에 validation 을 추가하는 것은 어떠신가요~?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금 새로 이슈 파놓고 댓글 완성되면 바로 진행해보겠습니다