public async Task <PaginationResponseModel <ReviewResponseModel> > GetAll(PaginationDTO pagination) { IEnumerable <Review> reviews; int count = await _reviewRepository.Count(); string reviewsInsertedOnCacheJson = await _cacheDatabase.Get($"reviews?page={pagination.Page}&quantityPerPage={pagination.QuantityPerPage}"); if (reviewsInsertedOnCacheJson != null) { reviews = _jsonUtils.Deserialize <IEnumerable <Review> >(reviewsInsertedOnCacheJson); } else { reviews = await _reviewRepository.GetAll(pagination); if (reviews.Count() > 0) { await _cacheDatabase.Set($"reviews?page={pagination.Page}&quantityPerPage={pagination.QuantityPerPage}", _jsonUtils.Serialize(reviews)); } } return(CreatePaginationResult(reviews, count, pagination)); }
public async Task <PaginationResponseModel <CommentResponseModel> > GetAllFromReview(string reviewId, PaginationDTO pagination) { Guid reviewIdGuid = Guid.Parse(reviewId); await ThrowIfReviewNotExists(reviewIdGuid); int totalInsertedsCommentsInReview = await _commentRepository.CountFromReview(reviewIdGuid); IEnumerable <Comment> comments; string commentsRegisteredOnCacheJson = await _cacheDatabase.Get($"reviews/{reviewId}/comments?page={pagination.Page}&quantityPerPage={pagination.QuantityPerPage}"); if (commentsRegisteredOnCacheJson != null) { comments = _jsonUtils.Deserialize <IEnumerable <Comment> >(commentsRegisteredOnCacheJson); return(CreatePaginationResult(comments, totalInsertedsCommentsInReview, reviewId, pagination)); } comments = await _commentRepository.GetAllFromReview(reviewIdGuid, pagination); if (comments.Count() > 0) { await _cacheDatabase.Set($"reviews/{reviewId}/comments?page={pagination.Page}&quantityPerPage={pagination.QuantityPerPage}", _jsonUtils.Serialize(comments)); } return(CreatePaginationResult(comments, totalInsertedsCommentsInReview, reviewId, pagination)); }