Skip to content

Commit 0932192

Browse files
authored
Merge pull request #139 from SWU-Elixir/feat/3-recipe-CRUD
feat: 레시피 수정 시 RecipeDetailResponseDTO를 반환하도록 수정
2 parents 820c363 + a4707ef commit 0932192

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

src/main/java/BE_Elixir/Elixir/domain/recipe/controller/RecipeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public ResponseEntity<CommonResponse<?>> updateRecipe(
139139
@AuthenticationPrincipal MemberDetails memberDetails
140140
) {
141141
Member member = memberDetails.getMember();
142-
RecipeResponseDTO response = recipeService.updateRecipe(recipeId, dto, image, recipeStepImages, member);
142+
RecipeDetailResponseDTO response = recipeService.updateRecipe(recipeId, dto, image, recipeStepImages, member);
143143
return ResponseEntity.ok(CommonResponse.success(
144144
HttpStatus.OK.value(), HttpStatus.OK.toString(),
145145
"레시피 수정 성공", response

src/main/java/BE_Elixir/Elixir/domain/recipe/controller/api/RecipeApi.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,25 +374,36 @@ ResponseEntity<CommonResponse<?>> getSearchKeyword(
374374
"code": "200 OK",
375375
"message": "레시피 수정 성공",
376376
"data": {
377-
"id": 49,
378-
"email": "[email protected]",
379-
"title": "닭가슴살 덮밥",
380-
"imageUrl": "http://www.foodsafetykorea.go.kr/uploadimg/cook/10_00281_1.png",
381-
"description": "닭가슴살로 간단히 덮밥해먹기",
382-
"categorySlowAging": "염증감소",
377+
"authorFollowByCurrentUser": false,
378+
"likedByCurrentUser": false,
379+
"scrappedByCurrentUser": false,
380+
"id": 181,
381+
"authorId": 1,
382+
"title": "닭가슴살 덮밥 수정하기",
383+
"imageUrl": "http://foodsafetykorea/food.jpg",
384+
"description": "굽기",
385+
"categorySlowAging": "항산화강화",
383386
"categoryType": "한식",
384387
"difficulty": "쉬움",
385388
"timeHours": 0,
386389
"timeMinutes": 45,
387390
"ingredientTagIds": [
388391
1
389392
],
390-
"ingredients": {
391-
"물": "2ml(1/3작은술)"
392-
},
393-
"seasoning": {
394-
"설탕": "2g(1/3작은술)"
395-
},
393+
"ingredients": [
394+
{
395+
"name": "닭",
396+
"value": "1",
397+
"unit": "마리"
398+
}
399+
],
400+
"seasonings": [
401+
{
402+
"name": "설탕",
403+
"value": "1",
404+
"unit": "T"
405+
}
406+
],
396407
"stepDescriptions": [
397408
"닭가슴살을 전자레인지에 데운다"
398409
],

src/main/java/BE_Elixir/Elixir/domain/recipe/service/RecipeService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void saveSearchKeyword(String keyword) {
221221

222222
// 레시피 수정
223223
@Transactional
224-
public RecipeResponseDTO updateRecipe(
224+
public RecipeDetailResponseDTO updateRecipe(
225225
Long recipeId,
226226
RecipeRequestDTO dto,
227227
MultipartFile image,
@@ -278,7 +278,16 @@ public RecipeResponseDTO updateRecipe(
278278
);
279279

280280
recipeRepository.save(recipe);
281-
return new RecipeResponseDTO(recipe);
281+
282+
// 레시피 작성자
283+
Member authorRecipe = recipe.getMember();
284+
285+
// 작성자 팔로우 여부 확인
286+
boolean authorFollowByCurrentUser = followRepository.existsByFollowerAndFollowing(member, authorRecipe);
287+
// 좋아요 및 스크랩 여부 확인
288+
boolean likedByCurrentUser = recipeEventRepository.existsByRecipeIdAndMemberIdAndLikeFlagTrue(recipeId, member.getId());
289+
boolean scrappedByCurrentUser = recipeEventRepository.existsByRecipeIdAndMemberIdAndScrapFlagTrue(recipeId, member.getId());
290+
return new RecipeDetailResponseDTO(recipe, authorFollowByCurrentUser, likedByCurrentUser, scrappedByCurrentUser);
282291
}
283292

284293
// 레시피 삭제

0 commit comments

Comments
 (0)