Esempio n. 1
0
            protected async Task <int> GetTotalPages(
                PostsQuery request,
                int?userId = default,
                CancellationToken cancellationToken = default)
            {
                var postSpecification = this.GetPostSpecification(request);

                var userSpecification = this.GetUserSpecification(request, userId);

                var totalPosts = await this.postRepository.Total(
                    postSpecification,
                    userSpecification,
                    cancellationToken);

                return((int)Math.Ceiling((double)totalPosts / PostsPerPage));
            }
Esempio n. 2
0
            protected async Task <IEnumerable <TOutputModel> > GetPostListings <TOutputModel>(
                PostsQuery request,
                int?userId = default,
                CancellationToken cancellationToken = default)
            {
                var postSpecification = this.GetPostSpecification(request);

                var userSpecification = this.GetUserSpecification(request, userId);

                var searchOrder = new PostsSortOrder(request.SortBy, request.Order);

                var skip = (request.Page - 1) * PostsPerPage;

                return(await this.postRepository.GetPostListings <TOutputModel>(
                           postSpecification,
                           userSpecification,
                           searchOrder,
                           skip,
                           take : PostsPerPage,
                           cancellationToken));
            }
Esempio n. 3
0
 private Specification <Post> GetPostSpecification(PostsQuery request)
 => new PostByCategorySpecification(request.Category)
 .And(new PostByCreatedOnSpecification(request.StartDate, request.EndDate));
Esempio n. 4
0
 private Specification <PublicUser> GetUserSpecification(PostsQuery request, int?userId)
 => new PublicUserByIdSpecification(userId)
 .And(new PublicUserByUserNameSpecification(request.User));