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 private UserRepository userRepository; @Override 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(); user.setName(name); userRepository.save(user); return user; } @Override public boolean delete(String name) { 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; } @Override public User findByName(String name) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } return userRepository.findByName(name); } @Override public boolean isUserHasRight(String userName, Right right) { throw new IllegalStateException("not implemented !"); } }