|
@@ -4,7 +4,7 @@ import fr.natan.microservices.usermicroservice.exceptions.AddressNotFoundExcepti
|
4
|
4
|
import fr.natan.microservices.usermicroservice.exceptions.UserAlreadyExistsException;
|
5
|
5
|
import fr.natan.microservices.usermicroservice.exceptions.UserFieldsEmptyException;
|
6
|
6
|
import fr.natan.microservices.usermicroservice.exceptions.UserNotFoundException;
|
7
|
|
-import fr.natan.microservices.usermicroservice.model.User;
|
|
7
|
+import fr.natan.microservices.usermicroservice.model.AppUser;
|
8
|
8
|
import fr.natan.microservices.usermicroservice.repository.UserRepository;
|
9
|
9
|
import fr.natan.microservices.usermicroservice.service.utilities.UserValidator;
|
10
|
10
|
import fr.natan.microservices.usermicroservice.t_openfeign.model.Address;
|
|
@@ -28,16 +28,16 @@ public class UserServiceImplement implements UserService {
|
28
|
28
|
}
|
29
|
29
|
|
30
|
30
|
@Override
|
31
|
|
- public Collection<User> getUsers(String firstname, String lastname) {
|
|
31
|
+ public Collection<AppUser> getUsers(String firstname, String lastname) {
|
32
|
32
|
return userRepository.findByFirstnameAndLastname(firstname, lastname);
|
33
|
33
|
}
|
34
|
34
|
|
35
|
35
|
@Override
|
36
|
|
- public User createUser(User user) throws UserAlreadyExistsException, UserFieldsEmptyException, AddressNotFoundException {
|
|
36
|
+ public AppUser createUser(AppUser user) throws UserAlreadyExistsException, UserFieldsEmptyException, AddressNotFoundException {
|
37
|
37
|
if(!UserValidator.isValidUser(user)){
|
38
|
38
|
throw new UserFieldsEmptyException();
|
39
|
39
|
}
|
40
|
|
- User formattedUser = UserValidator.formatUser(user);
|
|
40
|
+ AppUser formattedUser = UserValidator.formatUser(user);
|
41
|
41
|
if(getUsers(formattedUser.getFirstname(), formattedUser.getLastname()).size()>0){
|
42
|
42
|
throw new UserAlreadyExistsException();
|
43
|
43
|
}
|
|
@@ -55,8 +55,8 @@ public class UserServiceImplement implements UserService {
|
55
|
55
|
}
|
56
|
56
|
|
57
|
57
|
@Override
|
58
|
|
- public Collection<User> getUsers() {
|
59
|
|
- Collection<User> users = userRepository.findAll();
|
|
58
|
+ public Collection<AppUser> getUsers() {
|
|
59
|
+ Collection<AppUser> users = userRepository.findAll();
|
60
|
60
|
users.forEach(user -> {
|
61
|
61
|
try {
|
62
|
62
|
user.setAddress(addressService.getAddress(user.getAddressID()));
|
|
@@ -68,8 +68,8 @@ public class UserServiceImplement implements UserService {
|
68
|
68
|
}
|
69
|
69
|
|
70
|
70
|
@Override
|
71
|
|
- public User getUser(Long userID) throws UserNotFoundException, AddressNotFoundException {
|
72
|
|
- User user = userRepository.findById(userID).orElseThrow(
|
|
71
|
+ public AppUser getUser(Long userID) throws UserNotFoundException, AddressNotFoundException {
|
|
72
|
+ AppUser user = userRepository.findById(userID).orElseThrow(
|
73
|
73
|
()-> new UserNotFoundException()
|
74
|
74
|
);
|
75
|
75
|
Address address = addressService.getAddress(user.getAddressID());
|
|
@@ -80,7 +80,7 @@ public class UserServiceImplement implements UserService {
|
80
|
80
|
|
81
|
81
|
@Override
|
82
|
82
|
@Transactional
|
83
|
|
- public User updateUser(Long userID, User user) throws UserNotFoundException, UserFieldsEmptyException,
|
|
83
|
+ public AppUser updateUser(Long userID, AppUser user) throws UserNotFoundException, UserFieldsEmptyException,
|
84
|
84
|
AddressNotFoundException {
|
85
|
85
|
if (!UserValidator.isValidUser(user)){
|
86
|
86
|
throw new UserFieldsEmptyException();
|
|
@@ -92,7 +92,7 @@ public class UserServiceImplement implements UserService {
|
92
|
92
|
|
93
|
93
|
user = UserValidator.formatUser(user);
|
94
|
94
|
|
95
|
|
- User savedUser = getUser(userID);
|
|
95
|
+ AppUser savedUser = getUser(userID);
|
96
|
96
|
savedUser.setLastname(user.getLastname());
|
97
|
97
|
savedUser.setFirstname(user.getFirstname());
|
98
|
98
|
savedUser.setEmail(user.getEmail());
|
|
@@ -114,13 +114,13 @@ public class UserServiceImplement implements UserService {
|
114
|
114
|
}
|
115
|
115
|
|
116
|
116
|
@Override
|
117
|
|
- public Collection<User> getUsersLivingAtAddress(Long addressID) throws AddressNotFoundException {
|
|
117
|
+ public Collection<AppUser> getUsersLivingAtAddress(Long addressID) throws AddressNotFoundException {
|
118
|
118
|
Address address = addressService.getAddress(addressID);
|
119
|
119
|
if(address==null){
|
120
|
120
|
throw new AddressNotFoundException();
|
121
|
121
|
}
|
122
|
122
|
|
123
|
|
- Collection<User> users = userRepository.findByAddressID(addressID);
|
|
123
|
+ Collection<AppUser> users = userRepository.findByAddressID(addressID);
|
124
|
124
|
users.forEach(user -> {
|
125
|
125
|
try {
|
126
|
126
|
user.setAddress(addressService.getAddress(user.getAddressID()));
|