-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix : recipe의 id는 만개의 레시피에서 직접 지정한다. * refact : 사용하지 않는 메서드 제거 * refact : recommand -> recommend * feat : ai api와 연결 확인 및 기본 베이스 구현 * refact : aiBaseUrl은 프로퍼티에 저장해두고 사용한다. * feat : AI와 연결하여 유저의 소유 재료 변경시 event를 발행해 recipe를 새로 추천 받아 DB에 저장한다. 및 리팩토링 * refact : 폴더 구조 리팩토링 및 테스트 코드 주석처리 * refact : 서비스 클래스에서 @RequiredConstructor를 사용하여 의존성을 주입받고, 메서드에 @transactional을 적용한다. * feat : 레시피 카테고리 추가 * refact : IngredientChangedEvent는 ingredientService에서 발행하므로 위치 변경 * refact : import 수정 * feat : 추천 레시피 목록 조회시 페이지네이션을 수행한다. * feat : 추천 레시피 카테고리를 변경하는 api 추가 * refact : 불필요한 transactional 제거 * fix : 레시피 테이블의 이름은 recipes이다. * refact : EOL 추가
- Loading branch information
Showing
34 changed files
with
621 additions
and
422 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...ango/src/main/java/com/sundaegukbap/banchango/ai/application/AiRecipeRecommendClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.sundaegukbap.banchango.ai.application; | ||
|
||
import com.sundaegukbap.banchango.ai.dto.AiRecipeRecommendRequest; | ||
import com.sundaegukbap.banchango.ai.dto.AiRecipeRecommendResponse; | ||
import com.sundaegukbap.banchango.ingredient.domain.Ingredient; | ||
import com.sundaegukbap.banchango.recipe.domain.RecipeCategory; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class AiRecipeRecommendClient { | ||
@Value("${api.aiBaseUrl}") | ||
private String aiBaseUrl; | ||
private final RestTemplate restTemplate; | ||
|
||
public AiRecipeRecommendClient(RestTemplate restTemplate) { | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
@Transactional | ||
public List<Long> getRecommendedRecipesFromAI(RecipeCategory category, List<Ingredient> ingredientList) { | ||
AiRecipeRecommendRequest request = AiRecipeRecommendRequest.of(ingredientList); | ||
AiRecipeRecommendResponse response = restTemplate.postForObject(aiBaseUrl + "/recommend", request, AiRecipeRecommendResponse.class); | ||
|
||
return response.recommended_recipes(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...r/banchango/src/main/java/com/sundaegukbap/banchango/ai/dto/AiRecipeRecommendRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.sundaegukbap.banchango.ai.dto; | ||
|
||
import com.sundaegukbap.banchango.ingredient.domain.Ingredient; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record AiRecipeRecommendRequest( | ||
List<Long> ingredients | ||
) { | ||
public static AiRecipeRecommendRequest of(List<Ingredient> ingredients) { | ||
List<Long> ingredientIds = ingredients.stream() | ||
.map(Ingredient::getId) | ||
.collect(Collectors.toList()); | ||
|
||
return new AiRecipeRecommendRequest(ingredientIds); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
.../banchango/src/main/java/com/sundaegukbap/banchango/ai/dto/AiRecipeRecommendResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.sundaegukbap.banchango.ai.dto; | ||
|
||
import java.util.List; | ||
|
||
public record AiRecipeRecommendResponse( | ||
List<Long> recommended_recipes | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Server/banchango/src/main/java/com/sundaegukbap/banchango/config/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.sundaegukbap.banchango.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class AppConfig { | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,4 @@ | |
@Configuration | ||
@EnableJpaAuditing | ||
public class JpaAuditingConfig { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 9 additions & 33 deletions
42
...c/main/java/com/sundaegukbap/banchango/ingredient/application/IngredientQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,43 @@ | ||
package com.sundaegukbap.banchango.ingredient.application; | ||
|
||
import com.sundaegukbap.banchango.container.domain.Container; | ||
import com.sundaegukbap.banchango.container.repository.ContainerRepository; | ||
import com.sundaegukbap.banchango.ingredient.domain.ContainerIngredient; | ||
import com.sundaegukbap.banchango.ingredient.dto.CategoryIngredientResponse; | ||
import com.sundaegukbap.banchango.ingredient.dto.CategoryIngredientResponses; | ||
import com.sundaegukbap.banchango.ingredient.dto.IngredientDetailResponse; | ||
import com.sundaegukbap.banchango.ingredient.dto.IngredientDetailResponses; | ||
import com.sundaegukbap.banchango.ingredient.dto.dto.ContainerIngredientDto; | ||
import com.sundaegukbap.banchango.ingredient.dto.dto.ContainerIngredientDtos; | ||
import com.sundaegukbap.banchango.ingredient.repository.ContainerIngredientRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class IngredientQueryService { | ||
private final ContainerRepository containerRepository; | ||
private final ContainerIngredientRepository containerIngredientRepository; | ||
|
||
public IngredientQueryService(ContainerRepository containerRepository, ContainerIngredientRepository containerIngredientRepository) { | ||
this.containerRepository = containerRepository; | ||
this.containerIngredientRepository = containerIngredientRepository; | ||
} | ||
|
||
@Transactional | ||
public ContainerIngredientDtos getUserIngredients(Long userId) { | ||
List<Container> containerList = containerRepository.findAllByUserId(userId); | ||
List<ContainerIngredient> containerIngredientList = containerIngredientRepository.findByContainerIn(containerList); | ||
|
||
return ContainerIngredientDtos.of(containerIngredientList); | ||
} | ||
|
||
@Transactional | ||
public ContainerIngredientDtos getContainerIngredients(Long containerId) { | ||
List<ContainerIngredient> containerIngredientList = containerIngredientRepository.findAllByContainerId(containerId); | ||
|
||
return ContainerIngredientDtos.of(containerIngredientList); | ||
} | ||
|
||
@Transactional | ||
public ContainerIngredientDto getIngredientInfo(Long containerIngredientId) { | ||
ContainerIngredient containerIngredient = containerIngredientRepository.findById(containerIngredientId) | ||
.orElseThrow(() -> new NoSuchElementException("no ingredient in container")); | ||
return ContainerIngredientDto.of(containerIngredient); | ||
} | ||
|
||
public CategoryIngredientResponses getCategoryIngredientResponses(Long containerId) { | ||
List<ContainerIngredient> containerIngredients = containerIngredientRepository.findAllByContainerId(containerId); | ||
|
||
Map<String, List<ContainerIngredient>> kindIngredientsMap = containerIngredients.stream() | ||
.collect(Collectors.groupingBy(userHavingIngredient -> userHavingIngredient.getIngredient().getKind())); | ||
|
||
List<CategoryIngredientResponse> categoryIngredientResponseList = new ArrayList<>(); | ||
kindIngredientsMap.forEach((kind, userHavingIngredientsList) -> { | ||
List<IngredientDetailResponse> ingredientDetailResponseList = userHavingIngredientsList.stream() | ||
.map(IngredientDetailResponse::of) | ||
.collect(Collectors.toList()); | ||
|
||
IngredientDetailResponses ingredientDetailResponses = IngredientDetailResponses.of(ingredientDetailResponseList); | ||
|
||
categoryIngredientResponseList.add(CategoryIngredientResponse.of(kind, ingredientDetailResponses)); | ||
}); | ||
|
||
return CategoryIngredientResponses.of(categoryIngredientResponseList); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...src/main/java/com/sundaegukbap/banchango/ingredient/dto/event/IngredientChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sundaegukbap.banchango.ingredient.dto.event; | ||
|
||
public record IngredientChangedEvent( | ||
Long userId | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.