KB51 Add handler for post links.
Change-Id: Icb36da42fcf085ec541ba70c1421e8635d295974
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 @@
@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 @@
}
@CheckForNull
- protected User getCurrentUser() {
+ protected final User getCurrentUser() {
if (identity.isAnonymous()) {
return null;
}
@@ -292,13 +292,8 @@
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 @@
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);
+ }
}
diff --git a/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js b/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js
index 5b67cee..e43e135 100644
--- a/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js
+++ b/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js
@@ -71,7 +71,7 @@
connectedCallback() {
if (this.editedId !== null) {
this.mainForm.method = "post";
- this.mainForm.action = `/lazychat/p/${this.editedId}/edit`;
+ this.mainForm.action = `/lazychat/${this.editedId}/edit`;
}
}
@@ -89,7 +89,7 @@
return;
}
- let fetchUrl = new URL(`/lazychat/p/${this.editedId}`, document.URL);
+ let fetchUrl = new URL(`/posts/${this.editedId}`, document.URL);
let r = await fetch(fetchUrl);
if (!r.ok) {