Skip to content

Commit d5fe5cf

Browse files
author
Sandra Thieme
committed
Move new address api to AddressApiController
1 parent db4d39b commit d5fe5cf

File tree

4 files changed

+35
-118
lines changed

4 files changed

+35
-118
lines changed

src/main/java/net/contargo/iris/address/api/AddressApiController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
4141

42+
import static org.springframework.web.bind.annotation.RequestMethod.GET;
43+
4244
import static java.util.Collections.singletonList;
4345

4446

@@ -49,12 +51,14 @@
4951
* @author Aljona Murygina - murygina@synyx.de
5052
* @author Arnold Franke - franke@synyx.de
5153
* @author Tobias Schneider - schneider@synyx.de
54+
* @author Sandra Thieme - thieme@synyx.de
55+
* @author Ben Antony - antony@synyx.de
5256
*/
5357
@Controller
5458
@Api(description = "API for querying addresses.", value = "")
5559
public class AddressApiController {
5660

57-
public static final String METHOD_ADDRESS_BY_GEOLOCATION = "addressByGeolocation";
61+
private static final String METHOD_ADDRESS_BY_GEOLOCATION = "addressByGeolocation";
5862
private static final Logger LOG = getLogger(MethodHandles.lookup().lookupClass());
5963

6064
private final AddressDtoService addressDtoService;
@@ -188,4 +192,16 @@ public List<AddressDto> addressesWherePlaceIsIn(
188192

189193
return addressDtoService.getAddressesWherePlaceIsIn(placeId);
190194
}
195+
196+
197+
@ApiOperation(
198+
value = "Returns a list of matching addresses.",
199+
notes = "Can be static addresses or nominatim resolved addresses."
200+
)
201+
@ModelAttribute("addresses")
202+
@RequestMapping(value = "/addresses", method = GET, params = { "query" })
203+
public List<AddressDto> getAddresses(@RequestParam("query") String query) {
204+
205+
return addressDtoService.getAddressesByQuery(query);
206+
}
191207
}

src/main/java/net/contargo/iris/address/api/SimpleAddressApiController.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/test/java/net/contargo/iris/address/api/AddressApiControllerMvcUnitTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
* MVC Unit test of {@link AddressApiController}.
5959
*
6060
* @author Arnold Franke - franke@synyx.de
61+
* @author Sandra Thieme - thieme@synyx.de
62+
* @author Ben Antony - antony@synyx.de
6163
*/
6264
@RunWith(SpringJUnit4ClassRunner.class)
6365
@ContextConfiguration(locations = { "classpath:public-api-context.xml" })
@@ -209,4 +211,20 @@ public void testAddressByPlaceId() throws Exception {
209211
.andExpect(content().contentType("application/json"))
210212
.andExpect(jsonPath("$.addresses[0].displayName", is("76137 Karlsruhe")));
211213
}
214+
215+
216+
@Test
217+
public void getAddresses() throws Exception {
218+
219+
Address address = new Address();
220+
address.setDisplayName("Gartenstr. 67, Karlsruhe (Südweststadt)");
221+
222+
when(addressDtoServiceMock.getAddressesByQuery("Gartenstraße 67, Karlsruhe")).thenReturn(singletonList(
223+
new AddressDto(address)));
224+
225+
mockMvc.perform(get("/addresses").param("query", "Gartenstraße 67, Karlsruhe"))
226+
.andExpect(status().isOk())
227+
.andExpect(jsonPath("$.addresses", hasSize(1)))
228+
.andExpect(jsonPath("$.addresses[0].displayName", is("Gartenstr. 67, Karlsruhe (Südweststadt)")));
229+
}
212230
}

src/test/java/net/contargo/iris/address/api/SimpleAddressApiControllerUnitTest.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)