use of com.baremaps.model.Collections in project baremaps by baremaps.
the class CollectionsResourceIntegrationTest method test.
@Test
public void test() {
// Create a new collection
Collection collection = new Collection().title("test").links(List.of(new Link().href("/link").rel("self")));
// List the collections
Collections collections = target().path("/collections").request().get(Collections.class);
assertEquals(0, collections.getCollections().size());
// Insert the collection
Response response = target().path("/collections").request(MediaType.APPLICATION_JSON).post(Entity.entity(collection, MediaType.valueOf("application/json")));
assertEquals(201, response.getStatus());
// List the collections
collections = target().path("/collections").request().get(Collections.class);
assertEquals(1, collections.getCollections().size());
// Get the collection
String id = response.getHeaderString("Location").split("/")[4];
collection = target().path("/collections/" + id).request().get(Collection.class);
assertEquals("test", collection.getTitle());
// Update the collection
collection.setTitle("test_update");
response = target().path("/collections/" + id).request().put(Entity.entity(collection, MediaType.valueOf("application/json")));
assertEquals(204, response.getStatus());
// Delete the collection
response = target().path("/collections/" + id).request().delete();
assertEquals(204, response.getStatus());
// List the collections
collections = target().path("/collections").request().get(Collections.class);
assertEquals(0, collections.getCollections().size());
}
use of com.baremaps.model.Collections in project baremaps by baremaps.
the class CollectionsResource method getCollections.
@Override
public Response getCollections() {
List<Collection> collectionList = jdbi.withHandle(handle -> handle.createQuery("select collection from collections").mapTo(COLLECTION).list());
collectionList.forEach(collection -> collection.getLinks().add(new Link().href(uriInfo.getRequestUri().toString() + "/" + collection.getId()).rel("self")));
Collections collections = new Collections().collections(collectionList);
collections.getLinks().add(new Link().href(uriInfo.getRequestUri().toString()).rel("self"));
return Response.ok(collections).build();
}
Aggregations