Implement active Location Sharing Stopped/Ended state with red dot pin

This commit is contained in:
Shanmuga Krishnan S M
2026-07-27 13:51:41 +05:30
parent def3a7c9ce
commit a3e1f1e826
4 changed files with 42 additions and 9 deletions

View File

@@ -37,6 +37,20 @@ public class BusLocationController {
return ResponseEntity.ok(Map.of("status", "success", "message", "Location updated successfully"));
}
@PostMapping("/{routeNumber}/stop")
public ResponseEntity<Map<String, String>> stopLocation(
@PathVariable String routeNumber,
@RequestBody Map<String, String> body) {
String pin = body != null ? body.get("pin") : null;
if (!REQUIRED_PIN.equals(pin)) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(Map.of("error", "Invalid driver PIN"));
}
busLocationService.stopLocation(routeNumber);
return ResponseEntity.ok(Map.of("status", "success", "message", "Location sharing stopped"));
}
@GetMapping
public ResponseEntity<List<BusLocation>> getActiveLocations() {
return ResponseEntity.ok(busLocationService.getActiveLocations());

View File

@@ -13,4 +13,5 @@ public class BusLocation {
private Double latitude;
private Double longitude;
private Instant lastUpdated;
private boolean stopped = false;
}

View File

@@ -19,10 +19,19 @@ public class BusLocationService {
routeNumber,
latitude,
longitude,
Instant.now()
Instant.now(),
false
));
}
public void stopLocation(String routeNumber) {
BusLocation loc = locationCache.get(routeNumber);
if (loc != null) {
loc.setStopped(true);
loc.setLastUpdated(Instant.now());
}
}
public BusLocation getLocation(String routeNumber) {
BusLocation loc = locationCache.get(routeNumber);
if (loc != null) {