Get Working Status of Today Endpoint
All checks were successful
Java CI with Maven / build (push) Successful in 55s

This commit is contained in:
Sebastian Böckelmann 2023-11-11 19:09:24 +01:00
parent f076a5907c
commit d7850a9aa7
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,42 @@
package core.api.controller;
import core.api.models.timemanager.history.WorkingStatus;
import core.entities.timemanager.AbstractSchedule;
import core.services.TaskScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api")
public class StatisticController {
@Autowired private TaskScheduleService taskScheduleService;
@GetMapping("/history/todayStatus")
public ResponseEntity<?> loadStatusOfToday() {
boolean missedSchedules = !taskScheduleService.getAllMissedSchedulesOfUser(SecurityContextHolder.getContext().getAuthentication().getName()).isEmpty();
List<AbstractSchedule> executedSchedules = taskScheduleService.getActiveSchedulesOfToday(SecurityContextHolder.getContext().getAuthentication().getName());
int activeTime = 0;
for(AbstractSchedule schedule : executedSchedules) {
if(schedule.getStartTime().toLocalDate().isBefore(LocalDate.now())) {
activeTime += (int) Duration.between(LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT), schedule.getStopTime()).toMinutes();
} else {
activeTime += (int) Duration.between(schedule.getStartTime(), schedule.getStopTime()).toMinutes();
}
}
return ResponseEntity.ok(new WorkingStatus(missedSchedules, activeTime));
}
}

View File

@ -0,0 +1,28 @@
package core.api.models.timemanager.history;
public class WorkingStatus {
private boolean missedSchedules;
private int activeTime;
public WorkingStatus(boolean missedSchedules, int activeTime) {
this.missedSchedules = missedSchedules;
this.activeTime = activeTime;
}
public boolean isMissedSchedules() {
return missedSchedules;
}
public void setMissedSchedules(boolean missedSchedules) {
this.missedSchedules = missedSchedules;
}
public int getActiveTime() {
return activeTime;
}
public void setActiveTime(int activeTime) {
this.activeTime = activeTime;
}
}

View File

@ -147,4 +147,14 @@ public class TaskScheduleService {
} }
return missedSchedules; return missedSchedules;
} }
public List<AbstractSchedule> getActiveSchedulesOfToday(String username) {
List<AbstractSchedule> activatedSchedules = new ArrayList<>();
for(AbstractSchedule schedule : getAllSchedulesOfUser(username)) {
if(schedule.getStopTime() != null && schedule.getStopTime().toLocalDate().isEqual(LocalDate.now())) {
activatedSchedules.add(schedule);
}
}
return activatedSchedules;
}
} }