diff --git a/backend/.idea/workspace.xml b/backend/.idea/workspace.xml
index 9f87681..ec8b0d2 100644
--- a/backend/.idea/workspace.xml
+++ b/backend/.idea/workspace.xml
@@ -4,10 +4,11 @@
-
-
-
+
+
+
+
@@ -86,8 +87,8 @@
-
-
+
+
@@ -97,70 +98,71 @@
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
+
-
+
-
-
-
+
+
+
-
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -175,11 +177,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -215,7 +217,8 @@
-
+
+
@@ -417,14 +420,21 @@
1699471078386
-
+
+
+ 1699474949938
+
+
+
+ 1699474949938
+
+
-
@@ -449,7 +459,8 @@
-
+
+
@@ -479,6 +490,16 @@
57
+
+ file://$PROJECT_DIR$/src/test/java/core/tasks/TaskRepositoryTest.java
+ 152
+
+
+
+ file://$PROJECT_DIR$/src/test/java/core/tasks/TaskRepositoryTest.java
+ 151
+
+
diff --git a/backend/src/main/java/core/repositories/timemanager/TaskRepository.java b/backend/src/main/java/core/repositories/timemanager/TaskRepository.java
index fd8d118..d4f7268 100644
--- a/backend/src/main/java/core/repositories/timemanager/TaskRepository.java
+++ b/backend/src/main/java/core/repositories/timemanager/TaskRepository.java
@@ -17,22 +17,21 @@ public interface TaskRepository extends CrudRepository {
@Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.finished = ?2")
List findAllByUser(String username, boolean finished);
- @Transactional
+
@Modifying
- @Query(value = "DELETE FROM Task t WHERE t.taskgroup = ?1")
+ @Transactional
void deleteAllByTaskgroup(Taskgroup taskgroup);
@Transactional
@Modifying
- @Query(value = "DELETE FROM Task t WHERE t.taskID = ?1")
void deleteByTaskID(long taskID);
- @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.deadline is NOT NULL AND t.deadline > ?2 AND t.finished = FALSE")
+ @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.deadline is NOT NULL AND t.deadline < ?2 AND t.finished = FALSE")
List findAllOverdue(String username, LocalDate now);
@Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.startDate IS NOT NULL AND t.startDate > ?2 AND t.finished = FALSE")
List findAllUpcoming(String username, LocalDate now);
- @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND t.startDate IS NULL OR t.startDate <= ?2 AND t.finished = FALSE")
+ @Query(value = "SELECT t FROM Task t WHERE t.taskgroup.user.username = ?1 AND (t.startDate IS NULL OR t.startDate <= ?2) AND t.finished = FALSE")
List findAllActive(String username, LocalDate now);
}
diff --git a/backend/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java b/backend/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java
index 3da0877..1172aa8 100644
--- a/backend/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java
+++ b/backend/src/test/java/core/taskgroups/TaskgroupRepsitoryTest.java
@@ -108,6 +108,5 @@ public class TaskgroupRepsitoryTest {
for(long i=5; i<=8; i++) {
assertThat(testEntityManager.find(Taskgroup.class, i)).isNull();
}
-
}
}
diff --git a/backend/src/test/java/core/tasks/TaskRepositoryTest.java b/backend/src/test/java/core/tasks/TaskRepositoryTest.java
index fde7b8c..5df74d5 100644
--- a/backend/src/test/java/core/tasks/TaskRepositoryTest.java
+++ b/backend/src/test/java/core/tasks/TaskRepositoryTest.java
@@ -13,8 +13,10 @@ import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlGroup;
import org.springframework.test.context.junit.jupiter.SpringExtension;
+import java.time.LocalDate;
import java.util.List;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -65,4 +67,94 @@ public class TaskRepositoryTest {
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 13L)));
assertTrue(tasks_user1_true.contains(testEntityManager.find(Task.class, 14L)));
}
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void deleteAllByTaskgroup() {
+ Taskgroup taskgroup_no_tasks = testEntityManager.find(Taskgroup.class, 1L);
+ taskRepository.deleteAllByTaskgroup(taskgroup_no_tasks);
+
+ for(long i=1; i<=14; i++) {
+ assertThat(testEntityManager.find(Task.class, i)).isNotNull();
+ }
+
+ Taskgroup taskgroup_with_task = testEntityManager.find(Taskgroup.class, 2L);
+ taskRepository.deleteAllByTaskgroup(taskgroup_with_task);
+ for(long i=1; i<=14; i++) {
+ Task task = testEntityManager.find(Task.class, i);
+ assertThat(task).isNull();
+ }
+ }
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void deleteByTaskID() {
+ taskRepository.deleteByTaskID(-1);
+ for(long i=1; i<=14; i++) {
+ assertThat(testEntityManager.find(Task.class, i)).isNotNull();
+ }
+
+ taskRepository.deleteByTaskID(1);
+ assertThat(testEntityManager.find(Task.class, 1L)).isNull();
+ for(long i=2; i<=14; i++) {
+ assertThat(testEntityManager.find(Task.class, i)).isNotNull();
+ }
+ }
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void findAllOverdue() {
+ User testuser1 = testEntityManager.find(User.class, 1L);
+ LocalDate referenceDate = LocalDate.of(2023, 10, 11);
+
+ List overdue = taskRepository.findAllOverdue(testuser1.getUsername(), referenceDate);
+ assertEquals(2, overdue.size());
+ assertTrue(overdue.contains(testEntityManager.find(Task.class, 3L)));
+ assertTrue(overdue.contains(testEntityManager.find(Task.class, 5L)));
+ }
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void findAllUpcoming() {
+ User testuser1 = testEntityManager.find(User.class, 1L);
+ LocalDate referenceDate = LocalDate.of(2023, 10, 11);
+
+ List upcoming = taskRepository.findAllUpcoming(testuser1.getUsername(), referenceDate);
+ assertEquals(2, upcoming.size());
+ assertTrue(upcoming.contains(testEntityManager.find(Task.class, 7L)));
+ assertTrue(upcoming.contains(testEntityManager.find(Task.class, 9L)));
+
+ }
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void findAllActive() {
+ User testuser1 = testEntityManager.find(User.class, 1L);
+ LocalDate referenceDate = LocalDate.of(2023, 10, 11);
+
+ List active = taskRepository.findAllActive(testuser1.getUsername(), referenceDate);
+ //1,3,5,11,12
+ assertEquals(5, active.size());
+ assertTrue(active.contains(testEntityManager.find(Task.class, 1L)));
+ assertTrue(active.contains(testEntityManager.find(Task.class, 3L)));
+ assertTrue(active.contains(testEntityManager.find(Task.class, 5L)));
+ assertTrue(active.contains(testEntityManager.find(Task.class, 11L)));
+ assertTrue(active.contains(testEntityManager.find(Task.class, 12L)));
+ }
+
}