added parent id to posts

This commit is contained in:
2024-06-05 11:00:09 +02:00
parent d843bbd787
commit 49254f3d87
2 changed files with 24 additions and 11 deletions

View File

@@ -81,12 +81,9 @@ public class Routes {
// create a post from the author id
JodelPost post = new JodelPost(rs);
// get the posts parent
long parent = rs.getLong("parent");
// check if the parent is the own id
// if it is, it is a post
if (parent == post.id) {
if (!post.isComment()) {
// add the post to the posts
posts.add(post);
}
@@ -95,7 +92,7 @@ public class Routes {
// iterate over all posts
for (JodelPost p : posts) {
// try to add the post to a parent
p.addComment(post, parent);
p.addComment(post);
}
}
}
@@ -200,7 +197,7 @@ public class Routes {
// else it is a comment
else {
// try to add the post to parent
root_post.ifPresent(root -> root.addComment(post, parent));
root_post.ifPresent(root -> root.addComment(post));
}
}
@@ -287,6 +284,14 @@ public class Routes {
throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "Database is offline");
}
// fill missing post values
if (post.parent.isEmpty()) post.parent = Optional.of(post.id);
post.reactions = new Reactions(0, 0);
post.reaction = Optional.empty();
// anonymize code
post.anonymize(Optional.empty());
return post;
}