diff --git a/backend/.idea/workspace.xml b/backend/.idea/workspace.xml
index cf60247..ebfaa2e 100644
--- a/backend/.idea/workspace.xml
+++ b/backend/.idea/workspace.xml
@@ -7,8 +7,10 @@
+
+
@@ -87,23 +89,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -152,6 +138,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -177,11 +179,11 @@
+
-
@@ -561,7 +563,7 @@
file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java
- 50
+ 52
diff --git a/backend/src/main/java/core/api/controller/ScheduleController.java b/backend/src/main/java/core/api/controller/ScheduleController.java
index 9d62300..90ac6e4 100644
--- a/backend/src/main/java/core/api/controller/ScheduleController.java
+++ b/backend/src/main/java/core/api/controller/ScheduleController.java
@@ -5,6 +5,7 @@ import core.api.models.auth.SimpleStatusResponse;
import core.api.models.timemanager.taskSchedule.BasicScheduleFieldInfo;
import core.api.models.timemanager.taskSchedule.BasicScheduleInfo;
import core.api.models.timemanager.taskSchedule.ScheduleFieldInfo;
+import core.api.models.timemanager.taskSchedule.ScheduleInfo;
import core.entities.timemanager.AbstractSchedule;
import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.Task;
@@ -16,6 +17,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
+import java.time.LocalDate;
import java.util.List;
@@ -105,4 +107,11 @@ public class ScheduleController {
taskScheduleService.deleteSchedule(permissionResult.getResult());
return ResponseEntity.ok(new SimpleStatusResponse("success"));
}
+
+ @GetMapping("/schedules/{date}/{startable}")
+ public ResponseEntity> loadFilteredSchedulesOfUser(@PathVariable String date, @PathVariable boolean startable) {
+ List abstractSchedules = taskScheduleService.getFilteredScheduledOfUser(LocalDate.parse(date), startable, SecurityContextHolder.getContext().getAuthentication().getName());
+
+ return ResponseEntity.ok(abstractSchedules.stream().map(AbstractSchedule::toScheduleInfo).toList());
+ }
}
diff --git a/backend/src/main/java/core/repositories/timemanager/ScheduleRepository.java b/backend/src/main/java/core/repositories/timemanager/ScheduleRepository.java
index c947222..116271b 100644
--- a/backend/src/main/java/core/repositories/timemanager/ScheduleRepository.java
+++ b/backend/src/main/java/core/repositories/timemanager/ScheduleRepository.java
@@ -12,5 +12,4 @@ public interface ScheduleRepository extends CrudRepository findAllByUsername(String username);
-
}
diff --git a/backend/src/main/java/core/services/TaskScheduleService.java b/backend/src/main/java/core/services/TaskScheduleService.java
index 4f4b550..55f085c 100644
--- a/backend/src/main/java/core/services/TaskScheduleService.java
+++ b/backend/src/main/java/core/services/TaskScheduleService.java
@@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -55,4 +57,26 @@ public class TaskScheduleService {
public void deleteSchedule(AbstractSchedule schedule) {
scheduleRepository.delete(schedule);
}
+
+ public List getFilteredScheduledOfUser(LocalDate date, boolean startable, String name) {
+ List abstractSchedules = getAllSchedulesOfUser(name);
+ List filteredSchedules = new LinkedList<>();
+ for(AbstractSchedule abstractSchedule : abstractSchedules) {
+ if(abstractSchedule instanceof BasicTaskSchedule) {
+ if(((BasicTaskSchedule) abstractSchedule).getScheduleDate().isEqual(date)) {
+ //Schedule is today
+ if(startable && abstractSchedule.getStartTime() == null) {
+ if(abstractSchedule.getStartTime() == null) {
+ filteredSchedules.add(abstractSchedule);
+ }
+ } else if(!startable) {
+ filteredSchedules.add(abstractSchedule);
+ }
+ }
+ } else {
+ //to continue...
+ }
+ }
+ return filteredSchedules;
+ }
}
diff --git a/backend/src/test/java/core/schedules/ScheduleServiceTest.java b/backend/src/test/java/core/schedules/ScheduleServiceTest.java
index 9e25f2b..a6d55fc 100644
--- a/backend/src/test/java/core/schedules/ScheduleServiceTest.java
+++ b/backend/src/test/java/core/schedules/ScheduleServiceTest.java
@@ -108,4 +108,32 @@ public class ScheduleServiceTest {
assertThat(entityManager.find(BasicTaskSchedule.class, i)).isNull();
}
}
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql"),
+ @Sql("classpath:basicScheduleEntries.sql")
+ })
+ void getFilteredScheduledOfUser() {
+ //Invalid user
+ assertEquals(0, taskScheduleService.getFilteredScheduledOfUser(LocalDate.now(), false, "Quatsch").size());
+ assertEquals(0, taskScheduleService.getFilteredScheduledOfUser(LocalDate.now(), true, "Quatsch").size());
+
+ //User with no tasks/schedules
+ assertEquals(0, taskScheduleService.getFilteredScheduledOfUser(LocalDate.now(), false, username2).size());
+ assertEquals(0, taskScheduleService.getFilteredScheduledOfUser(LocalDate.now(), true, username2).size());
+
+ //user with tasks and schedules
+ List result_1 = taskScheduleService.getFilteredScheduledOfUser(LocalDate.of(2024,11,11), false, username);
+ assertEquals(3, result_1.size());
+ assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 1L)));
+ assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 2L)));
+ assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 3L)));
+
+ List result_2 = taskScheduleService.getFilteredScheduledOfUser(LocalDate.of(2024,11,11), true, username);
+ assertEquals(2, result_2.size());
+ assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 1L)));
+ assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 2L)));
+ }
}
diff --git a/backend/src/test/resources/basicScheduleEntries.sql b/backend/src/test/resources/basicScheduleEntries.sql
index 5726e26..763129e 100644
--- a/backend/src/test/resources/basicScheduleEntries.sql
+++ b/backend/src/test/resources/basicScheduleEntries.sql
@@ -1,3 +1,4 @@
INSERT INTO abstract_schedule (schedule_type, scheduleid, start_time, stop_time, schedule_date, task, schedule_end, schedule_start)
VALUES (0, 1, null, null, '2024-11-11', 1, null, null),
- (0, 2, null, null, '2024-11-11', 2, null, null);
\ No newline at end of file
+ (0, 2, null, null, '2024-11-11', 2, null, null),
+ (0, 3, '2023-10-10', null, '2024-11-11', 1, null, null);
\ No newline at end of file
diff --git a/frontend/src/api/api/schedule.service.ts b/frontend/src/api/api/schedule.service.ts
index 80e9dbf..c14f0e8 100644
--- a/frontend/src/api/api/schedule.service.ts
+++ b/frontend/src/api/api/schedule.service.ts
@@ -146,6 +146,69 @@ export class ScheduleService {
);
}
+ /**
+ * get today\'s schedules
+ * get all schedules of today
+ * @param date determines the scheduled dates of the schedules
+ * @param startable determines whether only schedules that can be started should be included or all schedules of today
+ * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
+ * @param reportProgress flag to report request and response progress.
+ */
+ public schedulesDateStartableGet(date: string, startable: boolean, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>;
+ public schedulesDateStartableGet(date: string, startable: boolean, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>;
+ public schedulesDateStartableGet(date: string, startable: boolean, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>;
+ public schedulesDateStartableGet(date: string, startable: boolean, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable {
+ if (date === null || date === undefined) {
+ throw new Error('Required parameter date was null or undefined when calling schedulesDateStartableGet.');
+ }
+ if (startable === null || startable === undefined) {
+ throw new Error('Required parameter startable was null or undefined when calling schedulesDateStartableGet.');
+ }
+
+ let localVarHeaders = this.defaultHeaders;
+
+ let localVarCredential: string | undefined;
+ // authentication (API_TOKEN) required
+ localVarCredential = this.configuration.lookupCredential('API_TOKEN');
+ if (localVarCredential) {
+ localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
+ }
+
+ let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
+ if (localVarHttpHeaderAcceptSelected === undefined) {
+ // to determine the Accept header
+ const httpHeaderAccepts: string[] = [
+ 'application/json'
+ ];
+ localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
+ }
+ if (localVarHttpHeaderAcceptSelected !== undefined) {
+ localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
+ }
+
+ let localVarHttpContext: HttpContext | undefined = options && options.context;
+ if (localVarHttpContext === undefined) {
+ localVarHttpContext = new HttpContext();
+ }
+
+
+ let responseType_: 'text' | 'json' = 'json';
+ if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
+ responseType_ = 'text';
+ }
+
+ return this.httpClient.get>(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(date))}/${encodeURIComponent(String(startable))}`,
+ {
+ context: localVarHttpContext,
+ responseType: responseType_,
+ withCredentials: this.configuration.withCredentials,
+ headers: localVarHeaders,
+ observe: observe,
+ reportProgress: reportProgress
+ }
+ );
+ }
+
/**
* gets all schedules of user
* gets all schedules of user
@@ -880,63 +943,4 @@ export class ScheduleService {
);
}
- /**
- * get today\'s schedules
- * get all schedules of today
- * @param activateable determines whether only schedules that can be started should be included or all schedules of today
- * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
- * @param reportProgress flag to report request and response progress.
- */
- public schedulesTodayActivateableGet(activateable: boolean, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>;
- public schedulesTodayActivateableGet(activateable: boolean, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>;
- public schedulesTodayActivateableGet(activateable: boolean, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>;
- public schedulesTodayActivateableGet(activateable: boolean, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable {
- if (activateable === null || activateable === undefined) {
- throw new Error('Required parameter activateable was null or undefined when calling schedulesTodayActivateableGet.');
- }
-
- let localVarHeaders = this.defaultHeaders;
-
- let localVarCredential: string | undefined;
- // authentication (API_TOKEN) required
- localVarCredential = this.configuration.lookupCredential('API_TOKEN');
- if (localVarCredential) {
- localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
- }
-
- let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
- if (localVarHttpHeaderAcceptSelected === undefined) {
- // to determine the Accept header
- const httpHeaderAccepts: string[] = [
- 'application/json'
- ];
- localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
- }
- if (localVarHttpHeaderAcceptSelected !== undefined) {
- localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
- }
-
- let localVarHttpContext: HttpContext | undefined = options && options.context;
- if (localVarHttpContext === undefined) {
- localVarHttpContext = new HttpContext();
- }
-
-
- let responseType_: 'text' | 'json' = 'json';
- if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
- responseType_ = 'text';
- }
-
- return this.httpClient.get>(`${this.configuration.basePath}/schedules/today/${encodeURIComponent(String(activateable))}`,
- {
- context: localVarHttpContext,
- responseType: responseType_,
- withCredentials: this.configuration.withCredentials,
- headers: localVarHeaders,
- observe: observe,
- reportProgress: reportProgress
- }
- );
- }
-
}
diff --git a/frontend/src/app/dashboard/dashboard.component.ts b/frontend/src/app/dashboard/dashboard.component.ts
index a012bd1..1f7cfaf 100644
--- a/frontend/src/app/dashboard/dashboard.component.ts
+++ b/frontend/src/app/dashboard/dashboard.component.ts
@@ -30,7 +30,7 @@ export class DashboardComponent implements OnInit{
}
ngOnInit() {
- this.scheduleService.schedulesTodayActivateableGet(true).subscribe({
+ this.scheduleService.schedulesDateStartableGet(String(Date.now()), true).subscribe({
next: resp => {
this.schedules = resp;
}
diff --git a/openapi.yaml b/openapi.yaml
index 4b240f0..111e627 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -1431,7 +1431,7 @@ paths:
schema:
type: object
$ref: "#/components/schemas/SimpleStatusResponse"
- /schedules/today/{activateable}:
+ /schedules/{date}/{startable}:
get:
security:
- API_TOKEN: []
@@ -1440,7 +1440,15 @@ paths:
description: get all schedules of today
summary: get today's schedules
parameters:
- - name: activateable
+ - name: date
+ in: path
+ description: determines the scheduled dates of the schedules
+ required: true
+ schema:
+ type: string
+ format: date
+ nullable: true
+ - name: startable
in: path
description: determines whether only schedules that can be started should be included or all schedules of today
required: true