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

๐Ÿ› add isLike to RecipeDescriptionResponse #418

Merged
merged 2 commits into from
Oct 23, 2024
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 @@ -18,14 +18,16 @@ public record RecipeDescriptionResponse(
LocalDateTime createdAt,
List<CategoryResponse> category,
List<IngredientResponse> ingredient,
boolean mine
boolean mine,
boolean isLike
) {

public RecipeDescriptionResponse(
UserInfo userInfo,
RecipeDataResponse firstResponse,
List<CategoryResponse> category,
List<IngredientResponse> ingredient
List<IngredientResponse> ingredient,
boolean isLike
) {
this(
firstResponse.recipeId(),
Expand All @@ -40,7 +42,8 @@ public RecipeDescriptionResponse(
firstResponse.createdAt(),
category,
ingredient,
userInfo.isSameUser(firstResponse.authorId())
userInfo.isSameUser(firstResponse.authorId()),
isLike
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ public void updateRecipe(UserInfo userInfo, Long recipeId, RecipeUpdateRequest r
@Transactional(readOnly = true)
public RecipeDescriptionResponse readRecipeDescription(UserInfo userInfo, long recipeId) {
List<RecipeDataResponse> recipeDataResponses = recipeRepository.findRecipeData(recipeId);
boolean isLike = likeRepository.existsByUserIdAndRecipeId(userInfo.getId(), recipeId);

return new RecipeDescriptionResponse(
userInfo,
recipeDataResponses.getFirst(),
getCategoryResponses(recipeDataResponses),
getIngredientResponses(recipeDataResponses)
getIngredientResponses(recipeDataResponses),
isLike
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ void readRecipeDescription() {
List.of(new IngredientResponse(2, "์Œ€", Requirement.REQUIRED),
new IngredientResponse(3, "๊ณ„๋ž€", Requirement.OPTIONAL),
new IngredientResponse(4, "๊น€์น˜", Requirement.REQUIRED)),
true);
true,
false);

RecipeDescriptionResponse actual = RestAssured.given(spec).log().all()
.filter(document(DEFAULT_RESTDOCS_PATH,
Expand Down Expand Up @@ -521,7 +522,8 @@ void readRecipeDescription() {
fieldWithPath("ingredient[].ingredientId").description("์žฌ๋ฃŒ ์•„์ด๋””"),
fieldWithPath("ingredient[].ingredientName").description("์žฌ๋ฃŒ ์ด๋ฆ„"),
fieldWithPath("ingredient[].requirement").description("์žฌ๋ฃŒ ํ•„์ˆ˜ ์—ฌ๋ถ€"),
fieldWithPath("mine").description("์กฐํšŒ์ž ์ž‘์„ฑ์—ฌ๋ถ€")
fieldWithPath("mine").description("์กฐํšŒ์ž ์ž‘์„ฑ ์—ฌ๋ถ€"),
fieldWithPath("isLike").description("์กฐํšŒ์ž ์ข‹์•„์š” ์—ฌ๋ถ€")
)))
.when()
.get("/recipes/{recipeId}", 2L)
Expand Down
3 changes: 3 additions & 0 deletions backend/src/test/resources/data/recipe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ALTER TABLE ingredient_recipe ALTER COLUMN id RESTART;
TRUNCATE TABLE recipe_step;
ALTER TABLE recipe_step ALTER COLUMN id RESTART;

TRUNCATE TABLE recipe_like;
ALTER TABLE recipe_like ALTER COLUMN id RESTART;

TRUNCATE TABLE user_block;
ALTER TABLE user_block ALTER COLUMN id RESTART WITH 1;

Expand Down
Loading