Skip to content

Commit

Permalink
Fix location query for stores
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed Jul 21, 2015
1 parent 7c642eb commit 4eaa0de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions rest-microservices-customers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<artifactId>spring-hateoas</artifactId>
</dependency>


<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@
public class CustomerResourceProcessor implements ResourceProcessor<Resource<Customer>> {

private static final String X_FORWARDED_HOST = "X-Forwarded-Host";
private final StoreIntegration storeIntegration;
private final Provider<HttpServletRequest> request;
private final StoreIntegration storeIntegration;
private final Provider<HttpServletRequest> request;

@Override
public Resource<Customer> process(Resource<Customer> resource) {

Customer customer = resource.getContent();
Location location = customer.getAddress().getLocation();

Map<String, Object> parameters = new HashMap<>();
parameters.put("location", String.format("%s,%s", location.getLatitude(), location.getLongitude()));
parameters.put("distance", "50");
String host = request.get().getHeader(X_FORWARDED_HOST);
Link link = storeIntegration.getStoresByLocationLink(parameters, host);
if (link != null) {
resource.add(link.withRel("stores-nearby"));
}
Map<String, Object> parameters = new HashMap<>();
parameters.put("location", String.format("%s,%s", location.getLatitude(), location.getLongitude()));
parameters.put("distance", "50km");
String host = this.request.get().getHeader(X_FORWARDED_HOST);
Link link = this.storeIntegration.getStoresByLocationLink(parameters, host);
if (link != null) {
resource.add(link.withRel("stores-nearby"));
}

return resource;
}
Expand Down

0 comments on commit 4eaa0de

Please sign in to comment.