exerciseBodypartToDto(ExerciseBodypart)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 16
rs 9.6
c 0
b 0
f 0
cc 1
1
package com.osomapps.pt.admin.exercise;
2
3
import com.osomapps.pt.dictionary.DictionaryName;
4
import com.osomapps.pt.dictionary.DictionaryService;
5
import com.osomapps.pt.exercises.ExerciseBodypart;
6
import java.util.List;
7
import java.util.stream.Collectors;
8
import org.springframework.stereotype.Service;
9
10
@Service
11
class AdminExerciseBodypartService {
12
13
    private final ExerciseBodypartRepository exerciseBodypartRepository;
14
    private final DictionaryService dictionaryService;
15
16
    AdminExerciseBodypartService(
17
            ExerciseBodypartRepository exerciseBodypartRepository,
18
            DictionaryService dictionaryService) {
19
        this.exerciseBodypartRepository = exerciseBodypartRepository;
20
        this.dictionaryService = dictionaryService;
21
    }
22
23
    List<ExerciseBodypartResponseDTO> findAll() {
24
        return exerciseBodypartRepository.findAll().stream()
25
                .map(bodypart -> exerciseBodypartToDto(bodypart))
26
                .collect(Collectors.toList());
27
    }
28
29
    private ExerciseBodypartResponseDTO exerciseBodypartToDto(ExerciseBodypart bodypart) {
30
        final String exerciseBodypartEnName =
31
                dictionaryService.getEnValue(
32
                        DictionaryName.exercise_bodypart_name,
33
                        bodypart.getDExerciseBodypartName(),
34
                        "");
35
        final String exerciseBodypartNoName =
36
                dictionaryService.getNoValue(
37
                        DictionaryName.exercise_bodypart_name,
38
                        bodypart.getDExerciseBodypartName(),
39
                        exerciseBodypartEnName);
40
        return ExerciseBodypartResponseDTO.builder()
41
                .id(bodypart.getId())
42
                .nameEn(exerciseBodypartEnName)
43
                .nameNo(exerciseBodypartNoName)
44
                .build();
45
    }
46
}
47