Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Server] fix : 배포후 발생한 문제들 해결(#50, #54) #56

Merged
merged 30 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7ed41c2
deploy : CD테스트
Due-IT Sep 22, 2024
ed22395
deploy : Dockerfile 추가
Due-IT Sep 22, 2024
e8ee86b
Update gradle.yml
Due-IT Sep 22, 2024
4e3c1e0
deploy : CD 테스트
Due-IT Sep 22, 2024
8b82157
Merge branch 'Server/CD' of https://github.com/Sundae-Gukbap/Banchang…
Due-IT Sep 22, 2024
9bdb56a
Update gradle.yml
Due-IT Sep 22, 2024
b505ddc
deploy : CD 테스트
Due-IT Sep 22, 2024
ca94b13
Update gradle.yml
Due-IT Sep 22, 2024
a87ba3a
deploy : CD 테스트
Due-IT Sep 22, 2024
8c3ae46
Update gradle.yml
Due-IT Sep 22, 2024
e272d86
deploy : CD 테스트
Due-IT Sep 22, 2024
d897b65
Update gradle.yml
Due-IT Sep 22, 2024
26829cd
deploy : CD 테스트
Due-IT Sep 22, 2024
16dd3c7
deploy : CD 테스트
Due-IT Sep 22, 2024
0677ac6
Update gradle.yml
Due-IT Sep 22, 2024
dabaca0
deploy : CD 테스트
Due-IT Sep 22, 2024
feef981
Merge branch 'Server/CD' of https://github.com/Sundae-Gukbap/Banchang…
Due-IT Sep 22, 2024
6552449
deploy : CD 테스트
Due-IT Sep 22, 2024
64665a3
Update gradle.yml
Due-IT Sep 22, 2024
103a947
deploy : CD 테스트
Due-IT Sep 22, 2024
957d3dc
Merge branch 'Server/CD' of https://github.com/Sundae-Gukbap/Banchang…
Due-IT Sep 22, 2024
b57141a
merge : pull origin develop
Due-IT Oct 2, 2024
86e54f1
Merge branch 'develop' of https://github.com/Sundae-Gukbap/Banchango-…
Due-IT Oct 2, 2024
bf04ae0
fix : recipeCategory db에 string 형태로 저장
Due-IT Oct 2, 2024
941beac
chore : DNS를 mvc cors도 허용해본다.
Due-IT Oct 2, 2024
15eb6c9
style : 라인 정리
Due-IT Oct 2, 2024
635800a
fix : 정렬후 저장하지 않고 바로 바로 저장한다.
Due-IT Oct 2, 2024
bfd7325
fix : 이 부분에서 정렬되는 건가?
Due-IT Oct 2, 2024
a0ce745
fix : transactional 추가
Due-IT Oct 2, 2024
c5ad95e
refact : 메서드 분할
Due-IT Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ public OpenAPI openAPI() {
.info(info)
.servers(List.of(server));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
Expand All @@ -34,28 +36,26 @@ public class RecipeService {
private final AiRecipeRecommendClient aiRecipeRecommendClient;

@EventListener
@Transactional
public void refreshRecommendedRecipes(IngredientChangedEvent event) {
refreshRecommendedRecipes(event.userId(), RecipeCategory.전체);
}

@Transactional
public void changeRecipeCategory(Long userId, RecipeCategory recipeCategory) {
refreshRecommendedRecipes(userId, recipeCategory);
}

@Transactional
public void refreshRecommendedRecipes(Long userId, RecipeCategory recipeCategory) {
List<Container> containers = containerRepository.findAllByUserId(userId);
List<ContainerIngredient> containerIngredients = containerIngredientRepository.findByContainerIn(containers);
List<Ingredient> ingredients = containerIngredients.stream()
.map(ContainerIngredient::getIngredient)
.collect(Collectors.toList());
List<Ingredient> ingredients = getIngredientsWithUser(userId);

recommendedRecipeRepository.deleteAllByUserId(userId);

User user = userRepository.findById(userId)
.orElseThrow(() -> new NoSuchElementException("no user"));
List<Long> recommendedRecipeIds = aiRecipeRecommendClient.getRecommendedRecipesFromAI(recipeCategory, ingredients);
List<Recipe> recipes = recipeRepository.findAllById(recommendedRecipeIds);
List<Recipe> recipes = recommendedRecipesFromAI(recipeCategory, ingredients);

List<UserRecommendedRecipe> recommendedRecipes = recipes.stream()
.map(recipe -> UserRecommendedRecipe.builder()
.user(user)
Expand All @@ -64,4 +64,24 @@ public void refreshRecommendedRecipes(Long userId, RecipeCategory recipeCategory
.collect(Collectors.toList());
recommendedRecipeRepository.saveAll(recommendedRecipes);
}

private List<Ingredient> getIngredientsWithUser(Long userId) {
List<Container> containers = containerRepository.findAllByUserId(userId);
List<ContainerIngredient> containerIngredients = containerIngredientRepository.findByContainerIn(containers);
List<Ingredient> ingredients = containerIngredients.stream()
.map(ContainerIngredient::getIngredient)
.collect(Collectors.toList());
return ingredients;
}

private List<Recipe> recommendedRecipesFromAI(RecipeCategory recipeCategory, List<Ingredient> ingredients) {
List<Long> recommendedRecipeIds = aiRecipeRecommendClient.getRecommendedRecipesFromAI(recipeCategory, ingredients);
List<Recipe> recipes = new ArrayList<>();
recommendedRecipeIds.forEach(recommendedRecipeId -> {
Optional<Recipe> recipe = recipeRepository.findById(recommendedRecipeId);

if (recipe.isPresent()) recipes.add(recipe.get());
});
return recipes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Recipe {
private RecipeDifficulty recipeDifficulty;
private String bySort;
private String byIngredient;
@Enumerated(EnumType.STRING)
private RecipeCategory recipeCategory;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ResponseEntity<RecommendedRecipeResponse> getRecipeDetail(@PathVariable("
@PostMapping("/{userId}")
@Operation(summary = "추천 레시피 카테고리 변경", description = "추천 레시피 카테고리를 변경하고 새로운 추천 레시피를 받아옵니다.")
public ResponseEntity<String> changeRecipeCategory(@PathVariable("userId") Long userId,
@RequestParam(defaultValue = "전체") RecipeCategory recipeCategory) {
@RequestParam(defaultValue = "전체") RecipeCategory recipeCategory) {
recipeService.changeRecipeCategory(userId, recipeCategory);
return new ResponseEntity<>("카테고리에 맞게 추천 레시피목록이 변경되었습니다.", HttpStatus.OK);
}
Expand Down
6 changes: 3 additions & 3 deletions Server/banchango/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
spring.application.name=banchango

spring.profiles.active=local
spring.profiles.active=prod

app.cors.allowedOrigins=http://34.222.135.30:8000,http://localhost:3000,http://localhost:8080
app.oauth2.authorizedRedirectUris=http://34.222.135.30:8000,http://localhost:3000/oauth2/redirect,myandroidapp://oauth2/redirect,myiosapp://oauth2/redirect
app.cors.allowedOrigins=https://backendu.com,http://34.222.135.30:8000,http://localhost:3000,http://localhost:8080
app.oauth2.authorizedRedirectUris=https://backendu.com,http://34.222.135.30:8000,http://localhost:3000/oauth2/redirect,myandroidapp://oauth2/redirect,myiosapp://oauth2/redirect

api.aiBaseUrl=http://34.222.135.30:8000