use of com.khartec.waltz.model.bookmark.Bookmark in project waltz by khartec.
the class BookmarksEndpoint method register.
@Override
public void register() {
get(mkPath(BASE_URL, ":kind", ":id"), (request, response) -> {
response.type(TYPE_JSON);
EntityReference ref = getEntityReference(request);
return bookmarkService.findByReference(ref);
}, transformer);
post(mkPath(BASE_URL), (request, response) -> {
requireRole(userRoleService, request, Role.BOOKMARK_EDITOR);
response.type(TYPE_JSON);
Bookmark bookmark = readBody(request, Bookmark.class);
LOG.info("Saving bookmark: " + bookmark);
boolean isUpdate = bookmark.id().isPresent();
return isUpdate ? bookmarkService.update(bookmark, getUsername(request)) : bookmarkService.create(bookmark, getUsername(request));
}, transformer);
delete(mkPath(BASE_URL, ":id"), (request, response) -> {
requireRole(userRoleService, request, Role.BOOKMARK_EDITOR);
response.type(TYPE_JSON);
long bookmarkId = getId(request);
Bookmark bookmark = bookmarkService.getById(bookmarkId);
if (bookmark == null) {
LOG.warn("Attempt made to delete non-existent bookmark: " + bookmarkId);
return false;
}
LOG.info("Deleting bookmark: " + bookmark);
return bookmarkService.deleteById(bookmark, getUsername(request));
}, transformer);
}
Aggregations