Blame view

src/main/java/fr/plil/sio/persistence/jdbc/UserServiceJdbc.java 1.58 KB
a800fde0   jcartign   First version, in...
1
2
3
4
5
6
7
8
9
10
11
12
  package fr.plil.sio.persistence.jdbc;
  
  import fr.plil.sio.persistence.api.Right;
  import fr.plil.sio.persistence.api.User;
  import fr.plil.sio.persistence.api.UserService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  @Service
  public class UserServiceJdbc implements UserService {
  
      @Autowired
31bdbe1b   msahmane   Version où les te...
13
      private UserRepository userRepository;
a800fde0   jcartign   First version, in...
14
15
  
      @Override
31bdbe1b   msahmane   Version où les te...
16
17
18
19
20
21
22
23
24
      public User create(String name, String userName) {
          if (name == null) {
              throw new IllegalArgumentException("name cannot be null");
          }
          User user = userRepository.findByName(name);
          if (user != null) {
              throw new IllegalStateException("a group with the same name already exists");
          }
          user = new User();
3de62e47   msahmane   Amélioration des ...
25
          user.setName(name);       
31bdbe1b   msahmane   Version où les te...
26
27
          userRepository.save(user);
          return user;
a800fde0   jcartign   First version, in...
28
29
30
      }
  
      @Override
5418cb05   jcartign   Javadoc of API is...
31
      public boolean delete(String name) {
31bdbe1b   msahmane   Version où les te...
32
33
34
35
36
37
38
39
40
41
          if (name == null) {
              throw new IllegalArgumentException("name cannot be null");
          }
          
          User user = userRepository.findByName(name); 
          if(user!=null){
              userRepository.delete(user.getId());
              return true;
          }
          return false;
a800fde0   jcartign   First version, in...
42
43
44
45
      }
  
      @Override
      public User findByName(String name) {
31bdbe1b   msahmane   Version où les te...
46
47
48
49
          if (name == null) {
              throw new IllegalArgumentException("name cannot be null");
          }
          return userRepository.findByName(name);
a800fde0   jcartign   First version, in...
50
51
      }
  
5418cb05   jcartign   Javadoc of API is...
52
53
      @Override
      public boolean isUserHasRight(String userName, Right right) {
292aec6f   jcartign   First version bef...
54
          throw new IllegalStateException("not implemented !");
a800fde0   jcartign   First version, in...
55
56
      }
  }