Update code localization HabitDictionary and Habit table.
@@ -235,14 +235,9 @@ public class HabitStatisticServiceImpl implements HabitStatisticService {
}
zonedDateTime = zonedDateTime.plusDays(1);
}
- HabitDictionaryTranslation habitDictionaryTranslation = habit.getHabitDictionary()
- .getHabitDictionaryTranslations().stream()
- .filter(t -> t.getLanguage().getCode().equals(language))
- .findFirst().orElseThrow(() -> new NotFoundException("This habit don`t exist for thi language"));
HabitDictionaryDto habitDictionaryDto = modelMapper.map(habit.getHabitDictionary(), HabitDictionaryDto.class);
- habitDictionaryDto.setDescription(habitDictionaryTranslation.getDescription());
- habitDictionaryDto.setHabitItem(habitDictionaryTranslation.getHabitItem());
- habitDictionaryDto.setName(habitDictionaryTranslation.getName());
+ HabitDictionaryTranslation habitDictionaryTranslation = createHabitDictionaryTranslation(habit,
+ habitDictionaryDto, language);
return new HabitDto(habit.getId(),
habitDictionaryTranslation.getName(),
@@ -255,4 +250,23 @@ public class HabitStatisticServiceImpl implements HabitStatisticService {
habitDictionaryDto
);
}
+
+ /**
+ * Create HabitDictionaryTranslation.
+ * @param habit {@link Habit}.
+ * @param habitDictionaryDto {@link HabitDictionaryDto}.
+ * @param language language code.
+ * @return {@link HabitDictionaryTranslation}.
+ */
+ private HabitDictionaryTranslation createHabitDictionaryTranslation(
+ Habit habit, HabitDictionaryDto habitDictionaryDto, String language) {
+ HabitDictionaryTranslation habitDictionaryTranslation = habit.getHabitDictionary()
+ .getHabitDictionaryTranslations().stream()
+ .filter(t -> t.getLanguage().getCode().equals(language))
+ .findFirst().orElseThrow(() -> new NotFoundException("This habit don`t exist for thi language"));
+ habitDictionaryDto.setDescription(habitDictionaryTranslation.getDescription());
+ habitDictionaryDto.setHabitItem(habitDictionaryTranslation.getHabitItem());
+ habitDictionaryDto.setName(habitDictionaryTranslation.getName());
+ return habitDictionaryTranslation;
+ }
}
