source: src/main/java/tech/techharbor/Service/Impl/UserServiceImpl.java

main
Last change on this file was f4b4afa, checked in by Nikola Todoroski <nikola.todoroski@…>, 6 months ago

Pushed whole project, original project location on github:https://github.com/hehxd/Tech-Harbor

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package tech.techharbor.Service.Impl;
2
3import org.springframework.stereotype.Service;
4import tech.techharbor.Model.Exceptions.UserNotFoundException;
5import tech.techharbor.Model.UserTableModel;
6import tech.techharbor.Repository.UserTableRepository;
7import tech.techharbor.Service.UserService;
8
9@Service
10public class UserServiceImpl implements UserService {
11
12 private final UserTableRepository userTableRepository;
13
14 public UserServiceImpl(UserTableRepository userTableRepository) {
15 this.userTableRepository = userTableRepository;
16 }
17
18 @Override
19 public UserTableModel findById(Integer id) {
20 return this.userTableRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user ID: " + id));
21 }
22
23 @Override
24 public UserTableModel create(String name, String username, String email, String password, String phoneNumber) {
25 UserTableModel user = new UserTableModel(username, name, email, password, phoneNumber);
26 return this.userTableRepository.save(user);
27 }
28
29 @Override
30 public UserTableModel update(Integer id, String name, String username, String email, String password, String phoneNumber) {
31 UserTableModel user = this.userTableRepository.findById(id).orElseThrow(() -> new UserNotFoundException(id));
32 user.setNameUser(name);
33 user.setUsername(username);
34 user.setEmail(email);
35 user.setPassword(password);
36 user.setPhoneNumber(phoneNumber);
37 return this.userTableRepository.save(user);
38 }
39
40 @Override
41 public UserTableModel findByUsername(String username) {
42 return this.userTableRepository.findByUsername(username);
43 }
44
45 @Override
46 public void delete(Integer id) {
47 this.userTableRepository.deleteById(id);
48 }
49}
Note: See TracBrowser for help on using the repository browser.