add a nominatim container to docker setup that is available via GeocodingController to reverse geocode lat / lon to address
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package SuMoC.backend.geocoding;
|
||||
|
||||
import SuMoC.backend.nominatim.NominatimClient;
|
||||
import SuMoC.backend.nominatim.ReverseResponse;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/geocoding")
|
||||
public class GeocodingController {
|
||||
|
||||
private final NominatimClient nominatimClient;
|
||||
|
||||
public GeocodingController(NominatimClient nominatimClient) {
|
||||
this.nominatimClient = nominatimClient;
|
||||
}
|
||||
|
||||
@GetMapping("/reverse")
|
||||
@Operation(description = "Returns the OSM location at the given lat / lon including the address.")
|
||||
public Mono<ReverseResponse> reverse(@RequestParam double lat, @RequestParam double lon) {
|
||||
return nominatimClient.reverse(lat, lon);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package SuMoC.backend.nominatim;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Service
|
||||
public class NominatimClient {
|
||||
|
||||
private final WebClient nominatimClient;
|
||||
|
||||
public NominatimClient(@Qualifier("nominatimWebClient") WebClient nominatimClient) {
|
||||
this.nominatimClient = nominatimClient;
|
||||
}
|
||||
|
||||
public Mono<ReverseResponse> reverse(double lat, double lon) {
|
||||
return nominatimClient.get()
|
||||
.uri(uriBuilder -> uriBuilder.path("/reverse")
|
||||
.queryParam("lat", lat)
|
||||
.queryParam("lon", lon)
|
||||
.queryParam("format", "jsonv2")
|
||||
.build())
|
||||
.retrieve()
|
||||
.bodyToMono(ReverseResponse.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package SuMoC.backend.nominatim;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(NominatimProperties.class)
|
||||
public class NominatimClientConfig {
|
||||
|
||||
@Bean
|
||||
public WebClient nominatimWebClient(NominatimProperties properties) {
|
||||
return WebClient.builder()
|
||||
.baseUrl(properties.baseUrl())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package SuMoC.backend.nominatim;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "nominatim")
|
||||
public record NominatimProperties(
|
||||
String baseUrl
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package SuMoC.backend.nominatim;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public record ReverseResponse(
|
||||
@JsonProperty("place_id") long placeId,
|
||||
String licence,
|
||||
@JsonProperty("osm_type") String osmType,
|
||||
@JsonProperty("osm_id") long osmId,
|
||||
String lat,
|
||||
String lon,
|
||||
@JsonProperty("display_name") String displayName,
|
||||
@JsonProperty("address") Map<String, String> address
|
||||
) {
|
||||
}
|
||||
@@ -96,6 +96,7 @@ public class SecurityConfiguration {
|
||||
auth.requestMatchers("/user/**").hasAnyRole("ADMIN", "USER");
|
||||
auth.requestMatchers("/friendship/**").hasAnyRole("ADMIN", "USER");
|
||||
auth.requestMatchers("/trip/**").hasAnyRole("USER", "ADMIN");
|
||||
auth.requestMatchers("/geocoding/**").hasAnyRole("USER", "ADMIN");
|
||||
//auth.requestMatchers("/error").permitAll();
|
||||
auth.anyRequest().authenticated();
|
||||
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
package SuMoC.backend.trip.dtos;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DTO representing a trip already persisted in the database.
|
||||
*/
|
||||
// TODO refactor to UploadedTripDTO for clarity against RouteDTO
|
||||
@Setter
|
||||
@Getter
|
||||
@Schema(description = "Represents a trip uploaded to the backend by a user that is already stored in the DB.")
|
||||
public class TripDTO {
|
||||
private long tripId;
|
||||
private int userId;
|
||||
@@ -35,4 +29,67 @@ public class TripDTO {
|
||||
this.tripSegments = tripSegmentDTOS;
|
||||
}
|
||||
|
||||
public long getTripId() {
|
||||
return tripId;
|
||||
}
|
||||
|
||||
public void setTripId(long tripId) {
|
||||
this.tripId = tripId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getStartPlace() {
|
||||
return startPlace;
|
||||
}
|
||||
|
||||
public void setStartPlace(String startPlace) {
|
||||
this.startPlace = startPlace;
|
||||
}
|
||||
|
||||
public String getEndPlace() {
|
||||
return endPlace;
|
||||
}
|
||||
|
||||
public void setEndPlace(String endPlace) {
|
||||
this.endPlace = endPlace;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(LocalDateTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(LocalDateTime endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public float getMobilityScore() {
|
||||
return mobilityScore;
|
||||
}
|
||||
|
||||
public void setMobilityScore(float mobilityScore) {
|
||||
this.mobilityScore = mobilityScore;
|
||||
}
|
||||
|
||||
public List<TripSegmentDTO> getTripSegments() {
|
||||
return tripSegments;
|
||||
}
|
||||
|
||||
public void setTripSegments(List<TripSegmentDTO> tripSegments) {
|
||||
this.tripSegments = tripSegments;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user