Start implementing /wiki/{pageName}.
Change-Id: Ia9adf24209be8eddcfec72a66434ea4100855533
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 0bf69d6..8f25254 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -2,25 +2,82 @@
import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import io.quarkus.panache.common.Sort;
import io.quarkus.qute.Template;
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.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
+import java.util.Map;
+import java.util.Optional;
import javax.inject.Inject;
import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import org.jboss.logging.Logger;
+import org.jboss.resteasy.spi.NotImplementedYetException;
@Path("/wiki")
public class WikiResource {
+ private static Logger log = Logger.getLogger(WikiResource.class);
+
+ private static DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+
+ private static DateTimeFormatter humanDateFormatter =
+ DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
+
@ResourcePath("benki/wiki/wikiPage.html")
- @Inject Template wikiPage;
+ @Inject
+ Template wikiPage;
+
+ @Inject SecurityIdentity identity;
@GET
- @Path("/pages/{pageName}")
+ @Path("/{pageName}")
@Produces(TEXT_HTML)
public TemplateInstance getPage(@PathParam("pageName") String pageName) {
- return wikiPage.data("title", "TEST");
+ Optional<WikiPageRevision> maybePage =
+ WikiPageRevision.find("title = ?1", Sort.by("date").descending(), pageName)
+ .firstResultOptional();
+ if (maybePage.isEmpty()) {
+ throw new NotFoundException();
+ }
+ var page = maybePage.get();
+ return wikiPage
+ .data("title", page.title)
+ .data(
+ "date",
+ Map.of(
+ "htmlFormat", htmlDateFormatter.format(page.date),
+ "humanFormat", humanDateFormatter.format(page.date)))
+ .data(
+ "author",
+ Map.of("name", String.format("%s %s", page.author.firstName, page.author.lastName)))
+ .data("content", page.content);
+ }
+
+ @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());
+ }
+ throw new NotImplementedYetException();
+ }
+
+ @GET
+ @Path("/{pageName}/revisions")
+ @Produces(TEXT_HTML)
+ public TemplateInstance getPageRevisions(@PathParam("pageName") String pageName) {
+ throw new NotImplementedYetException();
}
}
diff --git a/src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java b/src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java
deleted file mode 100644
index cac9ba8..0000000
--- a/src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package eu.mulk.mulkcms2.cms.web;
-
-import io.quarkus.security.Authenticated;
-import io.quarkus.security.identity.SecurityIdentity;
-import io.smallrye.jwt.auth.principal.JWTCallerPrincipal;
-import javax.inject.Inject;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import org.jboss.logging.Logger;
-
-@Path("/example")
-public class ExampleResource {
-
- private static Logger log = Logger.getLogger(ExampleResource.class);
-
- @Inject SecurityIdentity identity;
-
- @GET
- @Produces({MediaType.TEXT_PLAIN})
- @Authenticated
- public String hello() {
- if (!identity.isAnonymous()) {
- var jwtCallerPrincipal = (JWTCallerPrincipal) identity.getPrincipal();
- log.infof("Logged in as user: %s", jwtCallerPrincipal.getName());
- }
- return "hello!";
- }
-}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 4ba1cb1..bf6018f 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -7,9 +7,10 @@
#quarkus.flyway.baseline-version = 1
#quarkus.flyway.schemas = public
-%dev.quarkus.datasource.url = jdbc:postgresql://localhost:5432/flep
+%dev.quarkus.datasource.url = jdbc:postgresql://localhost:5432/mulkcms
%dev.quarkus.datasource.username = mulk
%dev.quarkus.datasource.password =
+%dev.quarkus.hibernate-orm.log.sql = true
quarkus.oidc.auth-server-url = https://login.benkard.de/auth/realms/master
quarkus.oidc.client-id = mulkcms
diff --git a/src/main/resources/templates/benki/wiki/wikiPage.html b/src/main/resources/templates/benki/wiki/wikiPage.html
index 9b3af5d..caf587a 100644
--- a/src/main/resources/templates/benki/wiki/wikiPage.html
+++ b/src/main/resources/templates/benki/wiki/wikiPage.html
@@ -6,5 +6,15 @@
</head>
<body>
<h1>{title}</h1>
+
+ <header>
+ Last edit: <time datetime="{date.htmlFormat}">{date.humanFormat}</time> {author.name}
+ </header>
+
+ <main>
+ <article>
+ {content.raw}
+ </article>
+ </main>
</body>
</html>