Erweiterungen

This commit is contained in:
2026-02-10 15:08:00 +01:00
parent edb39549bc
commit 49df32fa40
4 changed files with 1192 additions and 949 deletions

Binary file not shown.

View File

@@ -0,0 +1,59 @@
package de.assecutor.votianlt.controller;
import de.assecutor.votianlt.model.LocationPosition;
import de.assecutor.votianlt.service.LocationService;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;
/**
* REST-Controller für Location-bezogene API-Endpunkte.
*/
@RestController
@RequestMapping("/api/location")
@RequiredArgsConstructor
@Slf4j
public class LocationApiController {
private final LocationService locationService;
/**
* Gibt die aktuelle Position eines App-Nutzers zurück.
*
* @param appUserId die ID des App-Nutzers
* @return die aktuelle Position oder 404 wenn keine vorhanden
*/
@GetMapping("/{appUserId}")
public ResponseEntity<LocationResponse> getCurrentPosition(@PathVariable String appUserId) {
LocationPosition position = locationService.getLatestPosition(appUserId);
if (position == null || position.getLatitude() == null || position.getLongitude() == null) {
return ResponseEntity.notFound().build();
}
LocationResponse response = new LocationResponse();
response.setLatitude(position.getLatitude());
response.setLongitude(position.getLongitude());
response.setAccuracy(position.getAccuracy());
response.setSpeed(position.getSpeed());
response.setTimestamp(position.getTimestamp());
return ResponseEntity.ok(response);
}
@Data
public static class LocationResponse {
private Double latitude;
private Double longitude;
private Double accuracy;
private Double speed;
private Instant timestamp;
}
}

View File

@@ -74,7 +74,7 @@ public class LocationPosition {
* Timestamp when the position was received by the server * Timestamp when the position was received by the server
*/ */
@Field("received_at") @Field("received_at")
@Indexed(expireAfterSeconds = 3600) // TTL index: auto-delete after 60 minutes @Indexed(expireAfter = "3600s") // TTL index: auto-delete after 60 minutes
private Instant receivedAt; private Instant receivedAt;
public LocationPosition(String appUserId, Double latitude, Double longitude, Double accuracy, public LocationPosition(String appUserId, Double latitude, Double longitude, Double accuracy,