Search in sources :

Example 1 with CommentIdentifier

use of org.ambraproject.rhino.identity.CommentIdentifier in project rhino by PLOS.

the class CommentCrudController method read.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi:.+}", method = RequestMethod.GET)
public ResponseEntity<?> read(@PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    return commentCrudService.serveComment(commentId).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CommentIdentifier

use of org.ambraproject.rhino.identity.CommentIdentifier in project rhino by PLOS.

the class CommentCrudController method readFlagsOnComment.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags", method = RequestMethod.GET)
public void readFlagsOnComment(HttpServletRequest request, HttpServletResponse response, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    commentCrudService.readCommentFlagsOn(commentId).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CommentIdentifier

use of org.ambraproject.rhino.identity.CommentIdentifier in project rhino by PLOS.

the class CommentCrudController method removeFlag.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi}/flags/{flagId}", method = RequestMethod.DELETE)
public ResponseEntity<Object> removeFlag(@PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi, @PathVariable("flagId") long flagId) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId and commentId
    commentCrudService.deleteCommentFlag(flagId);
    return reportDeleted(Long.toString(flagId));
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CommentIdentifier

use of org.ambraproject.rhino.identity.CommentIdentifier in project rhino by PLOS.

the class CommentCrudController method delete.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi:.+}", method = RequestMethod.DELETE)
@ApiOperation(value = "delete", notes = "Performs a hard delete operation in the database. " + "NOTE: fails loudly if attempting to delete a comment that has any replies. All replies must " + "be deleted first.")
public ResponseEntity<?> delete(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    String deletedCommentUri = commentCrudService.deleteComment(commentId);
    return reportDeleted(deletedCommentUri);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with CommentIdentifier

use of org.ambraproject.rhino.identity.CommentIdentifier in project rhino by PLOS.

the class CommentCrudController method patch.

@RequestMapping(value = "/articles/{articleDoi}/comments/{commentDoi:.+}", method = RequestMethod.PATCH)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "CommentInputView", value = "example #1: {\"title\": \"new title\"}<br>" + "example #2: {\"body\": \"comment body replacement text\"}<br>" + "example #3: {\"isRemoved\": \"true\"}")
public ResponseEntity<?> patch(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi, @PathVariable("commentDoi") String commentDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentIdentifier commentId = CommentIdentifier.create(DoiEscaping.unescape(commentDoi));
    // TODO: Validate articleId
    CommentInputView input = readJsonFromRequest(request, CommentInputView.class);
    return commentCrudService.patchComment(commentId, input).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) CommentInputView(org.ambraproject.rhino.view.comment.CommentInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)8 CommentIdentifier (org.ambraproject.rhino.identity.CommentIdentifier)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ApiImplicitParam (com.wordnik.swagger.annotations.ApiImplicitParam)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 Flag (org.ambraproject.rhino.model.Flag)1 CommentFlagInputView (org.ambraproject.rhino.view.comment.CommentFlagInputView)1 CommentInputView (org.ambraproject.rhino.view.comment.CommentInputView)1