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