package resources; import dao.ShoppingDAO; import domain.ShoppingItem; import org.jooby.Jooby; import org.jooby.MediaType; import org.jooby.Status; public class ShoppingListResource extends Jooby { public ShoppingListResource(ShoppingDAO dao) { /** * A shopping list management service. */ path("/api/items", () -> { /** * Lists the items in the shopping list. * * @return Items in the list. */ get(() -> { return dao.getList(); }); /** * Add an item to the shopping list. * * @param body The item to add to the list. * @return 201 response if successful. */ post((req, rsp) -> { ShoppingItem item = req.body(ShoppingItem.class); dao.addItem(item); rsp.status(Status.CREATED); }); }).produces(MediaType.json).consumes(MediaType.json); } }