Ejemplo n.º 1
0
        public async Task <PaginationResponseModel <ReviewResponseModel> > GetAllFromUser(string userName, PaginationDTO pagination)
        {
            int    previousPage    = pagination.Page - 1;
            string previousPageUrl = previousPage > 0 ? $"{_webApplicationUrl}/reviews?page={previousPage}&quantityPerPage={pagination.QuantityPerPage}" : null;

            User registeredUser = await _userRepository.GetByName(userName);

            if (registeredUser == null)
            {
                throw new ResourceNotFoundException("User not found.");
            }

            int totalUserFavorites = await _favoriteRepository.CountByUserId(registeredUser.Id);

            IEnumerable <Favorite> favorites = await _favoriteRepository.GetAllByUserIdIncludingReview(registeredUser.Id, pagination);

            return(new PaginationResponseModel <ReviewResponseModel>()
            {
                Data = favorites.Select(favorite => _converter.ConvertReviewToReviewResponseModel(favorite.Review, registeredUser.Name)),
                NextPage = $"{_webApplicationUrl}/reviews/${registeredUser.Name}/favorites?page={pagination.Page + 1}&quantityPerPage={pagination.QuantityPerPage}",
                PreviousPage = previousPageUrl,
                Total = totalUserFavorites
            });
        }