summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java17
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java41
2 files changed, 50 insertions, 8 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java
index 35a4986..c6bcf5f 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java
@@ -38,4 +38,21 @@ public class WikiPageRevision extends PanacheEntityBase {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author", referencedColumnName = "id")
public User author;
+
+ public WikiPageRevision() {}
+
+ public WikiPageRevision(
+ OffsetDateTime date,
+ String title,
+ String content,
+ String format,
+ WikiPage page,
+ User author) {
+ this.date = date;
+ this.title = title;
+ this.content = content;
+ this.format = format;
+ this.page = page;
+ this.author = author;
+ }
}
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 a8d7db4..10112db 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -2,6 +2,7 @@ package eu.mulk.mulkcms2.benki.wiki;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import eu.mulk.mulkcms2.benki.users.User;
import io.quarkus.panache.common.Sort;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateExtension;
@@ -9,12 +10,13 @@ import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.api.ResourcePath;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
-import io.smallrye.jwt.auth.principal.JWTCallerPrincipal;
+import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.TemporalAccessor;
import java.util.Optional;
import javax.inject.Inject;
+import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
@@ -47,10 +49,11 @@ public class WikiResource {
@GET
@Path("/{pageName}")
@Produces(TEXT_HTML)
+ @Authenticated
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();
@@ -64,21 +67,43 @@ public class WikiResource {
@POST
@Path("/{pageName}")
@Authenticated
- public void updatePage(@PathParam("pageName") String pageName) {
- if (!identity.isAnonymous()) {
- var jwtCallerPrincipal = (JWTCallerPrincipal) identity.getPrincipal();
- log.infof("Logged in as user: %s", jwtCallerPrincipal.getName());
+ public void updatePage(
+ @PathParam("pageName") String pageName,
+ @FormParam("title") String title,
+ @FormParam("content") String content) {
+ var userName = identity.getPrincipal().getName();
+
+ Optional<WikiPageRevision> maybeCurrentRevision =
+ WikiPageRevision.find(
+ "from WikiPageRevision rev join fetch rev.author where rev.title = ?1",
+ Sort.by("date").descending(),
+ pageName)
+ .firstResultOptional();
+ if (maybeCurrentRevision.isEmpty()) {
+ throw new NotFoundException();
}
- throw new NotImplementedYetException();
+ var currentRevision = maybeCurrentRevision.get();
+
+ var pageRevision =
+ new WikiPageRevision(
+ OffsetDateTime.now(),
+ title,
+ content,
+ "html5",
+ currentRevision.page,
+ User.find("name = ?1", userName).singleResult());
+
+ WikiPageRevision.persist(pageRevision);
}
@GET
@Path("/{pageName}/revisions")
@Produces(TEXT_HTML)
+ @Authenticated
public TemplateInstance getPageRevisions(@PathParam("pageName") String pageName) {
Optional<WikiPageRevision> maybePrimaryRevision =
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();