change voting
This commit is contained in:
parent
1ba9ca32e4
commit
1fc18fdeb2
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>11</java.version>
|
||||
<revision>0.3.0-SNAPSHOT</revision>
|
||||
<revision>0.3.1-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
|
@ -112,25 +112,27 @@ public class CommentManager {
|
||||
}
|
||||
if (!comment.getMetadata().containsKey("points")) {
|
||||
comment.getMetadata().put("points",
|
||||
voteManager.getPoints(comment.getId(), Types.entry));
|
||||
voteManager.getPoints(comment.getId(), Types.comment));
|
||||
}
|
||||
if (!comment.getMetadata().containsKey("vote")) {
|
||||
comment.getMetadata().put("vote",
|
||||
!voteRepository.exists(qVote.target.eq(comment.getId())
|
||||
|
||||
if (!comment.getMetadata().containsKey("upvoted")) {
|
||||
comment.getMetadata().put("upvoted",
|
||||
voteRepository.exists(qVote.target.eq(comment.getId())
|
||||
.and(qVote.targetType.eq(Types.comment)).and(qVote.type.eq(VoteType.up))
|
||||
.and(qVote.author.eq(username))));
|
||||
}
|
||||
if (!comment.getMetadata().containsKey("unvote")) {
|
||||
comment.getMetadata().put("unvote",
|
||||
|
||||
if (!comment.getMetadata().containsKey("downvoted")) {
|
||||
comment.getMetadata().put("downvoted",
|
||||
voteRepository.exists(qVote.target.eq(comment.getId())
|
||||
.and(qVote.targetType.eq(Types.comment))
|
||||
.and(qVote.type.eq(VoteType.up).and(qVote.author.eq(username)))));
|
||||
.and(qVote.type.eq(VoteType.down)).and(qVote.author.eq(username))));
|
||||
}
|
||||
if (!comment.getMetadata().containsKey("downvote")) {
|
||||
comment.getMetadata()
|
||||
.put("downvote",
|
||||
!voteRepository.exists(qVote.target.eq(comment.getId())
|
||||
.and(qVote.targetType.eq(Types.comment))
|
||||
|
||||
if (!comment.getMetadata().containsKey("unvote")) {
|
||||
comment.getMetadata().put("unvote",
|
||||
voteRepository.exists(
|
||||
qVote.target.eq(comment.getId()).and(qVote.targetType.eq(Types.comment))
|
||||
.and(qVote.author.eq(username))));
|
||||
}
|
||||
}
|
||||
|
@ -89,22 +89,26 @@ public class EntryManager {
|
||||
if (!entry.getMetadata().containsKey("points")) {
|
||||
entry.getMetadata().put("points", voteManager.getPoints(entry.getId(), Types.entry));
|
||||
}
|
||||
if (!entry.getMetadata().containsKey("vote")) {
|
||||
entry.getMetadata().put("vote",
|
||||
!voteRepository.exists(qVote.target.eq(entry.getId())
|
||||
|
||||
if (!entry.getMetadata().containsKey("upvoted")) {
|
||||
entry.getMetadata().put("upvoted",
|
||||
voteRepository.exists(qVote.target.eq(entry.getId())
|
||||
.and(qVote.targetType.eq(Types.entry)).and(qVote.type.eq(VoteType.up))
|
||||
.and(qVote.author.eq(username))));
|
||||
}
|
||||
if (!entry.getMetadata().containsKey("unvote")) {
|
||||
entry.getMetadata().put("unvote",
|
||||
|
||||
if (!entry.getMetadata().containsKey("downvoted")) {
|
||||
entry.getMetadata().put("downvoted",
|
||||
voteRepository.exists(qVote.target.eq(entry.getId())
|
||||
.and(qVote.targetType.eq(Types.entry))
|
||||
.and(qVote.type.eq(VoteType.up).and(qVote.author.eq(username)))));
|
||||
.and(qVote.type.eq(VoteType.down)).and(qVote.author.eq(username))));
|
||||
}
|
||||
if (!entry.getMetadata().containsKey("downvote")) {
|
||||
entry.getMetadata().put("downvote",
|
||||
!voteRepository.exists(qVote.target.eq(entry.getId())
|
||||
.and(qVote.targetType.eq(Types.entry)).and(qVote.author.eq(username))));
|
||||
|
||||
if (!entry.getMetadata().containsKey("unvote")) {
|
||||
entry.getMetadata().put("unvote",
|
||||
voteRepository.exists(
|
||||
qVote.target.eq(entry.getId()).and(qVote.targetType.eq(Types.entry))
|
||||
.and(qVote.author.eq(username))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class VoteController extends BaseController {
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@PutMapping("/e/{id}")
|
||||
@PutMapping("/e/{id}/up")
|
||||
public void voteEntryUp(@PathVariable("id") Long id) {
|
||||
if (!entryManager.exists(id)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
@ -68,7 +68,7 @@ public class VoteController extends BaseController {
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@DeleteMapping("/e/{id}")
|
||||
@PutMapping("/e/{id}/down")
|
||||
public void voteEntryDown(@PathVariable("id") Long id) {
|
||||
if (!entryManager.exists(id)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
@ -88,6 +88,21 @@ public class VoteController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@DeleteMapping("/e/{id}")
|
||||
public void unvoteEntry(@PathVariable("id") Long id) {
|
||||
if (!entryManager.exists(id)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
Vote vote = voteManager.get(getCurrentUsername(), Types.entry, id);
|
||||
if (vote == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NOT_MODIFIED);
|
||||
}
|
||||
|
||||
voteManager.delete(vote);
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping("/c/{id}")
|
||||
public long getCommentPoints(@PathVariable("id") Long id) {
|
||||
@ -99,7 +114,7 @@ public class VoteController extends BaseController {
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@PutMapping("/c/{id}")
|
||||
@PutMapping("/c/{id}/up")
|
||||
public void voteCommentUp(@PathVariable("id") Long id) {
|
||||
if (!commentManager.exists(id)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
@ -120,7 +135,7 @@ public class VoteController extends BaseController {
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@DeleteMapping("/c/{id}")
|
||||
@PutMapping("/c/{id}/down")
|
||||
public void voteCommentDown(@PathVariable("id") Long id) {
|
||||
if (!commentManager.exists(id)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
@ -140,4 +155,19 @@ public class VoteController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@DeleteMapping("/c/{id}")
|
||||
public void unvoteComment(@PathVariable("id") Long id) {
|
||||
if (!commentManager.exists(id)) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
Vote vote = voteManager.get(getCurrentUsername(), Types.comment, id);
|
||||
if (vote == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NOT_MODIFIED);
|
||||
}
|
||||
|
||||
voteManager.delete(vote);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user