Просмотр исходного кода

Mogelijkheid tot opruimen inactieve teams

Harry de Boer 5 лет назад
Родитель
Сommit
4edff50b92

+ 5 - 0
src/main/java/puzzeltocht/controller/DashboardController.java

@@ -33,4 +33,9 @@ public class DashboardController {
         return teams;
         return teams;
     }
     }
 
 
+    @GetMapping(path = "cleanup")
+    public void cleanup() {
+        eventService.cleanup();
+    }
+
 }
 }

+ 11 - 0
src/main/java/puzzeltocht/domain/Event.java

@@ -1,5 +1,6 @@
 package puzzeltocht.domain;
 package puzzeltocht.domain;
 
 
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.*;
 
 
 public class Event {
 public class Event {
@@ -44,4 +45,14 @@ public class Event {
         return route.nextMission(m);
         return route.nextMission(m);
     }
     }
 
 
+    public synchronized void cleanup() {
+        List<UUID> keys = new ArrayList<>(teams.keySet());
+        for (UUID key : keys) {
+            Team t = teams.get(key);
+            if (t.getLastActive().isBefore(LocalDateTime.now().minusMinutes(15))) {
+                teams.remove(key);
+            }
+        }
+    }
+
 }
 }

+ 7 - 1
src/main/java/puzzeltocht/domain/Team.java

@@ -1,5 +1,6 @@
 package puzzeltocht.domain;
 package puzzeltocht.domain;
 
 
+import java.time.LocalDateTime;
 import java.util.UUID;
 import java.util.UUID;
 
 
 public class Team {
 public class Team {
@@ -7,6 +8,7 @@ public class Team {
     private final String name;
     private final String name;
     private Mission currentMission;
     private Mission currentMission;
     private Location currentLocation;
     private Location currentLocation;
+    private LocalDateTime lastActive = LocalDateTime.now();
 //    private final List<Location> locationHistory = new ArrayList<>();
 //    private final List<Location> locationHistory = new ArrayList<>();
 
 
     public Team(String name) {
     public Team(String name) {
@@ -38,8 +40,8 @@ public class Team {
         if (l == null) {
         if (l == null) {
             return;
             return;
         }
         }
+        this.lastActive = LocalDateTime.now();
         this.currentLocation = l;
         this.currentLocation = l;
-//        updateHistory(l);
     }
     }
 
 
 //    public List<Location> getLocationHistory() {
 //    public List<Location> getLocationHistory() {
@@ -57,4 +59,8 @@ public class Team {
 //        }
 //        }
 //    }
 //    }
 
 
+    public LocalDateTime getLastActive() {
+        return lastActive;
+    }
+
 }
 }

+ 6 - 0
src/main/java/puzzeltocht/service/EventService.java

@@ -45,4 +45,10 @@ public class EventService {
     public Team createTeam(Event e, TeamCreateDto team) {
     public Team createTeam(Event e, TeamCreateDto team) {
         return teamService.create(e, team);
         return teamService.create(e, team);
     }
     }
+
+    public void cleanup() {
+        for (Event event : currentEvents()) {
+            event.cleanup();
+        }
+    }
 }
 }