diff options
Diffstat (limited to 'src/main/java/eu')
-rw-r--r-- | src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java | 2 | ||||
-rw-r--r-- | src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java | 35 |
2 files changed, 29 insertions, 8 deletions
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); + } } |