summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-26 08:05:27 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-26 08:11:48 +0100
commit0aac7c559d87de940238c91ff06c1d225d489ec5 (patch)
tree56c83e013bc794e2c2c3fd75a9174e9ff4bb45cc /src/main/java
parentacac08ebf1f65a73503f56ac47892257026275ff (diff)
Add wiki page revision list.
Change-Id: I21a6ff469ef4dbf64a8d77eb4626765ae43ed37e
Diffstat (limited to 'src/main/java')
-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
2 files changed, 30 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