21
21
import java .util .Optional ;
22
22
import java .util .stream .Collectors ;
23
23
24
+ /**
25
+ * Service class for users managing.
26
+ */
24
27
@ Slf4j
25
28
@ Service
26
29
@ AllArgsConstructor
@@ -33,6 +36,12 @@ public class UserService {
33
36
@ Autowired
34
37
private PasswordEncoder passwordEncoder ;
35
38
39
+ /**
40
+ * Creating a new user from the received createDTO
41
+ *
42
+ * @param userCreateDto data for creation new user
43
+ * @return created user id
44
+ */
36
45
@ Transactional
37
46
@ Measurable
38
47
public Long create (UserCreateDto userCreateDto ) {
@@ -48,6 +57,12 @@ public Long create(UserCreateDto userCreateDto) {
48
57
return userFromBase .getUserId ();
49
58
}
50
59
60
+ /**
61
+ * Remove user from DB by user id
62
+ *
63
+ * @param id user id for removal
64
+ * @return true - deletion successful, false - user deletion failed
65
+ */
51
66
@ Transactional
52
67
@ Measurable
53
68
public boolean delete (Long id ) {
@@ -60,6 +75,12 @@ public boolean delete(Long id) {
60
75
return maybeUser .isPresent ();
61
76
}
62
77
78
+ /**
79
+ * Update existent user
80
+ *
81
+ * @param updateDto data for update
82
+ * @return true - update succeeded, false - update failed
83
+ */
63
84
@ Transactional
64
85
@ Measurable
65
86
public boolean update (UserUpdateDeleteDto updateDto ) {
@@ -81,18 +102,35 @@ public boolean update(UserUpdateDeleteDto updateDto) {
81
102
return maybeUser .isPresent ();
82
103
}
83
104
105
+ /**
106
+ * Find user by ID
107
+ *
108
+ * @param id user id for search
109
+ * @return optional found user DTO
110
+ */
84
111
@ Measurable
85
112
public Optional <UserReadDto > findById (Long id ) {
86
113
return userRepository .findById (id ).map (UserMapper .INSTANCE ::mapToUserReadDto );
87
114
}
88
115
116
+ /**
117
+ * Get all available user from DB
118
+ *
119
+ * @return users data collection
120
+ */
89
121
@ Measurable
90
122
public List <UserReadDto > findAll () {
91
123
return userRepository .findAll ().stream ()
92
124
.map (UserMapper .INSTANCE ::mapToUserReadDto )
93
125
.collect (Collectors .toList ());
94
126
}
95
127
128
+ /**
129
+ * Find user by login
130
+ *
131
+ * @param login login for search
132
+ * @return optional user found data
133
+ */
96
134
@ Measurable
97
135
public Optional <UserReadDto > findByLogin (String login ) {
98
136
return userRepository .findByLogin (login ).map (UserMapper .INSTANCE ::mapToUserReadDto );
0 commit comments