issue-25 #27

Merged
sebastian merged 32 commits from issue-25 into issue-18 2023-10-28 19:33:06 +02:00
12 changed files with 159 additions and 101 deletions
Showing only changes of commit 314a11ee18 - Show all commits

View File

@ -5,9 +5,12 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Load worked minutes when reloading dashboard"> <list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Load worked minutes when reloading dashboard">
<change beforePath="$PROJECT_DIR$/../frontend/src/app/dashboard/dashboard.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/dashboard/dashboard.component.ts" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskSchedule/ScheduleStatus.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/dashboard/task-overview/task-overview.component.ts" 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/api/models/timemanager/taskSchedule/ActiveMinutesInformation.java" beforeDir="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> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -104,7 +107,7 @@
<workItem from="1698298897364" duration="4242000" /> <workItem from="1698298897364" duration="4242000" />
<workItem from="1698426430946" duration="665000" /> <workItem from="1698426430946" duration="665000" />
<workItem from="1698474363766" duration="3686000" /> <workItem from="1698474363766" duration="3686000" />
<workItem from="1698499063683" duration="7085000" /> <workItem from="1698499063683" duration="7685000" />
</task> </task>
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies"> <task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
<option name="closed" value="true" /> <option name="closed" value="true" />

View File

@ -2,9 +2,11 @@ package core.api.controller;
import core.api.models.auth.SimpleStatusResponse; import core.api.models.auth.SimpleStatusResponse;
import core.api.models.timemanager.taskSchedule.*; import core.api.models.timemanager.taskSchedule.*;
import core.entities.User;
import core.entities.timemanager.BasicTaskSchedule; import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.ScheduleType; import core.entities.timemanager.ScheduleType;
import core.entities.timemanager.Task; import core.entities.timemanager.Task;
import core.repositories.UserRepository;
import core.repositories.timemanager.BasicTaskScheduleRepository; import core.repositories.timemanager.BasicTaskScheduleRepository;
import core.services.*; import core.services.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -13,10 +15,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.ArrayList; import java.util.*;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@CrossOrigin(origins = "*", maxAge = 3600) @CrossOrigin(origins = "*", maxAge = 3600)
@RestController @RestController
@ -26,12 +25,15 @@ public class ScheduleController {
private final TaskService taskService; private final TaskService taskService;
private final TaskScheduleService taskScheduleService; private final TaskScheduleService taskScheduleService;
private final BasicTaskScheduleRepository basicTaskScheduleRepository; private final BasicTaskScheduleRepository basicTaskScheduleRepository;
private final UserRepository userRepository;
public ScheduleController(@Autowired TaskService taskService, @Autowired TaskScheduleService taskScheduleService, public ScheduleController(@Autowired TaskService taskService, @Autowired TaskScheduleService taskScheduleService,
BasicTaskScheduleRepository basicTaskScheduleRepository) { BasicTaskScheduleRepository basicTaskScheduleRepository,
UserRepository userRepository) {
this.taskService = taskService; this.taskService = taskService;
this.taskScheduleService = taskScheduleService; this.taskScheduleService = taskScheduleService;
this.basicTaskScheduleRepository = basicTaskScheduleRepository; this.basicTaskScheduleRepository = basicTaskScheduleRepository;
this.userRepository = userRepository;
} }
@GetMapping("/schedules/{taskID}/{scheduleType}") @GetMapping("/schedules/{taskID}/{scheduleType}")
@ -189,9 +191,14 @@ public class ScheduleController {
} }
} }
@GetMapping("/schedules/workedMinutesToday") @GetMapping("/schedules/status/today")
public ResponseEntity<?> getWorkedMinutesToday() { public ResponseEntity<?> getWorkedMinutesToday() {
ServiceResult<Integer> getWorkedMinutes = taskScheduleService.getWorkedMinutes(SecurityContextHolder.getContext().getAuthentication().getName()); Optional<User> user = userRepository.findByUsername(SecurityContextHolder.getContext().getAuthentication().getName());
return ResponseEntity.ok(new ActiveMinutesInformation(getWorkedMinutes.getResult())); if(user.isEmpty()) {
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
}
int workedMinutes = taskScheduleService.getWorkedMinutes(user.get());
return ResponseEntity.ok(new ScheduleStatus(workedMinutes, taskScheduleService.isAnyScheduleMissed(user.get())));
} }
} }

View File

@ -1,18 +0,0 @@
package core.api.models.timemanager.taskSchedule;
public class ActiveMinutesInformation {
public int activeMinutes;
public ActiveMinutesInformation(int activeMinutes) {
this.activeMinutes = activeMinutes;
}
public int getActiveMinutes() {
return activeMinutes;
}
public void setActiveMinutes(int activeMinutes) {
this.activeMinutes = activeMinutes;
}
}

View File

@ -0,0 +1,28 @@
package core.api.models.timemanager.taskSchedule;
public class ScheduleStatus {
private int activeMinutes;
private boolean missedSchedules;
public ScheduleStatus(int activeMinutes, boolean missedSchedules) {
this.activeMinutes = activeMinutes;
this.missedSchedules = missedSchedules;
}
public int getActiveMinutes() {
return activeMinutes;
}
public void setActiveMinutes(int activeMinutes) {
this.activeMinutes = activeMinutes;
}
public boolean isMissedSchedules() {
return missedSchedules;
}
public void setMissedSchedules(boolean missedSchedules) {
this.missedSchedules = missedSchedules;
}
}

View File

@ -34,4 +34,6 @@ public interface BasicTaskScheduleRepository extends CrudRepository<BasicTaskSch
@Query(value = "SELECT bts FROM BasicTaskSchedule bts WHERE bts.task.taskgroup.user.username = ?1 AND bts.startTime is not null and bts.finishedTime is null") @Query(value = "SELECT bts FROM BasicTaskSchedule bts WHERE bts.task.taskgroup.user.username = ?1 AND bts.startTime is not null and bts.finishedTime is null")
Optional<BasicTaskSchedule> findActiveTaskSchedule(String username); Optional<BasicTaskSchedule> findActiveTaskSchedule(String username);
List<BasicTaskSchedule> findAllByStartTimeIsNull();
} }

View File

@ -135,19 +135,25 @@ public class TaskScheduleService {
return new ServiceResult<>((int) activeTime); return new ServiceResult<>((int) activeTime);
} }
public ServiceResult<Integer> getWorkedMinutes(String username) { public int getWorkedMinutes(User user) {
Optional<User> user = userRepository.findByUsername(username); List<BasicTaskSchedule> basicTaskSchedules = basicTaskScheduleRepository.findAllByUser(user);
if(user.isEmpty()) {
return new ServiceResult<>(ServiceExitCode.MISSING_ENTITY);
}
List<BasicTaskSchedule> basicTaskSchedules = basicTaskScheduleRepository.findAllByUser(user.get());
long workedMinutes = 0; long workedMinutes = 0;
for(BasicTaskSchedule basicTaskSchedule : basicTaskSchedules) { for(BasicTaskSchedule basicTaskSchedule : basicTaskSchedules) {
if(basicTaskSchedule.getFinishedTime() != null && basicTaskSchedule.getFinishedTime().toLocalDate().isEqual(LocalDate.now())) { if(basicTaskSchedule.getFinishedTime() != null && basicTaskSchedule.getFinishedTime().toLocalDate().isEqual(LocalDate.now())) {
workedMinutes += Duration.between(basicTaskSchedule.getStartTime(), basicTaskSchedule.getFinishedTime()).toMinutes(); workedMinutes += Duration.between(basicTaskSchedule.getStartTime(), basicTaskSchedule.getFinishedTime()).toMinutes();
} }
} }
return new ServiceResult<>((int) workedMinutes); return (int) workedMinutes;
}
public boolean isAnyScheduleMissed(User user) {
List<BasicTaskSchedule> unstartedSchedules = basicTaskScheduleRepository.findAllByStartTimeIsNull();
LocalDate dateReference = LocalDate.now();
for(BasicTaskSchedule schedule : unstartedSchedules) {
if(schedule.getScheduleDate().isBefore(dateReference)) {
return true;
}
}
return false;
} }
} }

View File

@ -14,7 +14,6 @@ encoder.ts
git_push.sh git_push.sh
index.ts index.ts
model/accountDeleteRequest.ts model/accountDeleteRequest.ts
model/activeMinutesInformation.ts
model/basicScheduleEntityInfo.ts model/basicScheduleEntityInfo.ts
model/basicScheduleFieldInfo.ts model/basicScheduleFieldInfo.ts
model/eMailChangeRequest.ts model/eMailChangeRequest.ts
@ -32,6 +31,7 @@ model/propertyUpdateRequest.ts
model/recursiveTaskgroupInfo.ts model/recursiveTaskgroupInfo.ts
model/scheduleActivateInfo.ts model/scheduleActivateInfo.ts
model/scheduleInfo.ts model/scheduleInfo.ts
model/scheduleStatus.ts
model/signUpRequest.ts model/signUpRequest.ts
model/simpleStatusResponse.ts model/simpleStatusResponse.ts
model/taskEntityInfo.ts model/taskEntityInfo.ts

View File

@ -18,11 +18,11 @@ import { HttpClient, HttpHeaders, HttpParams,
import { CustomHttpParameterCodec } from '../encoder'; import { CustomHttpParameterCodec } from '../encoder';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { ActiveMinutesInformation } from '../model/models';
import { BasicScheduleEntityInfo } from '../model/models'; import { BasicScheduleEntityInfo } from '../model/models';
import { BasicScheduleFieldInfo } from '../model/models'; import { BasicScheduleFieldInfo } from '../model/models';
import { ScheduleActivateInfo } from '../model/models'; import { ScheduleActivateInfo } from '../model/models';
import { ScheduleInfo } from '../model/models'; import { ScheduleInfo } from '../model/models';
import { ScheduleStatus } from '../model/models';
import { SimpleStatusResponse } from '../model/models'; import { SimpleStatusResponse } from '../model/models';
import { TaskScheduleStopResponse } from '../model/models'; import { TaskScheduleStopResponse } from '../model/models';
@ -456,6 +456,61 @@ export class ScheduleService {
); );
} }
/**
* get number of active minutes
* get number of worked minutes 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 schedulesStatusTodayGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<ScheduleStatus>;
public schedulesStatusTodayGet(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<ScheduleStatus>>;
public schedulesStatusTodayGet(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<ScheduleStatus>>;
public schedulesStatusTodayGet(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<ScheduleStatus>(`${this.configuration.basePath}/schedules/status/today`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
/** /**
* creates basic schedule for task * creates basic schedule for task
* creates a basic schedule for a task * creates a basic schedule for a task
@ -708,59 +763,4 @@ export class ScheduleService {
); );
} }
/**
* get number of active minutes
* get number of worked minutes 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 schedulesWorkedMinutesTodayGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<ActiveMinutesInformation>;
public schedulesWorkedMinutesTodayGet(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<ActiveMinutesInformation>>;
public schedulesWorkedMinutesTodayGet(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<ActiveMinutesInformation>>;
public schedulesWorkedMinutesTodayGet(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<ActiveMinutesInformation>(`${this.configuration.basePath}/schedules/workedMinutesToday`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
} }

View File

@ -1,5 +1,4 @@
export * from './accountDeleteRequest'; export * from './accountDeleteRequest';
export * from './activeMinutesInformation';
export * from './basicScheduleEntityInfo'; export * from './basicScheduleEntityInfo';
export * from './basicScheduleFieldInfo'; export * from './basicScheduleFieldInfo';
export * from './eMailChangeRequest'; export * from './eMailChangeRequest';
@ -16,6 +15,7 @@ export * from './propertyUpdateRequest';
export * from './recursiveTaskgroupInfo'; export * from './recursiveTaskgroupInfo';
export * from './scheduleActivateInfo'; export * from './scheduleActivateInfo';
export * from './scheduleInfo'; export * from './scheduleInfo';
export * from './scheduleStatus';
export * from './signUpRequest'; export * from './signUpRequest';
export * from './simpleStatusResponse'; export * from './simpleStatusResponse';
export * from './taskEntityInfo'; export * from './taskEntityInfo';

View File

@ -0,0 +1,24 @@
/**
* 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 ScheduleStatus {
/**
* number of minutes it was worked today
*/
activeMinutes: number;
/**
* states whether a schedule was missed or not
*/
missedSchedules: boolean;
}

View File

@ -30,9 +30,10 @@ export class DashboardComponent implements OnInit{
} }
}) })
this.scheduleService.schedulesWorkedMinutesTodayGet().subscribe({ this.scheduleService.schedulesStatusTodayGet().subscribe({
next: resp => { next: resp => {
this.workedMinutesToday = resp.activeMinutes; this.workedMinutesToday = resp.activeMinutes;
this.missedSchedules = resp.missedSchedules;
} }
}) })
} }

View File

@ -1597,7 +1597,7 @@ paths:
schema: schema:
type: object type: object
$ref: "#/components/schemas/SimpleStatusResponse" $ref: "#/components/schemas/SimpleStatusResponse"
/schedules/workedMinutesToday: /schedules/status/today:
get: get:
security: security:
- API_TOKEN: [] - API_TOKEN: []
@ -1611,7 +1611,7 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ActiveMinutesInformation' $ref: '#/components/schemas/ScheduleStatus'
404: 404:
description: User not found description: User not found
content: content:
@ -2127,12 +2127,17 @@ components:
type: number type: number
description: number in minutes that was already worked on this task description: number in minutes that was already worked on this task
example: 10 example: 10
ActiveMinutesInformation: ScheduleStatus:
required: required:
- activeMinutes - activeMinutes
- missedSchedules
additionalProperties: false additionalProperties: false
properties: properties:
activeMinutes: activeMinutes:
type: number type: number
example: 1 example: 1
description: number of minutes it was worked today description: number of minutes it was worked today
missedSchedules:
type: boolean
description: states whether a schedule was missed or not
example: true