private static PublicationComment ToDomain(Comment entity) { return(new PublicationComment( entity.Id, entity.Content, KeysBuilder.PublicationCommentKey(entity.Key), ToUser(entity.Author), entity.CreatedOn)); }
public async Task <(IEnumerable <PublicationComment>, long)> GetAsync(string publicationId, int skip, int take) { var response = await commentsApi .SearchByKeyWithHttpInfoAsync(KeysBuilder.PublicationCommentKey(publicationId), skip, take); var comments = response.Data.Select(c => ToDomain(c, publicationId)).ToList(); var totalCount = GetTotalCountHeader(response); return(comments, totalCount); }
private async Task <Dictionary <string, CommentsShort> > LoadCommentsAsync(IEnumerable <string> publicationIds) { var keys = publicationIds.Select(KeysBuilder.PublicationCommentKey).ToList(); var query = new FeaturedQuery(keys); var featuredComments = await commentsApi.SearchFeaturedAsync(query); return(publicationIds .ToDictionary(publicationId => publicationId, publicationId => { var comment = featuredComments.GetValueOrDefault(KeysBuilder.PublicationCommentKey(publicationId)); return new CommentsShort( comment?.Comments.Select(c => ToDomain(c)) ?? Enumerable.Empty <PublicationComment>(), comment?.TotalCount ?? 0); })); }
public async Task DeleteManyAsync(string publicationId) { await commentsApi.DeleteByKeyAsync(KeysBuilder.PublicationCommentKey(publicationId)); }
public async Task <PublicationComment> PublishAsync(string content, string publicationId, string userId) { var comment = await commentsApi.CreateAsync(new CreateCommentModel(KeysBuilder.PublicationCommentKey(publicationId), content, authorId : userId)); return(ToDomain(comment, publicationId)); }