88import org .springframework .beans .factory .annotation .Autowired ;
99import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
1010import org .springframework .stereotype .Service ;
11+ import org .springframework .transaction .annotation .Transactional ;
1112
1213import com .pedro .sphynx .dtos .auth .UserDataComplete ;
1314import com .pedro .sphynx .dtos .auth .UserDataRegisterInput ;
@@ -44,6 +45,7 @@ public class UserService {
4445
4546 private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder (12 );
4647
48+ @ Transactional
4749 public UserDataComplete create (UserDataRegisterInput data , User loggedUser ) {
4850 if (userRepository .existsByUser (data .user ())) {
4951 throw new EntityExistsException ("User already exists" );
@@ -129,12 +131,14 @@ public UserDataComplete create(UserDataRegisterInput data, User loggedUser) {
129131 return new UserDataComplete (userCreated );
130132 }
131133
134+ @ Transactional
132135 public UserDataComplete getById (Long id ) {
133136 User userEntity = userRepository .findById (id )
134137 .orElseThrow (() -> new EntityExistsException ("User not found" ));
135138 return new UserDataComplete (userEntity );
136139 }
137140
141+ @ Transactional
138142 public List <UserDataComplete > getAll (User loggedUser ) {
139143 List <UserDataComplete > listUsers ;
140144
@@ -156,6 +160,7 @@ public List<UserDataComplete> getAll(User loggedUser) {
156160 return listUsers ;
157161 }
158162
163+ @ Transactional
159164 public void delete (Long id ) {
160165 if (!userRepository .existsById (id )) {
161166 throw new EntityExistsException ("User not found" );
@@ -164,6 +169,7 @@ public void delete(Long id) {
164169 userRepository .deleteById (id );
165170 }
166171
172+ @ Transactional
167173 public UserDataComplete update (UserDataRegisterInput data , Long id ){
168174 if (!userRepository .existsById (id )) {
169175 throw new EntityNotFoundException (messages .getString ("error.idDontExists" ));
0 commit comments