Skip to content

Commit

Permalink
♻️ Refactor/296 stream().map().peek()으로 로직 간소화
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanvp committed Feb 4, 2024
2 parents 84e078e + 5cb665a commit 8c8b8b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -747,21 +748,20 @@ public static TestRecipe toTestRecipe(RecipeRequestDto.CreateRecipeDto request,
}

public static List<TestRecipeCategoryMapping> toTestRecipeCategory(List<Long> categoryIds, TestRecipe recipe) {
return categoryIds.stream().parallel()
return categoryIds.stream()
.map(recipeCategoryId -> toTestRecipeCategoryMappingDto(recipeCategoryId, recipe))
.collect(Collectors.toList());
}

private static TestRecipeCategoryMapping toTestRecipeCategoryMappingDto(Long categoryId, TestRecipe recipe) {
log.info("categoryMappingDto Thread: " + categoryId);
return TestRecipeCategoryMapping.builder()
.category(staticRecipeService.getRecipeCategory(categoryId))
.recipe(recipe)
.build();
}

public static List<TestStep> toTestStep(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe, List<MultipartFile> stepImages) {
return request.getSteps().stream().parallel()
return request.getSteps().stream()
.map(step-> {
if (step.getDescription() == null)
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
Expand All @@ -775,7 +775,6 @@ public static List<TestStep> toTestStep(RecipeRequestDto.CreateRecipeDto request
}

private static TestStep toTestStepDto(RecipeRequestDto.StepDto step, TestRecipe recipe, List<MultipartFile> stepImages) throws IOException {
log.info("stepDto Thread: " + step.getStepNum()+"(stepNum)");

TestStep createdStep = TestStep.builder()
.stepNum(step.getStepNum())
Expand Down Expand Up @@ -804,13 +803,12 @@ private static TestStep toTestStepDto(RecipeRequestDto.StepDto step, TestRecipe
}

public static List<TestIngredient> toTestIngredient(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe) {
return request.getIngredients().stream().parallel()
return request.getIngredients().stream()
.map(ingredient -> toTestIngredientDto(ingredient, recipe))
.collect(Collectors.toList());
}

private static TestIngredient toTestIngredientDto(RecipeRequestDto.NewIngredientDto ingredient, TestRecipe recipe) {
log.info("ingredientDto Thread: " + ingredient.getIngredientName());

return TestIngredient.builder()
.name(ingredient.getIngredientName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import zipdabang.server.domain.inform.PushAlarm;
import zipdabang.server.domain.member.*;
import zipdabang.server.domain.recipe.*;
import zipdabang.server.domain.test.QTestRecipe;
import zipdabang.server.domain.test.TestRecipe;
import zipdabang.server.firebase.fcm.service.FirebaseService;
import zipdabang.server.repository.AlarmRepository.AlarmCategoryRepository;
Expand All @@ -45,6 +46,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

@Slf4j
Expand Down Expand Up @@ -905,6 +907,7 @@ public RecipeCategory getRecipeCategory(Long categoryId) {
@Override
@Transactional(readOnly = false)
public TestRecipe testCreate(RecipeRequestDto.CreateRecipeDto request, MultipartFile thumbnail, List<MultipartFile> stepImages) throws IOException {

TestRecipe buildRecipe = RecipeConverter.toTestRecipe(request, thumbnail);
TestRecipe recipe = testRecipeRepository.save(buildRecipe);

Expand Down

0 comments on commit 8c8b8b2

Please sign in to comment.