public async Task <IActionResult> GetOriginalTweets() { try { var tweets = await TweetService.GetAsync(tweetSettings); var json = JsonConvert.SerializeObject(tweets); return(new OkObjectResult(json)); } catch (Exception e) { logger.LogCritical(e, "Unhandled error while getting original tweets"); return(new ObjectResult(e) { StatusCode = StatusCodes.Status500InternalServerError }); } }
private async Task <IActionResult> GetOriginalTweets( List <string> communities ) { try { communities ??= defaultCommunities; var allCommunities = (await realmSettings.GetAllCommunitiesAsync(SocialMediaType.Twitter)) .Select(x => x.Community.Name).ToList(); var allTweets = await CacheHelper.PostsCache.GetOrCreateAsync("tweets", async() => await TweetService.GetAsync(this.tweetSettings, allCommunities)); var tweets = new List <ISocialPost>(); foreach (var community in communities) { tweets.AddRange(allTweets.Where(x => x.CommunityGroupId.Equals(community, StringComparison.InvariantCultureIgnoreCase))); } var json = JsonConvert.SerializeObject(tweets); return(new OkObjectResult(json)); } catch (Exception e) { logger.LogCritical(e, "Unhandled error while getting original tweets"); return(new ObjectResult(e) { StatusCode = StatusCodes.Status500InternalServerError }); } }