source: src/main/java/mk/ukim/finki/eglas/services/Impl/UserProfileServiceImpl.java

main
Last change on this file was ac151d1, checked in by David <darsov2@…>, 4 months ago

initial

  • Property mode set to 100644
File size: 1.9 KB
Line 
1package mk.ukim.finki.eglas.services.Impl;
2
3import mk.ukim.finki.eglas.model.Citizen;
4import mk.ukim.finki.eglas.model.UserProfile;
5import mk.ukim.finki.eglas.repository.UserProfileRepository;
6import mk.ukim.finki.eglas.services.CitizenService;
7import mk.ukim.finki.eglas.services.UserProfileService;
8import org.springframework.stereotype.Service;
9
10import java.util.List;
11
12// Jovan
13@Service
14public class UserProfileServiceImpl implements UserProfileService {
15 private final UserProfileRepository userProfileRepository;
16 private final CitizenService citizenService;
17
18 UserProfileServiceImpl(UserProfileRepository userProfileRepository, CitizenService citizenService){
19 this.userProfileRepository = userProfileRepository;
20 this.citizenService = citizenService;
21 }
22
23 @Override
24 public List<UserProfile> findAll() {
25 return userProfileRepository.findAll();
26 }
27
28 @Override
29 public UserProfile findById(Long id) {
30 return userProfileRepository.findById(id).orElseThrow(() -> new RuntimeException("UserProfile not found"));
31 }
32
33 @Override
34 public UserProfile update(Long id, String userName, String password, String role, Long citizenId) {
35 Citizen citizen = citizenService.findById(citizenId);
36 UserProfile userProfile = new UserProfile();
37 if(id != null)
38 {
39 userProfile = findById(id);
40 }
41 userProfile.setUserName(userName);
42 userProfile.setPassword(password);
43 userProfile.setRole(role);
44 userProfile.setCitizen(citizen);
45 return userProfileRepository.save(userProfile);
46 }
47
48 @Override
49 public UserProfile delete(Long id) {
50 UserProfile userProfile = findById(id);
51 userProfileRepository.delete(userProfile);
52 return userProfile;
53 }
54
55 @Override
56 public UserProfile loadUserByUsername(String username) {
57 return userProfileRepository.findByUserName(username);
58 }
59}
Note: See TracBrowser for help on using the repository browser.