Add wiki page revision list.

Change-Id: I21a6ff469ef4dbf64a8d77eb4626765ae43ed37e
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 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 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 @@
   @Inject
   Template wikiPage;
 
+  @ResourcePath("benki/wiki/wikiPageRevisionList.html")
+  @Inject
+  Template wikiPageRevisionList;
+
   @Inject SecurityIdentity identity;
 
   @GET
@@ -47,9 +50,7 @@
   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 @@
   @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}