Skip to content

Commit

Permalink
Merge pull request #20 from soodgarak/Feat/get-recipe-list
Browse files Browse the repository at this point in the history
Fix: totalCount 조회 기능 수정
  • Loading branch information
ratcomp9992 committed Aug 29, 2024
2 parents 860353a + 000aa41 commit c268dba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
public interface RecipeRepository extends JpaRepository<Recipe, Long> {
Long countByMbtiStartingWith(String keyword);
Long countByMbtiEndingWith(String keyword);
Long countByMenuContaining(String keyword);
Long countByIngredientContaining(String keyword);
Long countByMenuOrIngredientContaining(String menuKeyword, String ingredientKeyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private Long countData(String keyword) {
if (searchRecipeRedis.existsById(countCheckValue)) {
return searchRecipeRedis.findById((countCheckValue)).orElse(null).getRecipeId();
}
totalCount = recipeRepository.countByMenuContaining(keyword) + recipeRepository.countByIngredientContaining(keyword);
totalCount = recipeRepository.countByMenuOrIngredientContaining(keyword, keyword);
searchRecipeRedis.save(RedisSearchRecipe.of(countCheckValue, totalCount));
}

Expand All @@ -95,26 +95,29 @@ private boolean checkNextData(RecipeGroup group, Long totalCount) {
}

public RecipeWithCountResponse getResponse(String keyword, RequestType requestType) {
Long totalCount = countData(keyword);
Long totalCount;
boolean hasNextData;
List<RecipeResponse> recipeResponseList;

if (keyword.isBlank()) {
hasNextData = checkNextData(RecipeGroup.ALL, totalCount);
if (requestType.equals(RequestType.INIT)) { recipeResponseList = getInitAllRecipeList(); }
else { recipeResponseList = addFromAllRecipeList(); }
totalCount = countData(keyword);
hasNextData = checkNextData(RecipeGroup.ALL, totalCount);
} else if (keyword.equals("M") || keyword.equals("S")
|| keyword.equals("V") || keyword.equals("H") || keyword.equals("N")) {
hasNextData = checkNextData(RecipeGroup.CATEGORY, totalCount);
if (requestType.equals(RequestType.INIT)) { recipeResponseList = getInitCategoryRecipeList(keyword); }
else { recipeResponseList = addFromCategoryRecipeList(keyword); }
totalCount = countData(keyword);
hasNextData = checkNextData(RecipeGroup.CATEGORY, totalCount);
} else {
hasNextData = checkNextData(RecipeGroup.SEARCH, totalCount);
if (requestType.equals(RequestType.INIT)) { recipeResponseList = getInitSearchRecipeList(keyword); }
else { recipeResponseList = addFromSearchRecipeList(keyword); }

totalCount = countData(keyword);
hasNextData = checkNextData(RecipeGroup.SEARCH, totalCount);
}


return RecipeWithCountResponse.of(
totalCount,
hasNextData,
Expand Down

0 comments on commit c268dba

Please sign in to comment.