From b6081275edefe500b8dd8b5239e7ab3dd7d633a2 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 18 Apr 2020 15:48:04 +0200 Subject: KB51 Add handler for post links. Change-Id: Icb36da42fcf085ec541ba70c1421e8635d295974 --- .../mulkcms2/benki/lazychat/LazychatResource.java | 2 +- .../eu/mulk/mulkcms2/benki/posts/PostResource.java | 35 +++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java index 3cb1204..fa2da99 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java @@ -49,7 +49,7 @@ public class LazychatResource extends PostResource { @POST @Transactional @Authenticated - @Path("/p/{id}/edit") + @Path("{id}/edit") public Response patchMessage( @PathParam("id") int id, @FormParam("text") String text, diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java index 03447ad..9c871d3 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java @@ -283,7 +283,7 @@ public abstract class PostResource { } @CheckForNull - protected User getCurrentUser() { + protected final User getCurrentUser() { if (identity.isAnonymous()) { return null; } @@ -292,13 +292,8 @@ public abstract class PostResource { return User.findByNickname(userName); } - @GET - @Produces(APPLICATION_JSON) - @Path("/p/{id}") - public Post getPost(@PathParam("id") int id) { - + protected final Post getPostIfVisible(int id) { var user = getCurrentUser(); - var message = getSession().byId(Post.class).load(id); if (!message.isVisibleTo(user)) { @@ -307,4 +302,30 @@ public abstract class PostResource { return message; } + + @GET + @Produces(APPLICATION_JSON) + @Path("{id}") + public Post getPostJson(@PathParam("id") int id) { + return getPostIfVisible(id); + } + + @GET + @Produces(TEXT_HTML) + @Path("{id}") + public TemplateInstance getPostHtml(@PathParam("id") int id) { + var post = getPostIfVisible(id); + + return postList + .data("posts", List.of(post)) + .data("feedUri", "/bookmarks/feed") + .data("pageTitle", pageTitle) + .data("showBookmarkForm", false) + .data("showLazychatForm", false) + .data("hasPreviousPage", false) + .data("hasNextPage", false) + .data("previousCursor", null) + .data("nextCursor", null) + .data("pageSize", null); + } } -- cgit v1.2.3