diff --git a/src/main/java/de/anxietyprime/swajodel/JodelPost.java b/src/main/java/de/anxietyprime/swajodel/JodelPost.java index 75ad871..97c7986 100644 --- a/src/main/java/de/anxietyprime/swajodel/JodelPost.java +++ b/src/main/java/de/anxietyprime/swajodel/JodelPost.java @@ -88,6 +88,7 @@ public class JodelPost { this.content = rs.getString("content"); this.date = rs.getTimestamp("postdate"); this.location = new Location(rs.getFloat("longitude"), rs.getFloat("latitude")); + this.reaction = Optional.of(rs.getBoolean("reaction")); this.reactions = new Reactions(rs.getLong("positive"), rs.getLong("negative")); this.parent = Optional.of(rs.getLong("parent")); } @@ -102,10 +103,8 @@ public class JodelPost { @JsonProperty("content") String content, @JsonProperty("date") Timestamp date, @JsonProperty("location") Location location, - @JsonProperty("parent") Optional parent, - // TODO: getter from Keycloak - @JsonProperty("authorID") long author) { - this.authorID = author; // TODO: getter from Keycloak + @JsonProperty("parent") Optional parent) { + this.authorID = User.getUserID(); // TODO: getter from Keycloak this.title = title; this.content = content; this.date = date; diff --git a/src/main/java/de/anxietyprime/swajodel/Routes.java b/src/main/java/de/anxietyprime/swajodel/Routes.java index bcf7bb8..4117b6e 100644 --- a/src/main/java/de/anxietyprime/swajodel/Routes.java +++ b/src/main/java/de/anxietyprime/swajodel/Routes.java @@ -75,10 +75,11 @@ public class Routes { (SELECT * FROM comments inner join posts ON comments.child = posts.id) com inner join targets ON targets.id = com.parent ) - SELECT * FROM targets;"""); + SELECT targets.*, reactions.positive AS reaction FROM targets, reactions WHERE targets.id = reactions.post AND reactions.userid = (?);"""); stmt.setObject(1, longitude); stmt.setObject(2, latitude); + stmt.setObject(3, User.getUserID()); // query recursively for posts inside a 10km radius ResultSet rs = stmt.executeQuery(); @@ -179,9 +180,10 @@ public class Routes { (SELECT * FROM comments inner join posts ON comments.child = posts.id) com inner join targets ON targets.id = com.parent ) - SELECT * FROM targets;"""); + SELECT targets.*, reactions.positive AS reaction FROM targets, reactions WHERE targets.id = reactions.post AND reactions.userid = (?);"""); stmt.setObject(1, id); + stmt.setObject(2, User.getUserID()); // query recursively for posts inside a 10km radius ResultSet rs = stmt.executeQuery(); @@ -320,9 +322,10 @@ public class Routes { c.setAutoCommit(false); // create a new statement - stmt = c.prepareStatement("UPDATE Posts SET deleted = now() WHERE id = ? AND deleted IS NULL"); + stmt = c.prepareStatement("UPDATE Posts SET deleted = now() WHERE id = ? AND author = (?) AND deleted IS NULL"); stmt.setObject(1, id); + stmt.setObject(2, User.getUserID()); // insert delete time stmt.execute();