diff options
Diffstat (limited to 'src/main/java/eu')
-rw-r--r-- | src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java | 40 |
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") |