Get Startable schedules of today
Some checks failed
Java CI with Maven / build (push) Failing after 36s

This commit is contained in:
Sebastian Böckelmann 2023-11-11 16:40:57 +01:00
parent 5edf192b98
commit e194c95863
9 changed files with 158 additions and 83 deletions

View File

@ -7,8 +7,10 @@
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Basic Reschedule">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/ScheduleRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/ScheduleRepository.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/core/schedules/ScheduleServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/schedules/ScheduleServiceTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/resources/basicScheduleEntries.sql" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/resources/basicScheduleEntries.sql" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -87,23 +89,7 @@
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
</key>
</component>
<component name="RunManager" selected="JUnit.ScheduleServiceTest.deleteSchedule">
<configuration name="ScheduleRepositoryTest.getAllSchedulesOfUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.schedules.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.schedules" />
<option name="MAIN_CLASS_NAME" value="core.schedules.ScheduleRepositoryTest" />
<option name="METHOD_NAME" value="getAllSchedulesOfUser" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<component name="RunManager" selected="Spring Boot.DemoApplication">
<configuration name="ScheduleServiceTest.deleteSchedule" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
@ -152,6 +138,22 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ScheduleServiceTest.getFilteredScheduledOfUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.schedules.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.schedules" />
<option name="MAIN_CLASS_NAME" value="core.schedules.ScheduleServiceTest" />
<option name="METHOD_NAME" value="getFilteredScheduledOfUser" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ScheduleServiceTest.scheduleBasic" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
@ -177,11 +179,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.ScheduleServiceTest.getFilteredScheduledOfUser" />
<item itemvalue="JUnit.ScheduleServiceTest.deleteSchedule" />
<item itemvalue="JUnit.ScheduleServiceTest.editBasicSchedule" />
<item itemvalue="JUnit.ScheduleServiceTest.scheduleBasic" />
<item itemvalue="JUnit.ScheduleServiceTest.getAllSchedulesOfUser" />
<item itemvalue="JUnit.ScheduleRepositoryTest.getAllSchedulesOfUser" />
</list>
</recent_temporary>
</component>
@ -561,7 +563,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java</url>
<line>50</line>
<line>52</line>
<option name="timeStamp" value="32" />
</line-breakpoint>
</breakpoints>

View File

@ -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<AbstractSchedule> abstractSchedules = taskScheduleService.getFilteredScheduledOfUser(LocalDate.parse(date), startable, SecurityContextHolder.getContext().getAuthentication().getName());
return ResponseEntity.ok(abstractSchedules.stream().map(AbstractSchedule::toScheduleInfo).toList());
}
}

View File

@ -12,5 +12,4 @@ public interface ScheduleRepository extends CrudRepository<AbstractSchedule, Lon
@Query(value = "SELECT s FROM AbstractSchedule s WHERE s.task.taskgroup.user.username = ?1")
List<AbstractSchedule> findAllByUsername(String username);
}

View File

@ -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<AbstractSchedule> getFilteredScheduledOfUser(LocalDate date, boolean startable, String name) {
List<AbstractSchedule> abstractSchedules = getAllSchedulesOfUser(name);
List<AbstractSchedule> 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;
}
}

View File

@ -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<AbstractSchedule> 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<AbstractSchedule> 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)));
}
}

View File

@ -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);
(0, 2, null, null, '2024-11-11', 2, null, null),
(0, 3, '2023-10-10', null, '2024-11-11', 1, null, null);

View File

@ -146,6 +146,69 @@ export class ScheduleService {
);
}
/**
* get today\&#39;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<Array<ScheduleInfo>>;
public schedulesDateStartableGet(date: string, startable: boolean, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<ScheduleInfo>>>;
public schedulesDateStartableGet(date: string, startable: boolean, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<ScheduleInfo>>>;
public schedulesDateStartableGet(date: string, startable: boolean, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
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<Array<ScheduleInfo>>(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(date))}/${encodeURIComponent(String(startable))}`,
{
context: localVarHttpContext,
responseType: <any>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\&#39;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<Array<ScheduleInfo>>;
public schedulesTodayActivateableGet(activateable: boolean, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<ScheduleInfo>>>;
public schedulesTodayActivateableGet(activateable: boolean, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<ScheduleInfo>>>;
public schedulesTodayActivateableGet(activateable: boolean, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
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<Array<ScheduleInfo>>(`${this.configuration.basePath}/schedules/today/${encodeURIComponent(String(activateable))}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
}

View File

@ -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;
}

View File

@ -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