Skip to content

Commit

Permalink
Merge pull request #40 from SAKPaaS/feature/location_daten-modell_anp…
Browse files Browse the repository at this point in the history
…assen

added type to location data-model
  • Loading branch information
MrKraboom authored Mar 24, 2020
2 parents 126a1a0 + 07cb331 commit 04c1b99
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public List<LocationSearchOSMResultDto> getLocationByCoordinates(Double latitude
public List<LocationSearchOSMResultDto> getLocationsForCountry(String countryCode) {
final String url = "https://overpass-api.de/api/interpreter?data=[out:json][timeout:2500];area(3600051477)->." +
"searchArea;(node[\"shop\"=\"supermarket\"](area.searchArea);way[\"shop\"=\"supermarket\"](area.searchArea););out center;";

RestTemplate restTemplate = new RestTemplate();
ResponseEntity<ApiResultDto> response = restTemplate.getForEntity(url, ApiResultDto.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ public String getCountry() {
return tags.getCountry();
}

public String getType() {
return tags.getType();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.Getter;

@Getter
@JsonPropertyOrder({"id", "name", "occupancy", "latitude", "longitude"})
@JsonPropertyOrder({"id", "name", "occupancy", "lat", "lon", "street", "housenumber", "postcode", "city", "country", "type"})
public class LocationSearchOutputDto {
private long id;
private String name;
Expand All @@ -18,6 +18,7 @@ public class LocationSearchOutputDto {
private String postcode;
private String city;
private String country;
private String type;

@JsonCreator
public LocationSearchOutputDto(@JsonProperty("id") long id,
Expand All @@ -29,7 +30,8 @@ public LocationSearchOutputDto(@JsonProperty("id") long id,
@JsonProperty("housenumber") String housenumber,
@JsonProperty("postcode") String postcode,
@JsonProperty("city") String city,
@JsonProperty("country") String country) {
@JsonProperty("country") String country,
@JsonProperty("type") String type) {
this.id = id;
if (name == null) {
this.name = "Supermarkt";
Expand All @@ -44,6 +46,7 @@ public LocationSearchOutputDto(@JsonProperty("id") long id,
this.postcode = postcode;
this.city = city;
this.country = country;
this.type = type;
}

}
6 changes: 4 additions & 2 deletions src/main/java/de/sakpaas/backend/dto/TagsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Getter;

@JsonPropertyOrder({"name", "addr:street", "addr:place", "addr:housenumber", "addr:postcode", "addr:city", "addr:country"})
@JsonPropertyOrder({"name", "addr:street", "addr:place", "addr:housenumber", "addr:postcode", "addr:city", "addr:country", "shop"})
@Getter
public class TagsDto {
private String name;
Expand All @@ -14,18 +14,20 @@ public class TagsDto {
private String postcode;
private String city;
private String country;
private String type;

@JsonCreator
public TagsDto(@JsonProperty("name") String name, @JsonProperty("addr:street") String street,
@JsonProperty("addr:housenumber") String housenumber, @JsonProperty("addr:postcode") String postcode,
@JsonProperty("addr:city") String city, @JsonProperty("addr:country") String country,
@JsonProperty("addr:place") String place) {
@JsonProperty("addr:place") String place, @JsonProperty("shop") String type) {
this.name = name;
this.street = street != null ? street : place;
this.housenumber = housenumber;
this.postcode = postcode;
this.city = city;
this.country = country;
this.type = type;

}
}
3 changes: 3 additions & 0 deletions src/main/java/de/sakpaas/backend/model/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ public class Location {

@Column(name = "COUNTRY")
private String country;

@Column(name = "TYPE")
private String type;
}
6 changes: 3 additions & 3 deletions src/main/java/de/sakpaas/backend/service/LocationMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LocationSearchOutputDto mapToOutputDto(Location location) {
return new LocationSearchOutputDto(location.getId(), location.getName(),
occupancyService.getAverageOccupancy(location), location.getLatitude(), location.getLongitude(),
location.getStreet(),
location.getHousenumber(), location.getPostcode(), location.getCity(), location.getCountry());
location.getHousenumber(), location.getPostcode(), location.getCity(), location.getCountry(), location.getType());
}

public LocationSearchOutputDto mapToOutputDto(LocationSearchOSMResultDto apiResult) {
Expand All @@ -35,7 +35,7 @@ public LocationSearchOutputDto mapToOutputDto(LocationSearchOSMResultDto apiResu

return new LocationSearchOutputDto(apiResult.getId(), apiResult.getName(), null, apiResult.getLat(),
apiResult.getLon(), apiResult.getStreet(), apiResult.getHousenumber(), apiResult.getPostcode(),
apiResult.getCity(), apiResult.getCountry());
apiResult.getCity(), apiResult.getCountry(), apiResult.getType());
}

public Location mapToLocation(LocationSearchOSMResultDto apiResult) {
Expand All @@ -47,6 +47,6 @@ public Location mapToLocation(LocationSearchOSMResultDto apiResult) {
.orElseGet(() -> new Location(apiResult.getId(),
apiResult.getName() != null ? apiResult.getName() : "Supermarkt", apiResult.getLat(),
apiResult.getLon(), apiResult.getStreet(), apiResult.getHousenumber(),
apiResult.getPostcode(), apiResult.getCity(), apiResult.getCountry()));
apiResult.getPostcode(), apiResult.getCity(), apiResult.getCountry(), apiResult.getType()));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spring:
datasource:
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: zuschwer
password: SAKPaaS
app:
presence:
duration: 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
import de.sakpaas.backend.model.Location;
import de.sakpaas.backend.model.Occupancy;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.ComponentScan;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

@SpringBootTest
@ComponentScan
class OccupancyServiceTest {

@Test
void getAverageOccupancy() {
Location location = new Location(1829487L, "LIDL", 42.0, 8.0, null, null, null, null, null);
Location location = new Location(1829487L, "LIDL", 42.0, 8.0, null, null, null, null, null, null);
ZonedDateTime time = ZonedDateTime.now();

List<Occupancy> occupancyList = new ArrayList<>();
Expand Down

0 comments on commit 04c1b99

Please sign in to comment.