@Test public void article() throws Exception { ArticleVoter articleVoter = articleVoter(VoteState.UP, "foo1"); when(voteService.listArticleVoters(isA(ClientAppUserAccessToken.class), eq(asList(FlakeId.fromString("foo1"), FlakeId.fromString("foo2"))))).thenReturn(asList( articleVoter)); oauthPerform(user, get("/v1/vote/article").param("article-id", "foo1,foo2")).andExpect(status().isOk()) .andExpect(jsonPath("$.data[0].voteState", is("UP"))); }
@ApiOperation(value = "[vote] Vote on an article", notes = "Vote on an article. Note that kaif do not support DOWN vote on article.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) public void article(ClientAppUserAccessToken token, @Valid @RequestBody VoteArticleEntry entry) { ignoreDuplicateVote(() -> { VoteState previousState = voteService.listArticleVoters(token, asList(entry.articleId)) .stream() .map(ArticleVoter::getVoteState) .findAny() .orElse(VoteState.EMPTY); int previousCount = 0; voteService.voteArticle(entry.voteState, entry.articleId, token, previousState, previousCount); }); }
V1VoteResource { @ApiOperation(value = "[vote] Vote on an article", notes = "Vote on an article. Note that kaif do not support DOWN vote on article.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) public void article(ClientAppUserAccessToken token, @Valid @RequestBody VoteArticleEntry entry) { ignoreDuplicateVote(() -> { VoteState previousState = voteService.listArticleVoters(token, asList(entry.articleId)) .stream() .map(ArticleVoter::getVoteState) .findAny() .orElse(VoteState.EMPTY); int previousCount = 0; voteService.voteArticle(entry.voteState, entry.articleId, token, previousState, previousCount); }); } }
V1VoteResource { @ApiOperation(value = "[vote] Vote on an article", notes = "Vote on an article. Note that kaif do not support DOWN vote on article.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) public void article(ClientAppUserAccessToken token, @Valid @RequestBody VoteArticleEntry entry) { ignoreDuplicateVote(() -> { VoteState previousState = voteService.listArticleVoters(token, asList(entry.articleId)) .stream() .map(ArticleVoter::getVoteState) .findAny() .orElse(VoteState.EMPTY); int previousCount = 0; voteService.voteArticle(entry.voteState, entry.articleId, token, previousState, previousCount); }); }  }
V1VoteResource { @ApiOperation(value = "[vote] Vote on an article", notes = "Vote on an article. Note that kaif do not support DOWN vote on article.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) public void article(ClientAppUserAccessToken token, @Valid @RequestBody VoteArticleEntry entry) { ignoreDuplicateVote(() -> { VoteState previousState = voteService.listArticleVoters(token, asList(entry.articleId)) .stream() .map(ArticleVoter::getVoteState) .findAny() .orElse(VoteState.EMPTY); int previousCount = 0; voteService.voteArticle(entry.voteState, entry.articleId, token, previousState, previousCount); }); }  @ApiOperation(value = "[vote] List votes of the user on multiple articles", notes = "List votes of the user on multiple articles. When you paging articles, " + "you may want to know what user voted for those articles in the page. " + "You can send multiple articleIds to obtain votes in batch.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.GET) List<V1VoteDto> votesOfArticles(ClientAppUserAccessToken token,
      @ApiParam(value = "comma separated articleIds", allowMultiple = true)
      @RequestParam("article-id") List<String> articleIds); @ApiOperation(value = "[vote] List votes of the user on multiple debates", notes = "List votes of the user on multiple debates. When you paging debates, " + "you may want to know what user voted for those debates in the page. " + "You can send multiple debateIds to obtain votes in batch.") @RequiredScope(VOTE) @RequestMapping(value = "/debate", method = RequestMethod.GET) List<V1VoteDto> votesOfDebates(ClientAppUserAccessToken token,
      @ApiParam(value = "comma separated debateIds", allowMultiple = true)
      @RequestParam("debate-id") List<String> debateIds); @ApiOperation(value = "[vote] List all votes of the user for all debates in an article", notes = "List all votes of the user on all debates of the article, this is recommend method when " + "you want all votes of the user in a large debate tree.") @RequiredScope(VOTE) @RequestMapping(value = "/debate/article/{articleId}", method = RequestMethod.GET) List<V1VoteDto> votesOfDebatesOfArticle(ClientAppUserAccessToken token,
      @PathVariable("articleId") FlakeId articleId); @ApiOperation(value = "[vote] Vote on an article", notes = "Vote on an article. Note that kaif do not support DOWN vote on article.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void article(ClientAppUserAccessToken token, @Valid @RequestBody VoteArticleEntry entry); @ApiOperation(value = "[vote] Vote on a debate", notes = "Vote on a debate.") @RequiredScope(VOTE) @RequestMapping(value = "/debate", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void debate(ClientAppUserAccessToken token, @Valid @RequestBody VoteDebateEntry entry); }
V1VoteResource { @ApiOperation(value = "[vote] Vote on an article", notes = "Vote on an article. Note that kaif do not support DOWN vote on article.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) public void article(ClientAppUserAccessToken token, @Valid @RequestBody VoteArticleEntry entry) { ignoreDuplicateVote(() -> { VoteState previousState = voteService.listArticleVoters(token, asList(entry.articleId)) .stream() .map(ArticleVoter::getVoteState) .findAny() .orElse(VoteState.EMPTY); int previousCount = 0; voteService.voteArticle(entry.voteState, entry.articleId, token, previousState, previousCount); }); }  @ApiOperation(value = "[vote] List votes of the user on multiple articles", notes = "List votes of the user on multiple articles. When you paging articles, " + "you may want to know what user voted for those articles in the page. " + "You can send multiple articleIds to obtain votes in batch.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.GET) List<V1VoteDto> votesOfArticles(ClientAppUserAccessToken token,
      @ApiParam(value = "comma separated articleIds", allowMultiple = true)
      @RequestParam("article-id") List<String> articleIds); @ApiOperation(value = "[vote] List votes of the user on multiple debates", notes = "List votes of the user on multiple debates. When you paging debates, " + "you may want to know what user voted for those debates in the page. " + "You can send multiple debateIds to obtain votes in batch.") @RequiredScope(VOTE) @RequestMapping(value = "/debate", method = RequestMethod.GET) List<V1VoteDto> votesOfDebates(ClientAppUserAccessToken token,
      @ApiParam(value = "comma separated debateIds", allowMultiple = true)
      @RequestParam("debate-id") List<String> debateIds); @ApiOperation(value = "[vote] List all votes of the user for all debates in an article", notes = "List all votes of the user on all debates of the article, this is recommend method when " + "you want all votes of the user in a large debate tree.") @RequiredScope(VOTE) @RequestMapping(value = "/debate/article/{articleId}", method = RequestMethod.GET) List<V1VoteDto> votesOfDebatesOfArticle(ClientAppUserAccessToken token,
      @PathVariable("articleId") FlakeId articleId); @ApiOperation(value = "[vote] Vote on an article", notes = "Vote on an article. Note that kaif do not support DOWN vote on article.") @RequiredScope(VOTE) @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void article(ClientAppUserAccessToken token, @Valid @RequestBody VoteArticleEntry entry); @ApiOperation(value = "[vote] Vote on a debate", notes = "Vote on a debate.") @RequiredScope(VOTE) @RequestMapping(value = "/debate", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void debate(ClientAppUserAccessToken token, @Valid @RequestBody VoteDebateEntry entry);  }