fix-issue-81 #88

Merged
sebastian merged 3 commits from fix-issue-81 into master 2023-12-20 10:54:27 +01:00
3 changed files with 17 additions and 5 deletions
Showing only changes of commit 1337bbb6ab - Show all commits

View File

@ -3,10 +3,7 @@ package core.api.controller;
import core.api.models.auth.SimpleStatusResponse;
import core.api.models.timemanager.taskSchedule.*;
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleFieldInfo;
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleInfo;
import core.api.models.timemanager.taskSchedule.scheduleInfos.BasicScheduleFieldInfo;
import core.api.models.timemanager.taskSchedule.scheduleInfos.ScheduleFieldInfo;
import core.api.models.timemanager.taskSchedule.scheduleInfos.*;
import core.entities.timemanager.AbstractSchedule;
import core.entities.timemanager.AdvancedTaskSchedule;
import core.entities.timemanager.BasicTaskSchedule;
@ -50,7 +47,14 @@ public class ScheduleController {
}
List<AbstractSchedule> taskSchedules = permissionResult.getResult().getBasicTaskSchedules();
return ResponseEntity.ok(taskSchedules.stream().map(AbstractSchedule::toScheduleInfo).toList());
List<ScheduleInfo> scheduleInfos = new ArrayList<>();
for(AbstractSchedule schedule : taskSchedules) {
//Filter completed schedules out
if(!schedule.isCompleted()) {
scheduleInfos.add(schedule.toScheduleInfo());
}
}
return ResponseEntity.ok(scheduleInfos);
}
@PutMapping("/schedules/{taskID}/basic")

View File

@ -207,4 +207,8 @@ public class Task {
}
return false;
}
public void increaseWorkTime(long minutes) {
this.workTime += (int) minutes;
}
}

View File

@ -14,6 +14,7 @@ import core.repositories.timemanager.TaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
@ -164,6 +165,9 @@ public class TaskScheduleService {
if(schedule.getStartTime() != null && schedule.getStopTime() == null) {
schedule.setStopTime(LocalDateTime.now());
scheduleRepository.save(schedule);
Duration scheduleDuration = Duration.between(schedule.getStartTime(), schedule.getStopTime());
schedule.getTask().increaseWorkTime(scheduleDuration.toMinutes());
taskRepository.save(schedule.getTask());
}
if(finish) {