Skip to content

Commit

Permalink
πŸ› add isLike to RecipeDescriptionResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxrxn committed Oct 23, 2024
1 parent 5ecadf9 commit d2109d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
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

0 comments on commit d2109d9

Please sign in to comment.