Commit cafada99 authored by saliou673's avatar saliou673
Browse files

SERVER:feat: handle up and down vote on post

parent 05b3f0a5
......@@ -23,4 +23,13 @@ public interface Post {
void addComment(Comment commentEntity);
void deleteComment(Comment commentEntity);
void setDate(String date);
int getUpVote();
void setUpVote(int value);
int getDownVote();
void setDownVote(int value);
int increaseUpVote();
int decreaseUpVote();
int increaseDownVote();
int decreaseDownVote();
}
......@@ -33,6 +33,10 @@ public class PostEntity implements Post{
private String date;
@Field("comments")
private List<Comment> comments;
@Field("upVote")
private int upVote;
@Field("downVote")
private int downVote;
public PostEntity(String subject, String content) {
this.subject = subject;
......@@ -40,6 +44,8 @@ public class PostEntity implements Post{
this.author = null;
this.date = Timestamp.valueOf(LocalDateTime.now()).toString();
this.comments = new ArrayList<>();
upVote = 0;
downVote = 0;
}
@Override
......@@ -107,6 +113,36 @@ public class PostEntity implements Post{
this.date = date;
}
@Override
public void setUpVote(int value) {
upVote = value;
}
@Override
public void setDownVote(int value) {
downVote = value;
}
@Override
public int increaseUpVote() {
return ++upVote;
}
@Override
public int decreaseUpVote() {
return --upVote;
}
@Override
public int increaseDownVote() {
return ++downVote;
}
@Override
public int decreaseDownVote() {
return --downVote;
}
@Override
public String toString() {
return "Post{" +
......@@ -115,6 +151,8 @@ public class PostEntity implements Post{
", content='" + content + '\'' +
", author=" + author +
", comments=" + comments +
", upVote=" + upVote +
"downVote=" + downVote +
'}';
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment