From dadb1204e8e1eae5ff3686329d26414d9d73f28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 11 Nov 2023 15:28:10 +0100 Subject: [PATCH] Refactor /schedules and /schedules/{taskID} endpoints (get + put) --- frontend/src/api/.openapi-generator/FILES | 2 + frontend/src/api/api/schedule.service.ts | 161 +++++++++--------- frontend/src/api/model/basicScheduleInfo.ts | 52 ++++++ .../src/api/model/basicScheduleInfoAllOf.ts | 17 ++ frontend/src/api/model/models.ts | 2 + frontend/src/api/model/scheduleInfo.ts | 2 - .../missed-schedules.component.html | 2 +- .../missed-schedules.component.ts | 6 +- .../basic-scheduler.component.ts | 12 +- .../schedule-dashboard.component.html | 16 +- .../schedule-dashboard.component.ts | 18 +- .../scheduler/scheduler.component.ts | 33 ++-- openapi.yaml | 34 ++-- 13 files changed, 224 insertions(+), 133 deletions(-) create mode 100644 frontend/src/api/model/basicScheduleInfo.ts create mode 100644 frontend/src/api/model/basicScheduleInfoAllOf.ts diff --git a/frontend/src/api/.openapi-generator/FILES b/frontend/src/api/.openapi-generator/FILES index 51b9f45..c190ae0 100644 --- a/frontend/src/api/.openapi-generator/FILES +++ b/frontend/src/api/.openapi-generator/FILES @@ -16,6 +16,8 @@ index.ts model/accountDeleteRequest.ts model/basicScheduleEntityInfo.ts model/basicScheduleFieldInfo.ts +model/basicScheduleInfo.ts +model/basicScheduleInfoAllOf.ts model/eMailChangeRequest.ts model/forgottenActivityRequest.ts model/inlineResponse200.ts diff --git a/frontend/src/api/api/schedule.service.ts b/frontend/src/api/api/schedule.service.ts index e19c1ef..d686ebc 100644 --- a/frontend/src/api/api/schedule.service.ts +++ b/frontend/src/api/api/schedule.service.ts @@ -18,7 +18,6 @@ import { HttpClient, HttpHeaders, HttpParams, import { CustomHttpParameterCodec } from '../encoder'; import { Observable } from 'rxjs'; -import { BasicScheduleEntityInfo } from '../model/models'; import { BasicScheduleFieldInfo } from '../model/models'; import { ForgottenActivityRequest } from '../model/models'; import { ScheduleActivateInfo } from '../model/models'; @@ -626,76 +625,6 @@ export class ScheduleService { ); } - /** - * creates basic schedule for task - * creates a basic schedule for a task - * @param taskID internal id of task - * @param basicScheduleFieldInfo - * @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 schedulesTaskIDBasicPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable; - public schedulesTaskIDBasicPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; - public schedulesTaskIDBasicPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; - public schedulesTaskIDBasicPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable { - if (taskID === null || taskID === undefined) { - throw new Error('Required parameter taskID was null or undefined when calling schedulesTaskIDBasicPut.'); - } - - 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(); - } - - - // to determine the Content-Type header - const consumes: string[] = [ - 'application/json' - ]; - const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); - if (httpContentTypeSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected); - } - - let responseType_: 'text' | 'json' = 'json'; - if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } - - return this.httpClient.put(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(taskID))}/basic`, - basicScheduleFieldInfo, - { - context: localVarHttpContext, - responseType: responseType_, - withCredentials: this.configuration.withCredentials, - headers: localVarHeaders, - observe: observe, - reportProgress: reportProgress - } - ); - } - /** * registers forgotten schedule * Registers forgotten schedule @@ -766,6 +695,65 @@ export class ScheduleService { ); } + /** + * gets schedules of task + * gets schedules of task + * @param taskID internal id of task + * @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 schedulesTaskIDGet(taskID: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; + public schedulesTaskIDGet(taskID: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>; + public schedulesTaskIDGet(taskID: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>; + public schedulesTaskIDGet(taskID: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable { + if (taskID === null || taskID === undefined) { + throw new Error('Required parameter taskID was null or undefined when calling schedulesTaskIDGet.'); + } + + 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(taskID))}`, + { + context: localVarHttpContext, + responseType: responseType_, + withCredentials: this.configuration.withCredentials, + headers: localVarHeaders, + observe: observe, + reportProgress: reportProgress + } + ); + } + /** * schedule task now * schedule task now @@ -827,22 +815,19 @@ export class ScheduleService { } /** - * gets schedules of task - * gets schedules of task + * creates basic schedule for task + * creates a basic schedule for a task * @param taskID internal id of task - * @param scheduleType internal id of task + * @param basicScheduleFieldInfo * @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 schedulesTaskIDScheduleTypeGet(taskID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; - public schedulesTaskIDScheduleTypeGet(taskID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>; - public schedulesTaskIDScheduleTypeGet(taskID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>>; - public schedulesTaskIDScheduleTypeGet(taskID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable { + public schedulesTaskIDPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable; + public schedulesTaskIDPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; + public schedulesTaskIDPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable>; + public schedulesTaskIDPut(taskID: number, basicScheduleFieldInfo?: BasicScheduleFieldInfo, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable { if (taskID === null || taskID === undefined) { - throw new Error('Required parameter taskID was null or undefined when calling schedulesTaskIDScheduleTypeGet.'); - } - if (scheduleType === null || scheduleType === undefined) { - throw new Error('Required parameter scheduleType was null or undefined when calling schedulesTaskIDScheduleTypeGet.'); + throw new Error('Required parameter taskID was null or undefined when calling schedulesTaskIDPut.'); } let localVarHeaders = this.defaultHeaders; @@ -872,12 +857,22 @@ export class ScheduleService { } + // to determine the Content-Type header + const consumes: string[] = [ + 'application/json' + ]; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected); + } + let responseType_: 'text' | 'json' = 'json'; if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) { responseType_ = 'text'; } - return this.httpClient.get>(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(taskID))}/${encodeURIComponent(String(scheduleType))}`, + return this.httpClient.put(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(taskID))}`, + basicScheduleFieldInfo, { context: localVarHttpContext, responseType: responseType_, diff --git a/frontend/src/api/model/basicScheduleInfo.ts b/frontend/src/api/model/basicScheduleInfo.ts new file mode 100644 index 0000000..6cf4391 --- /dev/null +++ b/frontend/src/api/model/basicScheduleInfo.ts @@ -0,0 +1,52 @@ +/** + * API Title + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { BasicScheduleInfoAllOf } from './basicScheduleInfoAllOf'; +import { TaskgroupEntityInfo } from './taskgroupEntityInfo'; +import { TaskShortInfo } from './taskShortInfo'; +import { ScheduleInfo } from './scheduleInfo'; + + +export interface BasicScheduleInfo { + /** + * internal id of schedule + */ + scheduleID: number; + /** + * type of schedule + */ + scheduleType: BasicScheduleInfo.ScheduleTypeEnum; + /** + * 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; + task: TaskShortInfo; + taskgroupPath: Array; + scheduleDate: string; +} +export namespace BasicScheduleInfo { + export type ScheduleTypeEnum = 'BASIC' | 'MODERATE' | 'ADVANCED'; + export const ScheduleTypeEnum = { + Basic: 'BASIC' as ScheduleTypeEnum, + Moderate: 'MODERATE' as ScheduleTypeEnum, + Advanced: 'ADVANCED' as ScheduleTypeEnum + }; +} + + diff --git a/frontend/src/api/model/basicScheduleInfoAllOf.ts b/frontend/src/api/model/basicScheduleInfoAllOf.ts new file mode 100644 index 0000000..ed13196 --- /dev/null +++ b/frontend/src/api/model/basicScheduleInfoAllOf.ts @@ -0,0 +1,17 @@ +/** + * API Title + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface BasicScheduleInfoAllOf { + scheduleDate: string; +} + diff --git a/frontend/src/api/model/models.ts b/frontend/src/api/model/models.ts index 0515444..26a3e14 100644 --- a/frontend/src/api/model/models.ts +++ b/frontend/src/api/model/models.ts @@ -1,6 +1,8 @@ export * from './accountDeleteRequest'; export * from './basicScheduleEntityInfo'; export * from './basicScheduleFieldInfo'; +export * from './basicScheduleInfo'; +export * from './basicScheduleInfoAllOf'; export * from './eMailChangeRequest'; export * from './forgottenActivityRequest'; export * from './inlineResponse200'; diff --git a/frontend/src/api/model/scheduleInfo.ts b/frontend/src/api/model/scheduleInfo.ts index a9deba8..9f09ca6 100644 --- a/frontend/src/api/model/scheduleInfo.ts +++ b/frontend/src/api/model/scheduleInfo.ts @@ -9,7 +9,6 @@ * https://openapi-generator.tech * Do not edit the class manually. */ -import { BasicScheduleFieldInfo } from './basicScheduleFieldInfo'; import { TaskgroupEntityInfo } from './taskgroupEntityInfo'; import { TaskShortInfo } from './taskShortInfo'; @@ -35,7 +34,6 @@ export interface ScheduleInfo { * number in minutes that the schedule was active */ activeMinutes: number; - schedule: BasicScheduleFieldInfo; task: TaskShortInfo; taskgroupPath: Array; } diff --git a/frontend/src/app/missed-schedules/missed-schedules.component.html b/frontend/src/app/missed-schedules/missed-schedules.component.html index ad49ce8..b7ba6b2 100644 --- a/frontend/src/app/missed-schedules/missed-schedules.component.html +++ b/frontend/src/app/missed-schedules/missed-schedules.component.html @@ -13,7 +13,7 @@
-

Originally planned: {{schedule.schedule.scheduleDate}}

+

Originally planned: {{toBasicSchedule(schedule).scheduleDate}}

- + +
+

{{ toBasicSchedule(schedule).scheduleDate | date:'EEEE, d MMM. y'}}

+
+ + +
-
+ + + diff --git a/frontend/src/app/schedules/schedule-dashboard/schedule-dashboard.component.ts b/frontend/src/app/schedules/schedule-dashboard/schedule-dashboard.component.ts index 82de4b0..6ce456a 100644 --- a/frontend/src/app/schedules/schedule-dashboard/schedule-dashboard.component.ts +++ b/frontend/src/app/schedules/schedule-dashboard/schedule-dashboard.component.ts @@ -1,5 +1,11 @@ import {Component, Input, OnInit} from '@angular/core'; -import {BasicScheduleEntityInfo, ScheduleService, TaskEntityInfo, TaskgroupEntityInfo} from "../../../api"; +import { + BasicScheduleEntityInfo, BasicScheduleInfo, + ScheduleInfo, + ScheduleService, + TaskEntityInfo, + TaskgroupEntityInfo +} from "../../../api"; import {MatSnackBar} from "@angular/material/snack-bar"; @Component({ @@ -12,7 +18,7 @@ export class ScheduleDashboardComponent implements OnInit{ @Input('taskgroup') taskgroup: TaskgroupEntityInfo | undefined @Input('task') task: TaskEntityInfo | undefined - schedules: BasicScheduleEntityInfo[] = [] + schedules: ScheduleInfo[] = [] constructor(private scheduleService: ScheduleService, private snackbar: MatSnackBar) { @@ -20,7 +26,7 @@ export class ScheduleDashboardComponent implements OnInit{ } ngOnInit() { - this.scheduleService.schedulesTaskIDScheduleTypeGet(this.task!.taskID, "BASIC").subscribe({ + this.scheduleService.schedulesTaskIDGet(this.task!.taskID).subscribe({ next: resp => { this.schedules = resp; } @@ -31,7 +37,7 @@ export class ScheduleDashboardComponent implements OnInit{ //todo } - deleteSchedule(deletedSchedule: BasicScheduleEntityInfo) { + deleteSchedule(deletedSchedule: ScheduleInfo) { this.scheduleService.schedulesScheduleIDScheduleTypeDelete(deletedSchedule.scheduleID, 'BASIC').subscribe({ next: resp => { this.schedules = this.schedules.filter(schedule => schedule.scheduleID !== deletedSchedule.scheduleID); @@ -47,4 +53,8 @@ export class ScheduleDashboardComponent implements OnInit{ } }) } + + toBasicSchedule(schedule: ScheduleInfo) { + return schedule as BasicScheduleInfo + } } diff --git a/frontend/src/app/schedules/scheduler/scheduler.component.ts b/frontend/src/app/schedules/scheduler/scheduler.component.ts index a5aea85..6d5755f 100644 --- a/frontend/src/app/schedules/scheduler/scheduler.component.ts +++ b/frontend/src/app/schedules/scheduler/scheduler.component.ts @@ -1,7 +1,7 @@ import {Component, OnInit, ViewChild} from '@angular/core'; import {NavigationLink, NavigationLinkListComponent} from "../../navigation-link-list/navigation-link-list.component"; import { - BasicScheduleEntityInfo, ScheduleService, + BasicScheduleEntityInfo, BasicScheduleInfo, ScheduleService, TaskEntityInfo, TaskgroupEntityInfo, TaskgroupService, @@ -136,26 +136,33 @@ export class SchedulerComponent implements OnInit{ fetschSchedules() { this.scheduleService.schedulesGet().subscribe({ next: resp => { - resp.forEach(schedule => { - let color: EventColor = colors['red'] - if(schedule.scheduleID === this.scheduleID) { - color = colors['yellow'] + resp.forEach(abstractSchedule => { + if(abstractSchedule.scheduleType == 'BASIC') { + this.handleFetchedBasicSchedule(abstractSchedule as BasicScheduleInfo) } - if(schedule.scheduleType === 'BASIC') { - this.events.push({ - start: new Date(schedule.schedule.scheduleDate), - title: this.computeTaskPath(schedule.taskgroupPath, schedule.task), - color: color, - allDay: true, - }) - } }) this.refresh.next(); } }) } + handleFetchedBasicSchedule(schedule: BasicScheduleInfo) { + let color: EventColor = colors['red'] + if(schedule.scheduleID === this.scheduleID) { + color = colors['yellow'] + } + + if(schedule.scheduleType === 'BASIC') { + this.events.push({ + start: new Date(schedule.scheduleDate), + title: this.computeTaskPath(schedule.taskgroupPath, schedule.task), + color: color, + allDay: true, + }) + } + } + eventClicked({ event }: { event: CalendarEvent }): void { this.router.navigateByUrl("/taskgroups/" + this.taskgroupID.toString() + "/tasks/" + this.task!.taskID ) } diff --git a/openapi.yaml b/openapi.yaml index 7137880..f0e2f4b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1270,7 +1270,7 @@ paths: items: $ref: '#/components/schemas/ScheduleInfo' - /schedules/{taskID}/{scheduleType}: + /schedules/{taskID}: get: security: - API_TOKEN: [] @@ -1286,16 +1286,6 @@ paths: schema: type: number example: 1 - - name: scheduleType - in: path - description: internal id of task - required: true - schema: - type: string - enum: - - BASIC - - MODERATE - - ADVANCED responses: 200: description: operation successfull @@ -1304,7 +1294,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/BasicScheduleEntityInfo' + $ref: '#/components/schemas/ScheduleInfo' 403: description: No permission content: @@ -1319,7 +1309,6 @@ paths: schema: type: object $ref: "#/components/schemas/SimpleStatusResponse" - /schedules/{taskID}/basic: put: security: - API_TOKEN: [] @@ -1347,7 +1336,7 @@ paths: application/json: schema: type: object - $ref: '#/components/schemas/BasicScheduleEntityInfo' + $ref: '#/components/schemas/ScheduleInfo' 403: description: No permission content: @@ -2182,7 +2171,6 @@ components: - startTime - finishTime - activeMinutes - - schedule - task - taskgroupPath additionalProperties: false @@ -2211,10 +2199,6 @@ components: type: number description: number in minutes that the schedule was active example: 10 - schedule: - type: object - oneOf: - - $ref: '#/components/schemas/BasicScheduleFieldInfo' task: type: object $ref: '#/components/schemas/TaskShortInfo' @@ -2222,7 +2206,17 @@ components: type: array items: $ref: '#/components/schemas/TaskgroupEntityInfo' - + BasicScheduleInfo: + allOf: + - $ref: '#/components/schemas/ScheduleInfo' + - type: object + required: + - scheduleDate + additionalProperties: false + properties: + scheduleDate: + type: string + format: date TaskShortInfo: required: - taskID