-
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
♻️ separate recipe info query #445
base: be/dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.pengcook.category.dto; | ||
|
||
import net.pengcook.category.domain.Category; | ||
|
||
public record CategoryResponse(long categoryId, String categoryName) { | ||
|
||
public CategoryResponse(Category category) { | ||
this(category.getId(), category.getName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.pengcook.ingredient.dto; | ||
|
||
import net.pengcook.ingredient.domain.IngredientRecipe; | ||
import net.pengcook.ingredient.domain.Requirement; | ||
|
||
public record IngredientResponse(long ingredientId, String ingredientName, Requirement requirement) { | ||
|
||
public IngredientResponse(IngredientRecipe ingredientRecipe) { | ||
this( | ||
ingredientRecipe.getIngredient().getId(), | ||
ingredientRecipe.getIngredient().getName(), | ||
ingredientRecipe.getRequirement()) | ||
; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
import net.pengcook.ingredient.domain.IngredientRecipe; | ||
import net.pengcook.ingredient.domain.Requirement; | ||
import net.pengcook.ingredient.dto.IngredientCreateRequest; | ||
import net.pengcook.ingredient.dto.IngredientResponse; | ||
import net.pengcook.ingredient.exception.InvalidNameException; | ||
import net.pengcook.ingredient.repository.IngredientRecipeRepository; | ||
import net.pengcook.ingredient.repository.IngredientRepository; | ||
import net.pengcook.recipe.domain.Recipe; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -21,6 +23,7 @@ | |
public class IngredientService { | ||
|
||
private final IngredientRepository ingredientRepository; | ||
private final IngredientRecipeRepository ingredientRecipeRepository; | ||
private final IngredientRecipeService ingredientRecipeService; | ||
private final IngredientSubstitutionService ingredientSubstitutionService; | ||
|
||
|
@@ -32,6 +35,13 @@ public void register(List<IngredientCreateRequest> requests, Recipe recipe) { | |
} | ||
} | ||
|
||
public List<IngredientResponse> findIngredientByRecipe(Recipe recipe) { | ||
Comment on lines
37
to
+38
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.
|
||
return ingredientRecipeRepository.findAllByRecipeId(recipe.getId()) | ||
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. 크게 문제가 될것 같지는 않지만 다른 로직에서 대부분 아이디로 조회하고 있네요. 수정하는것도 좋아 보입니다! |
||
.stream() | ||
.map(IngredientResponse::new) | ||
.toList(); | ||
} | ||
|
||
private void registerOne(IngredientCreateRequest request, Recipe recipe) { | ||
Ingredient ingredient = registerOrGetIngredient(request.name()); | ||
IngredientRecipe ingredientRecipe = registerIngredientRecipe(recipe, request, ingredient); | ||
|
@@ -87,5 +97,4 @@ private boolean hasDuplicateName(List<String> names) { | |
HashSet<String> nonDuplicate = new HashSet<>(names); | ||
return (names.size() != nonDuplicate.size()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
package net.pengcook.recipe.dto; | ||
|
||
import net.pengcook.user.domain.User; | ||
|
||
public record AuthorResponse(long authorId, String authorName, String authorImage) { | ||
|
||
public AuthorResponse(User author) { | ||
this(author.getId(), author.getUsername(), author.getImage()); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
import java.time.LocalTime; | ||
import java.util.List; | ||
import net.pengcook.authentication.domain.UserInfo; | ||
import net.pengcook.category.dto.CategoryResponse; | ||
import net.pengcook.ingredient.dto.IngredientResponse; | ||
import net.pengcook.recipe.domain.Recipe; | ||
|
||
public record RecipeDescriptionResponse( | ||
long recipeId, | ||
|
@@ -24,25 +27,25 @@ public record RecipeDescriptionResponse( | |
|
||
public RecipeDescriptionResponse( | ||
UserInfo userInfo, | ||
RecipeDataResponse firstResponse, | ||
Recipe recipe, | ||
List<CategoryResponse> category, | ||
List<IngredientResponse> ingredient, | ||
boolean isLike | ||
Comment on lines
28
to
33
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. 👍👍 |
||
) { | ||
this( | ||
firstResponse.recipeId(), | ||
firstResponse.title(), | ||
new AuthorResponse(firstResponse.authorId(), firstResponse.authorName(), firstResponse.authorImage()), | ||
firstResponse.cookingTime(), | ||
firstResponse.thumbnail(), | ||
firstResponse.difficulty(), | ||
firstResponse.likeCount(), | ||
firstResponse.commentCount(), | ||
firstResponse.description(), | ||
firstResponse.createdAt(), | ||
recipe.getId(), | ||
recipe.getTitle(), | ||
new AuthorResponse(recipe.getAuthor()), | ||
recipe.getCookingTime(), | ||
recipe.getThumbnail(), | ||
recipe.getDifficulty(), | ||
recipe.getLikeCount(), | ||
recipe.getCommentCount(), | ||
recipe.getDescription(), | ||
recipe.getCreatedAt(), | ||
category, | ||
ingredient, | ||
userInfo.isSameUser(firstResponse.authorId()), | ||
userInfo.isSameUser(recipe.getAuthor().getId()), | ||
Comment on lines
-45
to
+48
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. 👍 |
||
isLike | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,35 +94,6 @@ List<Long> findRecipeIdsByCategoryAndKeyword( | |
""") | ||
List<RecipeHomeResponse> findRecipeDataV1(List<Long> recipeIds); | ||
|
||
@Query(""" | ||
SELECT new net.pengcook.recipe.dto.RecipeDataResponse( | ||
r.id, | ||
r.title, | ||
r.author.id, | ||
r.author.username, | ||
r.author.image, | ||
Comment on lines
-97
to
-103
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. 👍👍 |
||
r.cookingTime, | ||
r.thumbnail, | ||
r.difficulty, | ||
r.likeCount, | ||
r.commentCount, | ||
r.description, | ||
r.createdAt, | ||
c.id, | ||
c.name, | ||
i.id, | ||
i.name, | ||
ir.requirement | ||
) | ||
FROM Recipe r | ||
JOIN FETCH CategoryRecipe cr ON cr.recipe = r | ||
JOIN FETCH Category c ON cr.category = c | ||
JOIN FETCH IngredientRecipe ir ON ir.recipe = r | ||
JOIN FETCH Ingredient i ON ir.ingredient = i | ||
WHERE r.id = :recipeId | ||
""") | ||
List<RecipeDataResponse> findRecipeData(long recipeId); | ||
|
||
@Query(""" | ||
SELECT r.id | ||
FROM Recipe r | ||
|
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.
말도안돼