summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java6
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java31
-rw-r--r--src/main/resources/templates/benki/wiki/wikiPageRevisionList.html38
3 files changed, 68 insertions, 7 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java
index dff7e69..9b40d5d 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java
@@ -1,12 +1,13 @@
package eu.mulk.mulkcms2.benki.wiki;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import java.util.Collection;
+import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
import javax.persistence.Table;
@Entity
@@ -18,5 +19,6 @@ public class WikiPage extends PanacheEntityBase {
public int id;
@OneToMany(mappedBy = "page", fetch = FetchType.LAZY)
- public Collection<WikiPageRevision> revisions;
+ @OrderBy("date desc")
+ public List<WikiPageRevision> revisions;
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
index 714b785..a8d7db4 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -13,7 +13,6 @@ import io.smallrye.jwt.auth.principal.JWTCallerPrincipal;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.TemporalAccessor;
-import java.util.Map;
import java.util.Optional;
import javax.inject.Inject;
import javax.ws.rs.GET;
@@ -39,6 +38,10 @@ public class WikiResource {
@Inject
Template wikiPage;
+ @ResourcePath("benki/wiki/wikiPageRevisionList.html")
+ @Inject
+ Template wikiPageRevisionList;
+
@Inject SecurityIdentity identity;
@GET
@@ -47,9 +50,7 @@ public class WikiResource {
public TemplateInstance getPage(@PathParam("pageName") String pageName) {
Optional<WikiPageRevision> maybePage =
WikiPageRevision.find(
- "from WikiPageRevision rev"
- + " join fetch rev.author"
- + " where rev.title = ?1",
+ "from WikiPageRevision rev" + " join fetch rev.author" + " where rev.title = ?1",
Sort.by("date").descending(),
pageName)
.firstResultOptional();
@@ -75,7 +76,27 @@ public class WikiResource {
@Path("/{pageName}/revisions")
@Produces(TEXT_HTML)
public TemplateInstance getPageRevisions(@PathParam("pageName") String pageName) {
- throw new NotImplementedYetException();
+ Optional<WikiPageRevision> maybePrimaryRevision =
+ WikiPageRevision.find(
+ "from WikiPageRevision rev" + " join fetch rev.author" + " where rev.title = ?1",
+ Sort.by("date").descending(),
+ pageName)
+ .firstResultOptional();
+ if (maybePrimaryRevision.isEmpty()) {
+ throw new NotFoundException();
+ }
+ var primaryRevision = maybePrimaryRevision.get();
+
+ WikiPage page =
+ WikiPageRevision.find(
+ "from WikiPage p"
+ + " join fetch p.revisions rev"
+ + " join fetch rev.author"
+ + " where p.id = ?1",
+ primaryRevision.page.id)
+ .singleResult();
+
+ return wikiPageRevisionList.data("page", page).data("title", pageName);
}
@TemplateExtension
diff --git a/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html b/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html
new file mode 100644
index 0000000..c44a6e5
--- /dev/null
+++ b/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html
@@ -0,0 +1,38 @@
+{@eu.mulk.mulkcms2.benki.wiki.WikiPage page}
+{@java.lang.String title}
+
+{#include base.html}
+
+{#title}Revisions &#8212; {title} &#8212; Benki Wiki{/title}
+
+{#body}
+<header>
+ <h1>Revisions &#8212; {title}</h1>
+</header>
+
+<main>
+ <table>
+ <thead>
+ <tr>
+ <th>Date</th>
+ <th>Title</th>
+ <th>Author</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ {#with page}
+ {#for revision in revisions}
+ {#with revision}
+ <tr>{date.humanDateTime}</tr>
+ <tr>{title}</tr>
+ <tr>{author.firstName}</tr>
+ {/with}
+ {/for}
+ {/with}
+ </tbody>
+ </table>
+</main>
+{/body}
+
+{/include}