summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-24 19:11:24 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-24 19:11:24 +0100
commit9222efa007b8790852dc761d09367863bf56ddf3 (patch)
tree078e101d53aa8a87e06013157ddb049a48b40e7d /src/main/java
parent57c9a8aa7845f27cee62c423c7128b46d256fc40 (diff)
Start implementing /wiki/{pageName}.
Change-Id: Ia9adf24209be8eddcfec72a66434ea4100855533
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java63
-rw-r--r--src/main/java/eu/mulk/mulkcms2/cms/web/ExampleResource.java30
2 files changed, 60 insertions, 33 deletions
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 @@ package eu.mulk.mulkcms2.benki.wiki;
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!";
- }
-}