diff --git a/backend/src/main/java/net/pengcook/recipe/dto/RecipeDescriptionResponse.java b/backend/src/main/java/net/pengcook/recipe/dto/RecipeDescriptionResponse.java index 4a4ce6f6..d367955f 100644 --- a/backend/src/main/java/net/pengcook/recipe/dto/RecipeDescriptionResponse.java +++ b/backend/src/main/java/net/pengcook/recipe/dto/RecipeDescriptionResponse.java @@ -18,14 +18,16 @@ public record RecipeDescriptionResponse( LocalDateTime createdAt, List category, List ingredient, - boolean mine + boolean mine, + boolean isLike ) { public RecipeDescriptionResponse( UserInfo userInfo, RecipeDataResponse firstResponse, List category, - List ingredient + List ingredient, + boolean isLike ) { this( firstResponse.recipeId(), @@ -40,7 +42,8 @@ public RecipeDescriptionResponse( firstResponse.createdAt(), category, ingredient, - userInfo.isSameUser(firstResponse.authorId()) + userInfo.isSameUser(firstResponse.authorId()), + isLike ); } } diff --git a/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java b/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java index 5efec0fb..59151437 100644 --- a/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java +++ b/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java @@ -195,12 +195,14 @@ public void updateRecipe(UserInfo userInfo, Long recipeId, RecipeUpdateRequest r @Transactional(readOnly = true) public RecipeDescriptionResponse readRecipeDescription(UserInfo userInfo, long recipeId) { List recipeDataResponses = recipeRepository.findRecipeData(recipeId); + boolean isLike = likeRepository.existsByUserIdAndRecipeId(userInfo.getId(), recipeId); return new RecipeDescriptionResponse( userInfo, recipeDataResponses.getFirst(), getCategoryResponses(recipeDataResponses), - getIngredientResponses(recipeDataResponses) + getIngredientResponses(recipeDataResponses), + isLike ); } diff --git a/backend/src/test/java/net/pengcook/recipe/controller/RecipeControllerTest.java b/backend/src/test/java/net/pengcook/recipe/controller/RecipeControllerTest.java index 02a0ab50..2369271c 100644 --- a/backend/src/test/java/net/pengcook/recipe/controller/RecipeControllerTest.java +++ b/backend/src/test/java/net/pengcook/recipe/controller/RecipeControllerTest.java @@ -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, @@ -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) diff --git a/backend/src/test/resources/data/recipe.sql b/backend/src/test/resources/data/recipe.sql index 2739e031..ea5ab388 100644 --- a/backend/src/test/resources/data/recipe.sql +++ b/backend/src/test/resources/data/recipe.sql @@ -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;