Browse Source

commit second

placidenduwayo 2 years ago
parent
commit
74d95d69d2

+ 5
- 5
project-microservice/src/main/java/fr/natan/microservices/projectmicroservice/model/entity/Project.java View File

@@ -3,7 +3,7 @@ package fr.natan.microservices.projectmicroservice.model.entity;
3 3
 import fr.natan.microservices.projectmicroservice.model.enumType.Priority;
4 4
 import fr.natan.microservices.projectmicroservice.model.enumType.ProjState;
5 5
 import fr.natan.microservices.projectmicroservice.t_openfeign.models.company.entity.Company;
6
-import fr.natan.microservices.projectmicroservice.t_openfeign.models.user.User;
6
+import fr.natan.microservices.projectmicroservice.t_openfeign.models.user.AppUser;
7 7
 
8 8
 import javax.persistence.*;
9 9
 
@@ -25,7 +25,7 @@ public class Project {
25 25
     private String description;
26 26
     private Long userID;
27 27
     @Transient
28
-    private User user;
28
+    private AppUser user;
29 29
 
30 30
     public Project() {
31 31
     }
@@ -34,7 +34,7 @@ public class Project {
34 34
             Long projectID, String projectName,
35 35
             Priority projectPriority, String createDate,
36 36
             Long companyID, Company company, String description,
37
-            Long userID, User user, ProjState projectProgress) {
37
+            Long userID, AppUser user, ProjState projectProgress) {
38 38
 
39 39
         this.projectID = projectID;
40 40
         this.projectName = projectName;
@@ -112,11 +112,11 @@ public class Project {
112 112
         this.userID = userID;
113 113
     }
114 114
 
115
-    public User getUser() {
115
+    public AppUser getUser() {
116 116
         return user;
117 117
     }
118 118
 
119
-    public void setUser(User user) {
119
+    public void setUser(AppUser user) {
120 120
         this.user = user;
121 121
     }
122 122
 

+ 2
- 2
project-microservice/src/main/java/fr/natan/microservices/projectmicroservice/service/services/ProjectServiceImplement.java View File

@@ -6,7 +6,7 @@ import fr.natan.microservices.projectmicroservice.repository.ProjectRepository;
6 6
 import fr.natan.microservices.projectmicroservice.service.utilities.ProjectValidator;
7 7
 import fr.natan.microservices.projectmicroservice.t_openfeign.models.address.Address;
8 8
 import fr.natan.microservices.projectmicroservice.t_openfeign.models.company.entity.Company;
9
-import fr.natan.microservices.projectmicroservice.t_openfeign.models.user.User;
9
+import fr.natan.microservices.projectmicroservice.t_openfeign.models.user.AppUser;
10 10
 import fr.natan.microservices.projectmicroservice.t_openfeign.services.AddressService;
11 11
 import fr.natan.microservices.projectmicroservice.t_openfeign.services.CompanyService;
12 12
 import fr.natan.microservices.projectmicroservice.t_openfeign.services.UserService;
@@ -64,7 +64,7 @@ public class ProjectServiceImplement implements ProjectService {
64 64
         }
65 65
 
66 66
         Project formattedProject = ProjectValidator.formatProject(project);
67
-        User user = userService.getUserByID(project.getUserID());
67
+        AppUser user = userService.getUserByID(project.getUserID());
68 68
         Address address = addressService.getAddressByID(user.getAddressID());
69 69
         user.setAddress(address);
70 70
 

project-microservice/src/main/java/fr/natan/microservices/projectmicroservice/t_openfeign/models/user/User.java → project-microservice/src/main/java/fr/natan/microservices/projectmicroservice/t_openfeign/models/user/AppUser.java View File

@@ -2,7 +2,7 @@ package fr.natan.microservices.projectmicroservice.t_openfeign.models.user;
2 2
 
3 3
 import fr.natan.microservices.projectmicroservice.t_openfeign.models.address.Address;
4 4
 
5
-public class User {
5
+public class AppUser {
6 6
     private Long userID;
7 7
     private String firstname;
8 8
     private String lastname;
@@ -12,11 +12,11 @@ public class User {
12 12
     private Long addressID;
13 13
     private Address address;
14 14
 
15
-    public User() {
15
+    public AppUser() {
16 16
     }
17 17
 
18
-    public User(Long userID, String firstname, String lastname, String email,
19
-                String createdDate, Long addressID, Address address) {
18
+    public AppUser(Long userID, String firstname, String lastname, String email,
19
+                   String createdDate, Long addressID, Address address) {
20 20
         this.userID = userID;
21 21
         this.firstname = firstname;
22 22
         this.lastname = lastname;

+ 2
- 2
project-microservice/src/main/java/fr/natan/microservices/projectmicroservice/t_openfeign/services/UserService.java View File

@@ -2,7 +2,7 @@ package fr.natan.microservices.projectmicroservice.t_openfeign.services;
2 2
 
3 3
 
4 4
 import fr.natan.microservices.projectmicroservice.module_exception.exceptions.UserNotFoundException;
5
-import fr.natan.microservices.projectmicroservice.t_openfeign.models.user.User;
5
+import fr.natan.microservices.projectmicroservice.t_openfeign.models.user.AppUser;
6 6
 import org.springframework.cloud.openfeign.FeignClient;
7 7
 import org.springframework.web.bind.annotation.PathVariable;
8 8
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,5 +12,5 @@ import org.springframework.web.bind.annotation.RequestMethod;
12 12
 public interface UserService {
13 13
 
14 14
     @RequestMapping(value = "/users/{userID}", method = RequestMethod.GET)
15
-    User getUserByID(@PathVariable(name = "userID") Long userID) throws UserNotFoundException;
15
+    AppUser getUserByID(@PathVariable(name = "userID") Long userID) throws UserNotFoundException;
16 16
 }

user-microservice/src/main/java/fr/natan/microservices/usermicroservice/model/User.java → user-microservice/src/main/java/fr/natan/microservices/usermicroservice/model/AppUser.java View File

@@ -7,7 +7,7 @@ import javax.persistence.*;
7 7
 
8 8
 @Entity
9 9
 @Table(name = "users")
10
-public class User {
10
+public class AppUser {
11 11
     @Id
12 12
     @GeneratedValue(strategy = GenerationType.IDENTITY)
13 13
     private Long userID;
@@ -21,12 +21,12 @@ public class User {
21 21
     @Transient
22 22
     private Address address;
23 23
 
24
-    public User() {
24
+    public AppUser() {
25 25
     }
26 26
 
27
-    public User(Long userID, String firstname, String lastname,
28
-                String email, String createdDate, UserType userType,
29
-                Long addressID, Address address) {
27
+    public AppUser(Long userID, String firstname, String lastname,
28
+                   String email, String createdDate, UserType userType,
29
+                   Long addressID, Address address) {
30 30
         this.userID = userID;
31 31
         this.firstname = firstname;
32 32
         this.lastname = lastname;

+ 4
- 4
user-microservice/src/main/java/fr/natan/microservices/usermicroservice/repository/UserRepository.java View File

@@ -1,13 +1,13 @@
1 1
 package fr.natan.microservices.usermicroservice.repository;
2 2
 
3
-import fr.natan.microservices.usermicroservice.model.User;
3
+import fr.natan.microservices.usermicroservice.model.AppUser;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7 7
 import java.util.Collection;
8 8
 
9 9
 @Repository
10
-public interface UserRepository extends JpaRepository<User, Long> {
11
-    Collection<User> findByFirstnameAndLastname(String firstname, String lastname);
12
-    Collection<User> findByAddressID(Long addressID);
10
+public interface UserRepository extends JpaRepository<AppUser, Long> {
11
+    Collection<AppUser> findByFirstnameAndLastname(String firstname, String lastname);
12
+    Collection<AppUser> findByAddressID(Long addressID);
13 13
 }

+ 7
- 7
user-microservice/src/main/java/fr/natan/microservices/usermicroservice/service/services/UserService.java View File

@@ -4,17 +4,17 @@ 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
 
9 9
 import java.util.Collection;
10 10
 
11 11
 public interface UserService {
12
-    User createUser(User user) throws UserAlreadyExistsException, UserFieldsEmptyException, AddressNotFoundException;
13
-    Collection<User> getUsers();
14
-    Collection<User> getUsers(String firstname, String lastname);
15
-    User getUser(Long userID) throws UserNotFoundException, AddressNotFoundException;
16
-    User updateUser(Long userID, User user) throws UserNotFoundException, UserFieldsEmptyException, AddressNotFoundException;
12
+    AppUser createUser(AppUser user) throws UserAlreadyExistsException, UserFieldsEmptyException, AddressNotFoundException;
13
+    Collection<AppUser> getUsers();
14
+    Collection<AppUser> getUsers(String firstname, String lastname);
15
+    AppUser getUser(Long userID) throws UserNotFoundException, AddressNotFoundException;
16
+    AppUser updateUser(Long userID, AppUser user) throws UserNotFoundException, UserFieldsEmptyException, AddressNotFoundException;
17 17
     void deleteUser(Long userID) throws UserNotFoundException, AddressNotFoundException;
18 18
     void deleteAllUsers();
19
-    Collection<User> getUsersLivingAtAddress(Long addressID) throws AddressNotFoundException;
19
+    Collection<AppUser> getUsersLivingAtAddress(Long addressID) throws AddressNotFoundException;
20 20
 }

+ 12
- 12
user-microservice/src/main/java/fr/natan/microservices/usermicroservice/service/services/UserServiceImplement.java View File

@@ -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()));

+ 3
- 3
user-microservice/src/main/java/fr/natan/microservices/usermicroservice/service/utilities/UserValidator.java View File

@@ -1,10 +1,10 @@
1 1
 package fr.natan.microservices.usermicroservice.service.utilities;
2 2
 
3
-import fr.natan.microservices.usermicroservice.model.User;
3
+import fr.natan.microservices.usermicroservice.model.AppUser;
4 4
 
5 5
 public class UserValidator {
6 6
 
7
-    public static boolean isValidUser(User user) {
7
+    public static boolean isValidUser(AppUser user) {
8 8
         if (
9 9
                 user.getFirstname().isEmpty()
10 10
                         || user.getLastname().isEmpty()
@@ -16,7 +16,7 @@ public class UserValidator {
16 16
             return true;
17 17
     }
18 18
 
19
-    public static User formatUser(User user) {
19
+    public static AppUser formatUser(AppUser user) {
20 20
         user.setLastname(user.getLastname().strip().toUpperCase());
21 21
         user.setFirstname(user.getFirstname().strip());
22 22
         user.setUserType(user.getUserType());

+ 6
- 6
user-microservice/src/main/java/fr/natan/microservices/usermicroservice/tt_controller/UserController.java View File

@@ -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.service.services.UserService;
9 9
 import fr.natan.microservices.usermicroservice.t_openfeign.service.AddressService;
10 10
 import org.springframework.web.bind.annotation.*;
@@ -22,18 +22,18 @@ public class UserController {
22 22
     }
23 23
 
24 24
     @RequestMapping(value = "/users", method = RequestMethod.POST)
25
-    private User createUser(@RequestBody User user)
25
+    private AppUser createUser(@RequestBody AppUser user)
26 26
             throws UserFieldsEmptyException, AddressNotFoundException, UserAlreadyExistsException {
27 27
         return userContract.createUser(user);
28 28
     }
29 29
 
30 30
     @RequestMapping(value = "/users", method = RequestMethod.GET)
31
-    private Collection<User> getAllUsers() {
31
+    private Collection<AppUser> getAllUsers() {
32 32
         return userContract.getUsers();
33 33
     }
34 34
 
35 35
     @RequestMapping(value = "/users/{userID}", method = RequestMethod.GET)
36
-    private User getUser(@PathVariable(name = "userID") Long userID) throws UserNotFoundException, AddressNotFoundException {
36
+    private AppUser getUser(@PathVariable(name = "userID") Long userID) throws UserNotFoundException, AddressNotFoundException {
37 37
         return userContract.getUser(userID);
38 38
     }
39 39
 
@@ -48,13 +48,13 @@ public class UserController {
48 48
     }
49 49
 
50 50
     @RequestMapping(value = "/users/{userID}", method = RequestMethod.PUT)
51
-    private User updateUser(@PathVariable(name = "userID") Long userID, @RequestBody User user)
51
+    private AppUser updateUser(@PathVariable(name = "userID") Long userID, @RequestBody AppUser user)
52 52
             throws UserNotFoundException, UserFieldsEmptyException, AddressNotFoundException {
53 53
         return userContract.updateUser(userID, user);
54 54
     }
55 55
 
56 56
     @RequestMapping(value = "/users/addresses/{addressID}", method = RequestMethod.GET)
57
-    private Collection<User> geUsersLivingAtAddress(@PathVariable (name = "addressID") Long addressID) throws AddressNotFoundException {
57
+    private Collection<AppUser> geUsersLivingAtAddress(@PathVariable (name = "addressID") Long addressID) throws AddressNotFoundException {
58 58
         return userContract.getUsersLivingAtAddress(addressID);
59 59
     }
60 60
 }

Powered by TurnKey Linux.