1
|
package cz.zcu.kiv.backendapi.type;
|
2
|
|
3
|
import lombok.RequiredArgsConstructor;
|
4
|
import org.springframework.stereotype.Service;
|
5
|
import org.springframework.transaction.annotation.Transactional;
|
6
|
|
7
|
import java.util.Optional;
|
8
|
import java.util.Set;
|
9
|
import java.util.stream.Collectors;
|
10
|
|
11
|
/**
|
12
|
* Type service implementation
|
13
|
*/
|
14
|
@Service
|
15
|
@Transactional
|
16
|
@RequiredArgsConstructor
|
17
|
public class TypeServiceImpl implements ITypeService {
|
18
|
/**
|
19
|
* Type repository
|
20
|
*/
|
21
|
private final TypeRepository typeRepository;
|
22
|
|
23
|
@Override
|
24
|
public void saveType(Type type) {
|
25
|
typeRepository.save(type);
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public Optional<Type> getTypeByName(String type) {
|
30
|
return typeRepository.findById(type);
|
31
|
}
|
32
|
|
33
|
@Override
|
34
|
public Set<String> getAllTypesAsString() {
|
35
|
return typeRepository.findAll().stream().map(Type::getType).collect(Collectors.toSet());
|
36
|
}
|
37
|
|
38
|
|
39
|
}
|