issue-23 #24

Merged
sebastian merged 4 commits from issue-23 into issue-18 2023-10-24 19:24:22 +02:00
10 changed files with 276 additions and 9 deletions
Showing only changes of commit 7707831463 - Show all commits

View File

@ -5,9 +5,13 @@
</component>
<component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Delete Schedules">
<change beforePath="$PROJECT_DIR$/../frontend/src/app/schedules/schedule-dashboard/schedule-dashboard.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/schedules/schedule-dashboard/schedule-dashboard.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/schedules/scheduler/scheduler.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/schedules/scheduler/scheduler.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/schedules/scheduler/scheduler.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/schedules/scheduler/scheduler.component.ts" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskSchedule/AbstractScheduleShortInfo.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskSchedule/BasicScheduleShortInfo.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskSchedule/ScheduleInfo.java" afterDir="false" />
<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/BasicTaskScheduleRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/BasicTaskScheduleRepository.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" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -96,6 +100,7 @@
<workItem from="1697969480767" duration="6407000" />
<workItem from="1697989716016" duration="3814000" />
<workItem from="1698067098771" duration="4770000" />
<workItem from="1698127431684" duration="1530000" />
</task>
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
<option name="closed" value="true" />
@ -180,7 +185,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java</url>
<line>36</line>
<line>41</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
</breakpoints>

View File

@ -3,9 +3,11 @@ package core.api.controller;
import core.api.models.auth.SimpleStatusResponse;
import core.api.models.timemanager.taskSchedule.BasicTaskScheduleEntityInfo;
import core.api.models.timemanager.taskSchedule.BasicTaskScheduleFieldInfo;
import core.api.models.timemanager.taskSchedule.ScheduleInfo;
import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.ScheduleType;
import core.entities.timemanager.Task;
import core.repositories.timemanager.BasicTaskScheduleRepository;
import core.services.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
@ -24,10 +26,13 @@ public class ScheduleController {
private final TaskService taskService;
private final TaskScheduleService taskScheduleService;
private final BasicTaskScheduleRepository basicTaskScheduleRepository;
public ScheduleController(@Autowired TaskService taskService, @Autowired TaskScheduleService taskScheduleService) {
public ScheduleController(@Autowired TaskService taskService, @Autowired TaskScheduleService taskScheduleService,
BasicTaskScheduleRepository basicTaskScheduleRepository) {
this.taskService = taskService;
this.taskScheduleService = taskScheduleService;
this.basicTaskScheduleRepository = basicTaskScheduleRepository;
}
@GetMapping("/schedules/{taskID}/{scheduleType}")
@ -96,4 +101,24 @@ public class ScheduleController {
taskScheduleService.deleteBasicSchedule(permissionResult.getResult());
return ResponseEntity.ok(new SimpleStatusResponse("success"));
}
@GetMapping("/schedules/today")
public ResponseEntity<?> loadTodaysSchedules() {
ServiceResult<List<BasicTaskSchedule>> todaysSchedules = taskScheduleService.loadTodaysSchedule(SecurityContextHolder.getContext().getAuthentication().getName());
if(todaysSchedules.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
} else {
return ResponseEntity.ok(todaysSchedules.getResult().stream().map(ScheduleInfo::new).toList());
}
}
@GetMapping("/schedules")
public ResponseEntity<?> loadSchedules() {
ServiceResult<List<BasicTaskSchedule>> schedules = taskScheduleService.loadSchedules(SecurityContextHolder.getContext().getAuthentication().getName());
if(schedules.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
} else {
return ResponseEntity.ok(schedules.getResult().stream().map(ScheduleInfo::new).toList());
}
}
}

View File

@ -0,0 +1,4 @@
package core.api.models.timemanager.taskSchedule;
public abstract class AbstractScheduleShortInfo {
}

View File

@ -0,0 +1,22 @@
package core.api.models.timemanager.taskSchedule;
import core.entities.timemanager.BasicTaskSchedule;
import java.time.LocalDate;
public class BasicScheduleShortInfo extends AbstractScheduleShortInfo {
private LocalDate scheduleDate;
public BasicScheduleShortInfo(BasicTaskSchedule basicTaskSchedule) {
this.scheduleDate = basicTaskSchedule.getScheduleDate();
}
public LocalDate getScheduleDate() {
return scheduleDate;
}
public void setScheduleDate(LocalDate scheduleDate) {
this.scheduleDate = scheduleDate;
}
}

View File

@ -0,0 +1,83 @@
package core.api.models.timemanager.taskSchedule;
import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.ScheduleType;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
public class ScheduleInfo {
private long scheduleID;
private ScheduleType scheduleType;
private LocalDateTime startTime;
private LocalDateTime finishTime;
private int activeMinutes;
private AbstractScheduleShortInfo schedule;
public ScheduleInfo(BasicTaskSchedule basicTaskSchedule) {
this.scheduleID = basicTaskSchedule.getScheduleID();
this.scheduleType = ScheduleType.BASIC;
this.startTime = basicTaskSchedule.getStartTime();
this.finishTime = basicTaskSchedule.getFinishedTime();
if(this.finishTime == null) {
this.activeMinutes = (int) Duration.between(basicTaskSchedule.getStartTime(), LocalDate.now()).toMinutes();
} else {
this.activeMinutes = (int) Duration.between(basicTaskSchedule.getStartTime(), basicTaskSchedule.getFinishedTime()).toMinutes();
}
this.schedule = new BasicScheduleShortInfo(basicTaskSchedule);
}
public long getScheduleID() {
return scheduleID;
}
public void setScheduleID(long scheduleID) {
this.scheduleID = scheduleID;
}
public ScheduleType getScheduleType() {
return scheduleType;
}
public void setScheduleType(ScheduleType scheduleType) {
this.scheduleType = scheduleType;
}
public LocalDateTime getStartTime() {
return startTime;
}
public void setStartTime(LocalDateTime startTime) {
this.startTime = startTime;
}
public LocalDateTime getFinishTime() {
return finishTime;
}
public void setFinishTime(LocalDateTime finishTime) {
this.finishTime = finishTime;
}
public int getActiveMinutes() {
return activeMinutes;
}
public void setActiveMinutes(int activeMinutes) {
this.activeMinutes = activeMinutes;
}
public AbstractScheduleShortInfo getSchedule() {
return schedule;
}
public void setSchedule(AbstractScheduleShortInfo schedule) {
this.schedule = schedule;
}
}

View File

@ -1,5 +1,6 @@
package core.repositories.timemanager;
import core.entities.User;
import core.entities.timemanager.BasicTaskSchedule;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -7,6 +8,8 @@ import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;
@Repository
public interface BasicTaskScheduleRepository extends CrudRepository<BasicTaskSchedule, Long> {
@ -15,4 +18,10 @@ public interface BasicTaskScheduleRepository extends CrudRepository<BasicTaskSch
@Transactional
@Query(value = "DELETE FROM BasicTaskSchedule bts WHERE bts.scheduleID = ?1")
void deleteBasicTaskScheduleByID(long id);
@Query(value = "SELECT bts FROM BasicTaskSchedule bts WHERE bts.task.taskgroup.user = ?1")
List<BasicTaskSchedule> findAllByUser(User user);
@Query(value = "SELECT bts FROM BasicTaskSchedule bts WHERE bts.task.taskgroup.user = ?1 AND bts.scheduleDate = ?2")
List<BasicTaskSchedule> findAllByUserAndDate(User user, LocalDate localDate);
}

View File

@ -1,13 +1,17 @@
package core.services;
import core.api.models.timemanager.taskSchedule.BasicTaskScheduleFieldInfo;
import core.entities.User;
import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.Task;
import core.repositories.UserRepository;
import core.repositories.timemanager.BasicTaskScheduleRepository;
import core.repositories.timemanager.TaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
@Service
@ -15,11 +19,14 @@ public class TaskScheduleService {
private final BasicTaskScheduleRepository basicTaskScheduleRepository;
private final TaskRepository taskRepository;
private final UserRepository userRepository;
public TaskScheduleService(@Autowired BasicTaskScheduleRepository basicTaskScheduleRepository,
@Autowired TaskRepository taskRepository) {
@Autowired TaskRepository taskRepository,
UserRepository userRepository) {
this.basicTaskScheduleRepository = basicTaskScheduleRepository;
this.taskRepository = taskRepository;
this.userRepository = userRepository;
}
public ServiceResult<BasicTaskSchedule> createBasicTaskSchedule(Task task, BasicTaskScheduleFieldInfo basicTaskScheduleFieldInfo) {
@ -44,4 +51,16 @@ public class TaskScheduleService {
public void deleteBasicSchedule(BasicTaskSchedule basicTaskSchedule) {
basicTaskScheduleRepository.deleteBasicTaskScheduleByID(basicTaskSchedule.getScheduleID());
}
public ServiceResult<List<BasicTaskSchedule>> loadTodaysSchedule(String username) {
Optional<User> user = userRepository.findByUsername(username);
return user.map(value -> new ServiceResult<>(basicTaskScheduleRepository.findAllByUserAndDate(value, LocalDate.now()))).orElseGet(() ->
new ServiceResult<>(ServiceExitCode.MISSING_ENTITY));
}
public ServiceResult<List<BasicTaskSchedule>> loadSchedules(String username) {
Optional<User> user = userRepository.findByUsername(username);
return user.map(value -> new ServiceResult<>(basicTaskScheduleRepository.findAllByUser(value))).orElseGet(() ->
new ServiceResult<>(ServiceExitCode.MISSING_ENTITY));
}
}

View File

@ -409,4 +409,59 @@ export class ScheduleService {
);
}
/**
* get today\&#39;s schedules
* get 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 schedulesTodayGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<ScheduleInfo>>;
public schedulesTodayGet(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<ScheduleInfo>>>;
public schedulesTodayGet(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<ScheduleInfo>>>;
public schedulesTodayGet(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
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`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
}

View File

@ -9,7 +9,7 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { BasicScheduleEntityInfo } from './basicScheduleEntityInfo';
import { BasicScheduleFieldInfo } from './basicScheduleFieldInfo';
export interface ScheduleInfo {
@ -21,7 +21,19 @@ export interface ScheduleInfo {
* type of schedule
*/
scheduleType: ScheduleInfo.ScheduleTypeEnum;
schedule: BasicScheduleEntityInfo;
/**
* date on which the task schedule was started
*/
startTime: string;
/**
* date on which the tasks schedule was finished
*/
finishedTime?: string;
/**
* number in minutes that the schedule was active
*/
activeMinutes: number;
schedule: BasicScheduleFieldInfo;
}
export namespace ScheduleInfo {
export type ScheduleTypeEnum = 'BASIC' | 'MODERATE' | 'ADVANCED';

View File

@ -1355,6 +1355,24 @@ paths:
schema:
type: object
$ref: "#/components/schemas/SimpleStatusResponse"
/schedules/today:
get:
security:
- API_TOKEN: []
tags:
- schedule
description: get all schedules of today
summary: get today's schedules
responses:
200:
description: Operation successfull
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ScheduleInfo'
components:
securitySchemes:
API_TOKEN:
@ -1712,6 +1730,9 @@ components:
required:
- scheduleID
- scheduleType
- startTime
- finishTime
- activeMinutes
- schedule
additionalProperties: false
properties:
@ -1727,7 +1748,19 @@ components:
- BASIC
- MODERATE
- ADVANCED
startTime:
type: string
format: date-time
description: date on which the task schedule was started
finishedTime:
type: string
format: date-time
description: date on which the tasks schedule was finished
activeMinutes:
type: number
description: number in minutes that the schedule was active
example: 10
schedule:
type: object
oneOf:
- $ref: '#/components/schemas/BasicScheduleEntityInfo'
- $ref: '#/components/schemas/BasicScheduleFieldInfo'