@Test public void news() throws Exception { when(feedService.listFeeds(isA(ClientAppUserAccessToken.class), isNull(FlakeId.class))).thenReturn(asList(asset1, asset2)); when(articleService.listDebatesByIdWithCache(asList(debate1.getDebateId(), debate2.getDebateId()))).thenReturn(asList(debate1, debate2)); oauthPerform(user, get("/v1/feed/news")).andExpect(status().isOk()) .andExpect(jsonPath("$.data[0].assetType", is("DEBATE_FROM_REPLY"))) .andExpect(jsonPath("$.data[0].debate.content", is("deb1"))); }
@ApiOperation(value = "[feed] Latest news", notes = "List latest FeedAssets, 25 assets a page. " + "To retrieve next page, passing last asset id of previous page in parameter start-asset-id.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news", method = RequestMethod.GET) public List<V1FeedAssetDto> news(ClientAppUserAccessToken token, @RequestParam(value = "start-asset-id", required = false) FlakeId startAssetId) { List<FeedAsset> feedAssets = feedService.listFeeds(token, startAssetId); List<Debate> debates = articleService.listDebatesByIdWithCache(feedAssets.stream() .map(FeedAsset::getAssetId) .collect(toList())); return feedAssets.stream() .filter(asset -> asset.getAssetType() == FeedAsset.AssetType.DEBATE_FROM_REPLY) .map(asset -> { V1DebateDto found = debates.stream() .filter(debate -> debate.getDebateId().equals(asset.getAssetId())) .map(Debate::toV1Dto) .findAny() .orElse(null); return new V1FeedAssetDto(asset.getAssetId().toString(), V1AssetType.DEBATE_FROM_REPLY, Date.from(asset.getCreateTime()), asset.isAcked(), found); }) .collect(toList()); }
V1FeedResource { @ApiOperation(value = "[feed] Latest news", notes = "List latest FeedAssets, 25 assets a page. " + "To retrieve next page, passing last asset id of previous page in parameter start-asset-id.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news", method = RequestMethod.GET) public List<V1FeedAssetDto> news(ClientAppUserAccessToken token, @RequestParam(value = "start-asset-id", required = false) FlakeId startAssetId) { List<FeedAsset> feedAssets = feedService.listFeeds(token, startAssetId); List<Debate> debates = articleService.listDebatesByIdWithCache(feedAssets.stream() .map(FeedAsset::getAssetId) .collect(toList())); return feedAssets.stream() .filter(asset -> asset.getAssetType() == FeedAsset.AssetType.DEBATE_FROM_REPLY) .map(asset -> { V1DebateDto found = debates.stream() .filter(debate -> debate.getDebateId().equals(asset.getAssetId())) .map(Debate::toV1Dto) .findAny() .orElse(null); return new V1FeedAssetDto(asset.getAssetId().toString(), V1AssetType.DEBATE_FROM_REPLY, Date.from(asset.getCreateTime()), asset.isAcked(), found); }) .collect(toList()); } }
V1FeedResource { @ApiOperation(value = "[feed] Latest news", notes = "List latest FeedAssets, 25 assets a page. " + "To retrieve next page, passing last asset id of previous page in parameter start-asset-id.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news", method = RequestMethod.GET) public List<V1FeedAssetDto> news(ClientAppUserAccessToken token, @RequestParam(value = "start-asset-id", required = false) FlakeId startAssetId) { List<FeedAsset> feedAssets = feedService.listFeeds(token, startAssetId); List<Debate> debates = articleService.listDebatesByIdWithCache(feedAssets.stream() .map(FeedAsset::getAssetId) .collect(toList())); return feedAssets.stream() .filter(asset -> asset.getAssetType() == FeedAsset.AssetType.DEBATE_FROM_REPLY) .map(asset -> { V1DebateDto found = debates.stream() .filter(debate -> debate.getDebateId().equals(asset.getAssetId())) .map(Debate::toV1Dto) .findAny() .orElse(null); return new V1FeedAssetDto(asset.getAssetId().toString(), V1AssetType.DEBATE_FROM_REPLY, Date.from(asset.getCreateTime()), asset.isAcked(), found); }) .collect(toList()); }  }
V1FeedResource { @ApiOperation(value = "[feed] Latest news", notes = "List latest FeedAssets, 25 assets a page. " + "To retrieve next page, passing last asset id of previous page in parameter start-asset-id.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news", method = RequestMethod.GET) public List<V1FeedAssetDto> news(ClientAppUserAccessToken token, @RequestParam(value = "start-asset-id", required = false) FlakeId startAssetId) { List<FeedAsset> feedAssets = feedService.listFeeds(token, startAssetId); List<Debate> debates = articleService.listDebatesByIdWithCache(feedAssets.stream() .map(FeedAsset::getAssetId) .collect(toList())); return feedAssets.stream() .filter(asset -> asset.getAssetType() == FeedAsset.AssetType.DEBATE_FROM_REPLY) .map(asset -> { V1DebateDto found = debates.stream() .filter(debate -> debate.getDebateId().equals(asset.getAssetId())) .map(Debate::toV1Dto) .findAny() .orElse(null); return new V1FeedAssetDto(asset.getAssetId().toString(), V1AssetType.DEBATE_FROM_REPLY, Date.from(asset.getCreateTime()), asset.isAcked(), found); }) .collect(toList()); }  @ApiOperation(value = "[feed] Latest news", notes = "List latest FeedAssets, 25 assets a page. " + "To retrieve next page, passing last asset id of previous page in parameter start-asset-id.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news", method = RequestMethod.GET) List<V1FeedAssetDto> news(ClientAppUserAccessToken token,
      @RequestParam(value = "start-asset-id", required = false) FlakeId startAssetId); @ApiOperation(value = "[feed] Get unread count in news feed", notes = "Get unread count in news feed, max value is 11 regardless real unread count. " + "The method should not repeat invoke in short time, we recommend once per 5 minutes.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news-unread-count", method = RequestMethod.GET) int newsUnreadCount(ClientAppUserAccessToken token); @ApiOperation(value = "[feed] Acknowledge a FeedAsset", notes = "A FeedAsset set to acknowledged will treat all assets before it as read. " + "Typically you should acknowledge the latest feedAssetId you received " + "when the user open news feed window in your app.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/acknowledge", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void acknowledge(ClientAppUserAccessToken token,
      @Valid @RequestBody AcknowledgeEntry entry); }
V1FeedResource { @ApiOperation(value = "[feed] Latest news", notes = "List latest FeedAssets, 25 assets a page. " + "To retrieve next page, passing last asset id of previous page in parameter start-asset-id.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news", method = RequestMethod.GET) public List<V1FeedAssetDto> news(ClientAppUserAccessToken token, @RequestParam(value = "start-asset-id", required = false) FlakeId startAssetId) { List<FeedAsset> feedAssets = feedService.listFeeds(token, startAssetId); List<Debate> debates = articleService.listDebatesByIdWithCache(feedAssets.stream() .map(FeedAsset::getAssetId) .collect(toList())); return feedAssets.stream() .filter(asset -> asset.getAssetType() == FeedAsset.AssetType.DEBATE_FROM_REPLY) .map(asset -> { V1DebateDto found = debates.stream() .filter(debate -> debate.getDebateId().equals(asset.getAssetId())) .map(Debate::toV1Dto) .findAny() .orElse(null); return new V1FeedAssetDto(asset.getAssetId().toString(), V1AssetType.DEBATE_FROM_REPLY, Date.from(asset.getCreateTime()), asset.isAcked(), found); }) .collect(toList()); }  @ApiOperation(value = "[feed] Latest news", notes = "List latest FeedAssets, 25 assets a page. " + "To retrieve next page, passing last asset id of previous page in parameter start-asset-id.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news", method = RequestMethod.GET) List<V1FeedAssetDto> news(ClientAppUserAccessToken token,
      @RequestParam(value = "start-asset-id", required = false) FlakeId startAssetId); @ApiOperation(value = "[feed] Get unread count in news feed", notes = "Get unread count in news feed, max value is 11 regardless real unread count. " + "The method should not repeat invoke in short time, we recommend once per 5 minutes.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/news-unread-count", method = RequestMethod.GET) int newsUnreadCount(ClientAppUserAccessToken token); @ApiOperation(value = "[feed] Acknowledge a FeedAsset", notes = "A FeedAsset set to acknowledged will treat all assets before it as read. " + "Typically you should acknowledge the latest feedAssetId you received " + "when the user open news feed window in your app.") @RequiredScope(ClientAppScope.FEED) @RequestMapping(value = "/acknowledge", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void acknowledge(ClientAppUserAccessToken token,
      @Valid @RequestBody AcknowledgeEntry entry);  }