summaryrefslogtreecommitdiff
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-26 06:09:57 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-04-26 06:12:43 +0200
commit1c2a8a70eed63a6b59dde22bdcb1d029e8485089 (patch)
treec3df25d8f9ff64daaeb27b19530eb13fc9e0b6b3 /src/main/java/eu
parent95d29a00d3f37d64f5256cea4e7308f5a975c86c (diff)
KB54 Put posts in date buckets for templating.
Change-Id: Ic17b2dede722f5962a55b9c4d3b4663a71480e9c
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java28
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java7
2 files changed, 31 insertions, 4 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
index 3a02e4e..bbfafa2 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
@@ -6,11 +6,15 @@ import eu.mulk.mulkcms2.benki.lazychat.LazychatMessage;
import eu.mulk.mulkcms2.benki.users.User;
import eu.mulk.mulkcms2.benki.users.User_;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
+import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
+import java.util.TimeZone;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.json.bind.annotation.JsonbTransient;
@@ -173,7 +177,9 @@ public abstract class Post extends PanacheEntityBase {
public @CheckForNull final Integer nextCursor;
public final List<T> posts;
- private PostPage(
+ private static final TimeZone timeZone = TimeZone.getDefault();
+
+ public PostPage(
@CheckForNull Integer c0,
@CheckForNull Integer c1,
@CheckForNull Integer c2,
@@ -183,6 +189,26 @@ public abstract class Post extends PanacheEntityBase {
this.nextCursor = c2;
this.posts = resultList;
}
+
+ public class Day {
+ public final @CheckForNull LocalDate date;
+ public final List<T> posts;
+
+ private Day(LocalDate date, List<T> posts) {
+ this.date = date;
+ this.posts = posts;
+ }
+ }
+
+ public List<Day> days() {
+ return posts.stream()
+ .collect(Collectors.groupingBy(post -> post.date.toLocalDate()))
+ .entrySet()
+ .stream()
+ .map(x -> new Day(x.getKey(), x.getValue()))
+ .sorted(Comparator.comparing((Day day) -> day.date).reversed())
+ .collect(Collectors.toUnmodifiableList());
+ }
}
public static List<Post> findViewable(
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
index 5f3c8b4..92e2f4e 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
@@ -13,6 +13,7 @@ import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.WireFeedOutput;
import eu.mulk.mulkcms2.benki.accesscontrol.PageKey;
import eu.mulk.mulkcms2.benki.accesscontrol.Role;
+import eu.mulk.mulkcms2.benki.posts.Post.PostPage;
import eu.mulk.mulkcms2.benki.users.User;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateExtension;
@@ -116,7 +117,7 @@ public abstract class PostResource {
}
return postList
- .data("posts", q.posts)
+ .data("postDays", q.days())
.data("feedUri", feedUri)
.data("pageTitle", pageTitle)
.data("showBookmarkForm", showBookmarkForm())
@@ -150,7 +151,7 @@ public abstract class PostResource {
}
return postList
- .data("posts", q.posts)
+ .data("postDays", q.days())
.data("feedUri", feedUri)
.data("pageTitle", pageTitle)
.data("showBookmarkForm", showBookmarkForm())
@@ -191,7 +192,7 @@ public abstract class PostResource {
var post = getPostIfVisible(id);
return postList
- .data("posts", List.of(post))
+ .data("postDays", new PostPage<>(null, null, null, List.of(post)).days())
.data("pageTitle", pageTitle)
.data("showBookmarkForm", false)
.data("showLazychatForm", false)