diff --git a/src/main/java/org/ntlab/nemophila/models/shops/ShopManager.java b/src/main/java/org/ntlab/nemophila/models/shops/ShopManager.java index bdfd27d..3ac567e 100644 --- a/src/main/java/org/ntlab/nemophila/models/shops/ShopManager.java +++ b/src/main/java/org/ntlab/nemophila/models/shops/ShopManager.java @@ -1,6 +1,7 @@ package org.ntlab.nemophila.models.shops; import org.ntlab.nemophila.models.accounts.Post; +import javax.ws.rs.FormParam; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -29,8 +30,24 @@ } //お店の情報を全て返す - public Collection getShops() { - return shopsMap.values(); + public Collection getShops(double upperRightLongitude, + double upperRightLatitude, + double lowerLeftlongitude, + double lowerLeftlatitude) { + Collection response = new ArrayList<>(); + + for (Shop shop: shopsMap.values()) { + double longitude = shop.getLongitude(); + double latitude = shop.getLatitude(); + + if (longitude < upperRightLongitude && longitude > lowerLeftlongitude) { + if (latitude < upperRightLatitude && latitude > lowerLeftlatitude) { + response.add(shop); + } + } + } + + return response; } //sidからその店の投稿を取得 @@ -64,4 +81,5 @@ public void removeShop(String id) { shopsMap.remove(id); } + } \ No newline at end of file diff --git a/src/main/java/org/ntlab/nemophila/resources/shops/ShopsRest.java b/src/main/java/org/ntlab/nemophila/resources/shops/ShopsRest.java index a8824b2..16cfecc 100644 --- a/src/main/java/org/ntlab/nemophila/resources/shops/ShopsRest.java +++ b/src/main/java/org/ntlab/nemophila/resources/shops/ShopsRest.java @@ -13,9 +13,17 @@ public class ShopsRest { @GET @Produces(MediaType.APPLICATION_JSON) - public Collection getShops() { + public Collection getShops(@QueryParam("monitor_upper_right_longitude") double upperRightLongitude, + @QueryParam("monitor_upper_right_latitude") double upperRightLatitude, + @QueryParam("monitor_lower_left_longitude") double lowerLeftLongitude, + @QueryParam("monitor_lower_left_latitude") double lowerLeftLatitude) { + System.out.println(upperRightLatitude); + System.out.println(upperRightLongitude); + System.out.println(lowerLeftLatitude); + System.out.println(lowerLeftLongitude); ShopManager shopManager = ShopManager.getInstance(); - return shopManager.getShops(); + Collection response = shopManager.getShops(upperRightLongitude, upperRightLatitude, lowerLeftLongitude, lowerLeftLatitude); + return response; } @POST