summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-18 15:48:04 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-18 15:48:04 +0200
commitb6081275edefe500b8dd8b5239e7ab3dd7d633a2 (patch)
tree68cbdedee388a238d906484a20dd572eeb4accbf /src/main/java
parent6cfe16b3bf3e5c576956f4cb9d9b5d8a30cc1e87 (diff)
KB51 Add handler for post links.
Change-Id: Icb36da42fcf085ec541ba70c1421e8635d295974
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java2
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java35
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);
+ }
}