Skip to content

Commit

Permalink
feat: comment vote endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sixwaaaay committed Jan 8, 2024
1 parent 2a7a4f6 commit 53bff17
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,32 @@ public void deleteComment(
comment.setReplyTo(request.getReplyTo());
commentService.deleteComment(comment);
}

/**
* vote a comment
*
* @param id the id of comment
* @param header the header of request
*/
@PostMapping("/action/like/{id}")
public void voteComment(
@PathVariable long id,
@RequestHeader(value = "Authorization", defaultValue = "") String header) {
var userAuth = tokenParser.parse(header);
commentService.voteComment(userAuth.map(UserAuth::getId).orElseThrow(NoUserExitsError::supply), id);
}

/**
* cancel vote a comment
*
* @param id the id of comment
* @param header the header of request
*/
@DeleteMapping("/action/like/{id}")
public void cancelVoteComment(
@PathVariable long id,
@RequestHeader(value = "Authorization", defaultValue = "") String header) {
var userAuth = tokenParser.parse(header);
commentService.cancelVoteComment(userAuth.map(UserAuth::getId).orElseThrow(NoUserExitsError::supply), id);
}
}

0 comments on commit 53bff17

Please sign in to comment.