com.osomapps.pt.admin.user.AdminUserTypeService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 23
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findAll() 0 4 1
A AdminUserTypeService(InUserTypeRepository,DictionaryService) 0 4 1
A userTypeToDto(InUserType) 0 12 1
1
package com.osomapps.pt.admin.user;
2
3
import com.osomapps.pt.dictionary.DictionaryName;
4
import com.osomapps.pt.dictionary.DictionaryService;
5
import java.util.List;
6
import java.util.stream.Collectors;
7
import org.springframework.stereotype.Service;
8
9
@Service
10
class AdminUserTypeService {
11
12
    private final InUserTypeRepository inUserTypeRepository;
13
    private final DictionaryService dictionaryService;
14
15
    AdminUserTypeService(
16
            InUserTypeRepository inUserTypeRepository, DictionaryService dictionaryService) {
17
        this.inUserTypeRepository = inUserTypeRepository;
18
        this.dictionaryService = dictionaryService;
19
    }
20
21
    List<UserTypeResponseDTO> findAll() {
22
        return inUserTypeRepository.findAll().stream()
23
                .map(userType -> userTypeToDto(userType))
24
                .collect(Collectors.toList());
25
    }
26
27
    private UserTypeResponseDTO userTypeToDto(InUserType inUserType) {
28
        final String userTypeEnName =
29
                dictionaryService.getEnValue(
30
                        DictionaryName.user_type, inUserType.getD_user_type(), "");
31
        final String userTypeNoName =
32
                dictionaryService.getNoValue(
33
                        DictionaryName.user_type, inUserType.getD_user_type(), "");
34
        return UserTypeResponseDTO.builder()
35
                .id(inUserType.getId())
36
                .nameEn(userTypeEnName)
37
                .nameNo(userTypeNoName)
38
                .build();
39
    }
40
}
41