Line | |
---|
1 | package com.example.service.impl;
|
---|
2 |
|
---|
3 | import com.example.exceptions.NoSuchIDException;
|
---|
4 | import com.example.model.User;
|
---|
5 | import com.example.repository.UserRepository;
|
---|
6 | import com.example.service.UserService;
|
---|
7 | import org.springframework.stereotype.Service;
|
---|
8 |
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.Optional;
|
---|
11 |
|
---|
12 | @Service
|
---|
13 | public 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.