Erweiterungen
This commit is contained in:
Binary file not shown.
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class LocationPosition {
|
||||
* Timestamp when the position was received by the server
|
||||
*/
|
||||
@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;
|
||||
|
||||
public LocationPosition(String appUserId, Double latitude, Double longitude, Double accuracy,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user