From 8ad1f5470750ad79086236798605a111e4febd39 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Tue, 6 Feb 2024 01:29:26 +0900 Subject: [PATCH 1/2] =?UTF-8?q?typo:=20enum=20=EB=B0=8F=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=EB=AA=85=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../puremarket/common/enums/BaseResponseStatus.java | 9 +++++---- .../kkobugi/puremarket/common/enums/IngredientType.java | 2 +- .../giveaway/presentation/GiveawayController.java | 4 ++-- .../produce/presentation/ProduceController.java | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/kkobugi/puremarket/common/enums/BaseResponseStatus.java b/src/main/java/com/kkobugi/puremarket/common/enums/BaseResponseStatus.java index 5c83f0f..67fcf10 100644 --- a/src/main/java/com/kkobugi/puremarket/common/enums/BaseResponseStatus.java +++ b/src/main/java/com/kkobugi/puremarket/common/enums/BaseResponseStatus.java @@ -19,21 +19,22 @@ public enum BaseResponseStatus { INVALID_PASSWORD(false, 2003, "비밀번호가 잘못되었습니다."), INVALID_LOGIN_ID(false, 2004, "잘못된 아이디입니다."), INVALID_ACCESS_TOKEN(false, 2005, "잘못된 AccessToken 입니다."), - INVALID_REFRESH_TOKEN(false, 2006, "잘못된 RefreshToken 입니다."), - NULL_ACCESS_TOKEN(false, 2007, "AccessToken을 입력해주세요."), + INVALID_REFRESH_TOKEN(false, 2006, "잘못된 Refresh Token 입니다."), + NULL_ACCESS_TOKEN(false, 2007, "Access Token을 입력해주세요."), // produce(2100-2199) - INVALID_PRODUCE_IDX(false, 2100, "잘못된 produce idx 입니다."), + INVALID_PRODUCE_IDX(false, 2100, "잘못된 판매글 idx 입니다."), TITLE_EXCEEDED_MAX_LIMIT(false, 2101, "제목은 32자 이하여야 합니다."), NO_PRODUCE_WRITER(false, 2102, "해당 판매글의 작성자가 아닙니다."), ALREADY_DELETED_PRODUCE(false, 2103, "이미 삭제된 판매글입니다."), // recipe(2200-2299) + INVALID_RECIPE_IDX(false, 2200, "잘못된 레시피글 idx 입니다."), // ingredient(2300-2399) // giveaway(2400-2499) - INVALID_GIVEAWAY_IDX(false, 2400, "잘못된 giveaway idx 입니다."), + INVALID_GIVEAWAY_IDX(false, 2400, "잘못된 나눔글 idx 입니다."), NO_GIVEAWAY_WRITER(false, 2401, "해당 나눔글의 작성자가 아닙니다."), ALREADY_DELETED_GIVEAWAY(false, 2402, "이미 삭제된 나눔글입니다."), diff --git a/src/main/java/com/kkobugi/puremarket/common/enums/IngredientType.java b/src/main/java/com/kkobugi/puremarket/common/enums/IngredientType.java index ecb3bd9..1572038 100644 --- a/src/main/java/com/kkobugi/puremarket/common/enums/IngredientType.java +++ b/src/main/java/com/kkobugi/puremarket/common/enums/IngredientType.java @@ -5,5 +5,5 @@ @Getter public enum IngredientType { INGREDIENT, - SOURCE + SAUCE } \ No newline at end of file diff --git a/src/main/java/com/kkobugi/puremarket/giveaway/presentation/GiveawayController.java b/src/main/java/com/kkobugi/puremarket/giveaway/presentation/GiveawayController.java index eafe627..caafe4b 100644 --- a/src/main/java/com/kkobugi/puremarket/giveaway/presentation/GiveawayController.java +++ b/src/main/java/com/kkobugi/puremarket/giveaway/presentation/GiveawayController.java @@ -33,7 +33,7 @@ public BaseResponse getGiveawayList() { // 나눔글 상세 조회 @GetMapping("/{giveawayIdx}") - public BaseResponse getGiveawayList(@PathVariable Long giveawayIdx) { + public BaseResponse getGiveaway(@PathVariable Long giveawayIdx) { try { return new BaseResponse<>(giveawayService.getGiveawayPost(giveawayIdx)); } catch (BaseException e) { @@ -65,7 +65,7 @@ public BaseResponse changeGiveawayStatus(@PathVariable Long giveawayIdx) { // [작성자] 나눔글 삭제 @PatchMapping("") - public BaseResponse deleteProduce(@RequestParam Long giveawayIdx) { + public BaseResponse deleteGiveaway(@RequestParam Long giveawayIdx) { try { giveawayService.deleteGiveaway(giveawayIdx); return new BaseResponse<>(SUCCESS); diff --git a/src/main/java/com/kkobugi/puremarket/produce/presentation/ProduceController.java b/src/main/java/com/kkobugi/puremarket/produce/presentation/ProduceController.java index 690023c..ca0953e 100644 --- a/src/main/java/com/kkobugi/puremarket/produce/presentation/ProduceController.java +++ b/src/main/java/com/kkobugi/puremarket/produce/presentation/ProduceController.java @@ -33,7 +33,7 @@ public BaseResponse getProduceList() { // 판매글 상세 조회 @GetMapping("/{produceIdx}") - public BaseResponse getProduceList(@PathVariable Long produceIdx) { + public BaseResponse getProduce(@PathVariable Long produceIdx) { try { return new BaseResponse<>(produceService.getProducePost(produceIdx)); } catch (BaseException e) { From 2efad3a5cdbba6d2d3783e448eb884f4538632d5 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Tue, 6 Feb 2024 01:30:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#9=20feat:=20=EB=A0=88=EC=8B=9C=ED=94=BC?= =?UTF-8?q?=EA=B8=80=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/IngredientRepository.java | 12 +++++ .../recipe/application/RecipeService.java | 51 ++++++++++++++++++- .../recipe/domain/dto/RecipeResponse.java | 19 +++++++ .../domain/entity/RecipeDescription.java | 2 +- .../recipe/presentation/RecipeController.java | 11 ++++ .../RecipeDescriptionRepository.java | 11 ++++ 6 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/kkobugi/puremarket/ingredient/repository/IngredientRepository.java create mode 100644 src/main/java/com/kkobugi/puremarket/recipe/domain/dto/RecipeResponse.java create mode 100644 src/main/java/com/kkobugi/puremarket/recipe/repository/RecipeDescriptionRepository.java diff --git a/src/main/java/com/kkobugi/puremarket/ingredient/repository/IngredientRepository.java b/src/main/java/com/kkobugi/puremarket/ingredient/repository/IngredientRepository.java new file mode 100644 index 0000000..919b6bf --- /dev/null +++ b/src/main/java/com/kkobugi/puremarket/ingredient/repository/IngredientRepository.java @@ -0,0 +1,12 @@ +package com.kkobugi.puremarket.ingredient.repository; + +import com.kkobugi.puremarket.common.enums.IngredientType; +import com.kkobugi.puremarket.ingredient.domain.entity.Ingredient; +import com.kkobugi.puremarket.recipe.domain.entity.Recipe; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface IngredientRepository extends JpaRepository { + List findByRecipeAndIngredientTypeAndStatusEqualsOrderByCreatedDateDesc(Recipe recipe, IngredientType ingredientType, String status); +} diff --git a/src/main/java/com/kkobugi/puremarket/recipe/application/RecipeService.java b/src/main/java/com/kkobugi/puremarket/recipe/application/RecipeService.java index 764b441..87f0d39 100644 --- a/src/main/java/com/kkobugi/puremarket/recipe/application/RecipeService.java +++ b/src/main/java/com/kkobugi/puremarket/recipe/application/RecipeService.java @@ -1,20 +1,30 @@ package com.kkobugi.puremarket.recipe.application; import com.kkobugi.puremarket.common.BaseException; +import com.kkobugi.puremarket.ingredient.repository.IngredientRepository; import com.kkobugi.puremarket.recipe.domain.dto.RecipeListResponse; +import com.kkobugi.puremarket.recipe.domain.dto.RecipeResponse; +import com.kkobugi.puremarket.recipe.domain.entity.Recipe; +import com.kkobugi.puremarket.recipe.repository.RecipeDescriptionRepository; import com.kkobugi.puremarket.recipe.repository.RecipeRepository; +import com.kkobugi.puremarket.user.application.AuthService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; import static com.kkobugi.puremarket.common.constants.Constant.ACTIVE; -import static com.kkobugi.puremarket.common.enums.BaseResponseStatus.DATABASE_ERROR; +import static com.kkobugi.puremarket.common.enums.BaseResponseStatus.*; +import static com.kkobugi.puremarket.common.enums.IngredientType.INGREDIENT; +import static com.kkobugi.puremarket.common.enums.IngredientType.SAUCE; @Service @RequiredArgsConstructor public class RecipeService { private final RecipeRepository recipeRepository; + private final AuthService authService; + private final IngredientRepository ingredientRepository; + private final RecipeDescriptionRepository recipeDescriptionRepository; // 레시피글 목록 조회 public RecipeListResponse getRecipeList() throws BaseException { @@ -34,4 +44,43 @@ public RecipeListResponse getRecipeList() throws BaseException { throw new BaseException(DATABASE_ERROR); } } + + // 레시피글 상세 조회 + public RecipeResponse getRecipe(Long recipeIdx) throws BaseException { + try { + Long userIdx = authService.getUserIdxFromToken(); + Recipe recipe = recipeRepository.findById(recipeIdx).orElseThrow(() -> new BaseException(INVALID_RECIPE_IDX)); + + boolean isWriter = false; + if (userIdx != null && recipe.getUser() != null) { + isWriter = userIdx.equals(recipe.getUser().getUserIdx()); + } + + // 재료 리스트 + List ingredientList = ingredientRepository.findByRecipeAndIngredientTypeAndStatusEqualsOrderByCreatedDateDesc(recipe, INGREDIENT, ACTIVE).stream() + .map(ingredient -> new RecipeResponse.IngredientDto( + ingredient.getName(), + ingredient.getQuantity())).toList(); + + // 양념 리스트 + List sauceList = ingredientRepository.findByRecipeAndIngredientTypeAndStatusEqualsOrderByCreatedDateDesc(recipe, SAUCE, ACTIVE).stream() + .map(sauce -> new RecipeResponse.SauceDto( + sauce.getName(), + sauce.getQuantity())).toList(); + + // 레시피 상세 리스트(조리 순서) + List recipeDescriptionList = recipeDescriptionRepository.findByRecipeAndStatusEqualsOrderByCreatedDateDesc(recipe, ACTIVE).stream() + .map(description -> new RecipeResponse.RecipeDescriptionDto( + description.getOrderNumber(), + description.getDescription())).toList(); + + return new RecipeResponse(recipe.getRecipeIdx(), recipe.getTitle(), recipe.getContent(), recipe.getRecipeImage(), + ingredientList, sauceList, recipeDescriptionList, + recipe.getUser().getNickname(), recipe.getUser().getContact(), recipe.getUser().getProfileImage(), isWriter); + } catch (BaseException e) { + throw e; + } catch (Exception e) { + throw new BaseException(DATABASE_ERROR); + } + } } diff --git a/src/main/java/com/kkobugi/puremarket/recipe/domain/dto/RecipeResponse.java b/src/main/java/com/kkobugi/puremarket/recipe/domain/dto/RecipeResponse.java new file mode 100644 index 0000000..be748a7 --- /dev/null +++ b/src/main/java/com/kkobugi/puremarket/recipe/domain/dto/RecipeResponse.java @@ -0,0 +1,19 @@ +package com.kkobugi.puremarket.recipe.domain.dto; + +import java.util.List; + +public record RecipeResponse(Long recipeIdx, + String title, + String content, + String recipeImage, + List ingredientList, + List sauceList, + List recipeDescriptionList, + String nickname, + String contact, + String profileImage, + boolean isWriter) { + public record IngredientDto(String name, String quantity) {} + public record SauceDto(String name, String quantity) {} + public record RecipeDescriptionDto(Integer orderNumber, String description) {} +} diff --git a/src/main/java/com/kkobugi/puremarket/recipe/domain/entity/RecipeDescription.java b/src/main/java/com/kkobugi/puremarket/recipe/domain/entity/RecipeDescription.java index ebacf3c..8a6c501 100644 --- a/src/main/java/com/kkobugi/puremarket/recipe/domain/entity/RecipeDescription.java +++ b/src/main/java/com/kkobugi/puremarket/recipe/domain/entity/RecipeDescription.java @@ -11,7 +11,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @DynamicInsert -public class RecipeDescription extends BaseEntity { // 레시피 상세 +public class RecipeDescription extends BaseEntity { // 레시피 상세(조리 순서) @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long recipeDescriptionIdx; diff --git a/src/main/java/com/kkobugi/puremarket/recipe/presentation/RecipeController.java b/src/main/java/com/kkobugi/puremarket/recipe/presentation/RecipeController.java index 19b7726..288a3f5 100644 --- a/src/main/java/com/kkobugi/puremarket/recipe/presentation/RecipeController.java +++ b/src/main/java/com/kkobugi/puremarket/recipe/presentation/RecipeController.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -30,4 +31,14 @@ public BaseResponse getRecipeList() { return new BaseResponse<>(e.getStatus()); } } + + // 레시피글 상세 조회 + @GetMapping("/{recipeIdx}") + public BaseResponse getRecipe(@PathVariable Long recipeIdx) { + try { + return new BaseResponse<>(recipeService.getRecipe(recipeIdx)); + } catch (BaseException e) { + return new BaseResponse<>(e.getStatus()); + } + } } diff --git a/src/main/java/com/kkobugi/puremarket/recipe/repository/RecipeDescriptionRepository.java b/src/main/java/com/kkobugi/puremarket/recipe/repository/RecipeDescriptionRepository.java new file mode 100644 index 0000000..77efafd --- /dev/null +++ b/src/main/java/com/kkobugi/puremarket/recipe/repository/RecipeDescriptionRepository.java @@ -0,0 +1,11 @@ +package com.kkobugi.puremarket.recipe.repository; + +import com.kkobugi.puremarket.recipe.domain.entity.Recipe; +import com.kkobugi.puremarket.recipe.domain.entity.RecipeDescription; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface RecipeDescriptionRepository extends JpaRepository { + List findByRecipeAndStatusEqualsOrderByCreatedDateDesc(Recipe recipe, String status); +}