Search in sources :

Example 1 with CommentInputView

use of org.ambraproject.rhino.view.comment.CommentInputView in project rhino by PLOS.

the class CommentCrudController method create.

@RequestMapping(value = "/articles/{articleDoi}/comments", method = RequestMethod.POST)
@ApiImplicitParam(name = "body", paramType = "body", dataType = "CommentInputView", value = "example: {\"creatorUserId\": 10365, " + "\"parentCommentId\": \"10.1371/annotation/0043aae2-f69d-4a05-ab19-4709704eb749\", " + "\"title\": \"no, really watch this\", " + "\"body\": \"http://www.youtube.com/watch?v=iGQdwSAAz9I\", " + "\"highlightedText\": \"whoah...\", " + "\"competingInterestStatement\": \"I'm going for an Emmy\"}")
public ResponseEntity<?> create(HttpServletRequest request, @PathVariable("articleDoi") String articleDoi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    CommentInputView input = readJsonFromRequest(request, CommentInputView.class);
    // TODO: Pass Optional.empty() if client POSTed to "/comments"?
    Optional<ArticleIdentifier> articleIdObj = Optional.of(articleId);
    return commentCrudService.createComment(articleIdObj, input).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) CommentInputView(org.ambraproject.rhino.view.comment.CommentInputView) ApiImplicitParam(com.wordnik.swagger.annotations.ApiImplicitParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CommentInputView

use of org.ambraproject.rhino.view.comment.CommentInputView 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

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