From d8023f2d6dbe3c48231bf600a34532e66f0660ce Mon Sep 17 00:00:00 2001 From: Lena Sotnik Date: Fri, 6 Oct 2023 03:08:12 -0700 Subject: [PATCH] Change of implementation of habitTranslationDtoOptional --- .../greencity/service/HabitServiceImpl.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/service/src/main/java/greencity/service/HabitServiceImpl.java b/service/src/main/java/greencity/service/HabitServiceImpl.java index 1288047b1f..65aa3925d7 100644 --- a/service/src/main/java/greencity/service/HabitServiceImpl.java +++ b/service/src/main/java/greencity/service/HabitServiceImpl.java @@ -434,15 +434,14 @@ private void updateExistingCustomShoppingListItems(CustomHabitDtoRequest habitDt private void updateHabitTranslationsForCustomHabit(CustomHabitDtoRequest habitDto, Habit habit) { Optional habitTranslationDtoOptional = habitDto.getHabitTranslations().stream() .findFirst(); - if (habitTranslationDtoOptional.isPresent()) { - HabitTranslationDto habitTranslationDto = habitTranslationDtoOptional.get(); - List habitTranslations = habitTranslationRepo.findAllByHabit(habit); - habitTranslations.forEach(habitTranslation -> { - habitTranslation.setName(habitTranslationDto.getName()); - habitTranslation.setDescription(habitTranslationDto.getDescription()); - habitTranslation.setHabitItem(habitTranslationDto.getHabitItem()); - }); - } + habitTranslationDtoOptional.ifPresent(habitTranslationDto -> { + habitTranslationRepo.findAllByHabit(habit) + .forEach(habitTranslation -> { + habitTranslation.setName(habitTranslationDto.getName()); + habitTranslation.setDescription(habitTranslationDto.getDescription()); + habitTranslation.setHabitItem(habitTranslationDto.getHabitItem()); + }); + }); } private void saveHabitTranslationListsToHabitTranslationRepo(CustomHabitDtoRequest habitDto, Habit habit) {