summaryrefslogtreecommitdiff
path: root/src/main/java/eu
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu')
-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