diff --git a/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/application/RecipeService.java b/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/application/RecipeService.java index 9a30ec0..a976ec7 100644 --- a/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/application/RecipeService.java +++ b/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/application/RecipeService.java @@ -10,7 +10,6 @@ import com.sundaegukbap.banchango.recipe.domain.Recipe; import com.sundaegukbap.banchango.recipe.domain.RecipeCategory; import com.sundaegukbap.banchango.recipe.domain.UserRecommendedRecipe; -import com.sundaegukbap.banchango.recipe.dto.event.RecommendedRecipeCategoryChangedEvent; import com.sundaegukbap.banchango.recipe.repository.RecipeRepository; import com.sundaegukbap.banchango.recipe.repository.RecommendedRecipeRepository; import com.sundaegukbap.banchango.user.domain.User; @@ -36,16 +35,15 @@ public class RecipeService { @EventListener public void refreshRecommendedRecipes(IngredientChangedEvent event) { - refreshRecommendedRecipes(event.userId()); + refreshRecommendedRecipes(event.userId(), RecipeCategory.전체); } - @EventListener - public void refreshRecommendedRecipes(RecommendedRecipeCategoryChangedEvent event) { - refreshRecommendedRecipes(event.userId()); + public void changeRecipeCategory(Long userId, RecipeCategory recipeCategory) { + refreshRecommendedRecipes(userId, recipeCategory); } @Transactional - public void refreshRecommendedRecipes(Long userId) { + public void refreshRecommendedRecipes(Long userId, RecipeCategory recipeCategory) { List containers = containerRepository.findAllByUserId(userId); List containerIngredients = containerIngredientRepository.findByContainerIn(containers); List ingredients = containerIngredients.stream() @@ -56,7 +54,7 @@ public void refreshRecommendedRecipes(Long userId) { User user = userRepository.findById(userId) .orElseThrow(() -> new NoSuchElementException("no user")); - List recommendedRecipeIds = aiRecipeRecommendClient.getRecommendedRecipesFromAI(RecipeCategory.전체, ingredients); + List recommendedRecipeIds = aiRecipeRecommendClient.getRecommendedRecipesFromAI(recipeCategory, ingredients); List recipes = recipeRepository.findAllById(recommendedRecipeIds); List recommendedRecipes = recipes.stream() .map(recipe -> UserRecommendedRecipe.builder() diff --git a/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/dto/event/RecommendedRecipeCategoryChangedEvent.java b/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/dto/event/RecommendedRecipeCategoryChangedEvent.java index 9323adf..32ae4ae 100644 --- a/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/dto/event/RecommendedRecipeCategoryChangedEvent.java +++ b/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/dto/event/RecommendedRecipeCategoryChangedEvent.java @@ -1,6 +1,9 @@ package com.sundaegukbap.banchango.recipe.dto.event; +import com.sundaegukbap.banchango.recipe.domain.RecipeCategory; + public record RecommendedRecipeCategoryChangedEvent( - Long userId + Long userId, + RecipeCategory recipeCategory ) { } diff --git a/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/presentation/RecipeController.java b/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/presentation/RecipeController.java index 804e184..914d90e 100644 --- a/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/presentation/RecipeController.java +++ b/Server/banchango/src/main/java/com/sundaegukbap/banchango/recipe/presentation/RecipeController.java @@ -1,6 +1,7 @@ package com.sundaegukbap.banchango.recipe.presentation; import com.sundaegukbap.banchango.recipe.application.RecipeQueryService; +import com.sundaegukbap.banchango.recipe.application.RecipeService; import com.sundaegukbap.banchango.recipe.domain.RecipeCategory; import com.sundaegukbap.banchango.recipe.dto.response.RecommendedRecipeResponse; import com.sundaegukbap.banchango.recipe.dto.response.RecommendedRecipeResponses; @@ -11,6 +12,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -21,17 +23,13 @@ @Tag(name = "레시피 조회 관련 컨트롤러") public class RecipeController { private final RecipeQueryService recipeQueryService; + private final RecipeService recipeService; @GetMapping("/recommend/{userId}") - @Operation(summary = "추천 레시피 목록 조회", - description = "추천 레시피 목록을 조회합니다.\n" + - "카테고리 종류(전체)\n" + - "* 현재 카테고리는 개발중에 있습니다.") + @Operation(summary = "추천 레시피 목록 조회", description = "추천 레시피 목록을 조회합니다.") public ResponseEntity getRecommendedRecipes(@PathVariable("userId") Long userId, @RequestParam(defaultValue = "0") int pageIndex, - @RequestParam(defaultValue = "10") int pageSize, - @RequestParam(defaultValue = "전체") RecipeCategory category - ) { + @RequestParam(defaultValue = "10") int pageSize) { RecommendedRecipeResponses response = recipeQueryService.getRecommendedRecipes(pageIndex, pageSize, userId); return new ResponseEntity<>(response, HttpStatus.OK); } @@ -39,7 +37,15 @@ public ResponseEntity getRecommendedRecipes(@PathVar @GetMapping("/{userId}/{recipeId}") @Operation(summary = "특정 레시피 상세 조회", description = "레시피를 조회한다.") public ResponseEntity getRecipeDetail(@PathVariable("userId") Long userId, @PathVariable("recipeId") Long recipeId) { - RecommendedRecipeResponse response = recipeQueryService.getRecipeDetail(userId,recipeId); + RecommendedRecipeResponse response = recipeQueryService.getRecipeDetail(userId, recipeId); return new ResponseEntity<>(response, HttpStatus.OK); } + + @PostMapping("/{userId}") + @Operation(summary = "추천 레시피 카테고리 변경", description = "추천 레시피 카테고리를 변경하고 새로운 추천 레시피를 받아옵니다.") + public ResponseEntity changeRecipeCategory(@PathVariable("userId") Long userId, + @RequestParam(defaultValue = "전체") RecipeCategory recipeCategory) { + recipeService.changeRecipeCategory(userId, recipeCategory); + return new ResponseEntity<>("카테고리에 맞게 추천 레시피목록이 변경되었습니다.", HttpStatus.OK); + } }