summaryrefslogtreecommitdiff
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-19 19:38:49 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-19 19:56:20 +0200
commitbbac0c7d90986f95e93a473c7228021ab726e464 (patch)
tree6a5807e3c026017ad1f8e37f492b415a65ee3f31 /src/main/java/eu
parent3c4911e9a87702fcf199d410a5502775b02e9947 (diff)
KB53 Support bookmark edition.
Change-Id: Ieacbb5c448b9afa4bc9524167e0c73618de6db48
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
index 495e511..059335c 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
@@ -27,10 +27,13 @@ import javax.transaction.Transactional;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
+import javax.ws.rs.ForbiddenException;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
@@ -76,6 +79,43 @@ public class BookmarkResource extends PostResource {
return Response.seeOther(new URI("/bookmarks")).build();
}
+ @POST
+ @Transactional
+ @Authenticated
+ @Produces(WILDCARD)
+ @Consumes({APPLICATION_FORM_URLENCODED, MULTIPART_FORM_DATA})
+ @Path("{id}/edit")
+ public Response patchMessage(
+ @PathParam("id") int id,
+ @FormParam("uri") @NotNull URI uri,
+ @FormParam("title") @NotEmpty String title,
+ @FormParam("description") @CheckForNull String description,
+ @FormParam("visibility") Post.Visibility visibility)
+ throws URISyntaxException {
+
+ var user = Objects.requireNonNull(getCurrentUser());
+
+ var bookmark = getSession().byId(Bookmark.class).load(id);
+
+ if (bookmark == null) {
+ throw new NotFoundException();
+ }
+
+ if (bookmark.owner == null || !Objects.equals(bookmark.owner.id, user.id)) {
+ throw new ForbiddenException();
+ }
+
+ bookmark.uri = uri.toString();
+ bookmark.title = title;
+ bookmark.tags = Set.of();
+ bookmark.description = description;
+ bookmark.owner = user;
+
+ assignPostTargets(visibility, user, bookmark);
+
+ return Response.seeOther(new URI("/bookmarks")).build();
+ }
+
@GET
@Authenticated
@Path("new")