Skip to content

Commit

Permalink
Change of implementation of habitTranslationDtoOptional
Browse files Browse the repository at this point in the history
  • Loading branch information
Lena Sotnik authored and Lena Sotnik committed Oct 6, 2023
1 parent 9c629de commit d8023f2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions service/src/main/java/greencity/service/HabitServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,14 @@ private void updateExistingCustomShoppingListItems(CustomHabitDtoRequest habitDt
private void updateHabitTranslationsForCustomHabit(CustomHabitDtoRequest habitDto, Habit habit) {
Optional<HabitTranslationDto> habitTranslationDtoOptional = habitDto.getHabitTranslations().stream()
.findFirst();
if (habitTranslationDtoOptional.isPresent()) {
HabitTranslationDto habitTranslationDto = habitTranslationDtoOptional.get();
List<HabitTranslation> 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) {
Expand Down

0 comments on commit d8023f2

Please sign in to comment.