source: src/main/java/com/example/service/impl/UserServiceImpl.java

Last change on this file was a51a591, checked in by colovik <j.colovik@…>, 14 months ago

final

  • Property mode set to 100644
File size: 954 bytes
Line 
1package com.example.service.impl;
2
3import com.example.exceptions.NoSuchIDException;
4import com.example.model.User;
5import com.example.repository.UserRepository;
6import com.example.service.UserService;
7import org.springframework.stereotype.Service;
8
9import java.util.List;
10import java.util.Optional;
11
12@Service
13public class UserServiceImpl implements UserService {
14
15 private final UserRepository userRepository;
16
17 public UserServiceImpl(UserRepository userRepository) {
18 this.userRepository = userRepository;
19 }
20
21 @Override
22 public List<User> findAllUsers() {
23 return userRepository.findAll();
24 }
25
26 @Override
27 public Optional<User> findByUsername(String username) {
28
29 return userRepository.findByUsername(username);
30 }
31
32 @Override
33 public User findById(Integer id) {
34 return userRepository.findById(id).stream().findFirst()
35 .orElseThrow(() -> new NoSuchIDException(id));
36 }
37}
Note: See TracBrowser for help on using the repository browser.