KB54 Put posts in date buckets for templating.

Change-Id: Ic17b2dede722f5962a55b9c4d3b4663a71480e9c
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.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 @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 @@
       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(