issue-6 #8
@ -14,6 +14,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin(origins = "*", maxAge = 3600)
|
||||
@RestController
|
||||
@ -70,4 +71,11 @@ public class TaskgroupController {
|
||||
taskgroupService.deleteTaskgroup(taskgroupPermissionResult.getResult());
|
||||
return ResponseEntity.ok(new SimpleStatusResponse("success"));
|
||||
}
|
||||
|
||||
@GetMapping("/taskgroups")
|
||||
public ResponseEntity<List<TaskgroupEntityInfo>> listTaskgroupsOfUser() {
|
||||
List<Taskgroup> taskgroups = taskgroupService.getTaskgroupsByUser(SecurityContextHolder.getContext().getAuthentication().getName());
|
||||
List<TaskgroupEntityInfo> taskgroupEntityInfos = taskgroups.stream().map(TaskgroupEntityInfo::new).toList();
|
||||
return ResponseEntity.ok(taskgroupEntityInfos);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,17 @@ package core.repositories.timemanager;
|
||||
|
||||
import core.entities.User;
|
||||
import core.entities.timemanager.Taskgroup;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface TaskgroupRepository extends CrudRepository<Taskgroup, Long> {
|
||||
|
||||
boolean existsByTaskgroupNameAndUser(String name, User user);
|
||||
|
||||
@Query("SELECT tg FROM Taskgroup tg WHERE tg.user.username = ?1")
|
||||
List<Taskgroup> findAllByUser(String username);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.springframework.scheduling.config.Task;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -66,4 +67,8 @@ public class TaskgroupService {
|
||||
public void deleteTaskgroup(Taskgroup taskgroup) {
|
||||
taskgroupRepository.delete(taskgroup);
|
||||
}
|
||||
|
||||
public List<Taskgroup> getTaskgroupsByUser(String username) {
|
||||
return taskgroupRepository.findAllByUser(username);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user