Delete Taskgroups when deleting corresponding user
This commit is contained in:
parent
e1b44cb92c
commit
9a67dfb875
@ -2,10 +2,12 @@ package core.repositories.timemanager;
|
|||||||
|
|
||||||
import core.entities.User;
|
import core.entities.User;
|
||||||
import core.entities.timemanager.Taskgroup;
|
import core.entities.timemanager.Taskgroup;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@ -15,4 +17,8 @@ public interface TaskgroupRepository extends CrudRepository<Taskgroup, Long> {
|
|||||||
|
|
||||||
@Query("SELECT tg FROM Taskgroup tg WHERE tg.user.username = ?1")
|
@Query("SELECT tg FROM Taskgroup tg WHERE tg.user.username = ?1")
|
||||||
List<Taskgroup> findAllByUser(String username);
|
List<Taskgroup> findAllByUser(String username);
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Transactional
|
||||||
|
void deleteAllByUser(User user);
|
||||||
}
|
}
|
||||||
|
@ -71,4 +71,8 @@ public class TaskgroupService {
|
|||||||
public List<Taskgroup> getTaskgroupsByUser(String username) {
|
public List<Taskgroup> getTaskgroupsByUser(String username) {
|
||||||
return taskgroupRepository.findAllByUser(username);
|
return taskgroupRepository.findAllByUser(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteTaskgroupByUser(User user) {
|
||||||
|
taskgroupRepository.deleteAllByUser(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import core.api.models.users.UserUpdateInfo;
|
|||||||
import core.entities.RoleEntity;
|
import core.entities.RoleEntity;
|
||||||
import core.entities.User;
|
import core.entities.User;
|
||||||
import core.entities.UserRole;
|
import core.entities.UserRole;
|
||||||
|
import core.entities.timemanager.Taskgroup;
|
||||||
import core.repositories.RoleRepository;
|
import core.repositories.RoleRepository;
|
||||||
import core.repositories.UserRepository;
|
import core.repositories.UserRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -29,6 +30,7 @@ public class UserService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RoleRepository roleRepository;
|
private RoleRepository roleRepository;
|
||||||
|
@Autowired private TaskgroupService taskgroupService;
|
||||||
|
|
||||||
public List<UserInfo> getAllUserInfos() {
|
public List<UserInfo> getAllUserInfos() {
|
||||||
Iterable<User> users = userRepository.findAll();
|
Iterable<User> users = userRepository.findAll();
|
||||||
@ -146,6 +148,7 @@ public class UserService {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taskgroupService.deleteTaskgroupByUser(requestedUser.get());
|
||||||
userRepository.deleteByUsername(username);
|
userRepository.deleteByUsername(username);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user