protected async Task <int> GetTotalPages( BooksQuery request, bool onlyAvailable = true, int?authorId = default, CancellationToken cancellationToken = default) { var bookSpecification = this.GetBookSpecification(request, onlyAvailable); var authorSpecification = this.GetAuthorSpecification(request, authorId); var totalBooks = await this.bookRepository.Total( bookSpecification, authorSpecification, cancellationToken); return((int)Math.Ceiling((double)totalBooks / BooksPerPage)); }
protected async Task <IEnumerable <TOutputModel> > GetBookListings <TOutputModel>( BooksQuery request, bool onlyAvailable = true, int?authorId = default, CancellationToken cancellationToken = default) { var bookSpecification = this.GetBookSpecification(request, onlyAvailable); var authorSpecification = this.GetAuthorSpecification(request, authorId); var searchOrder = new BooksSortOrder(request.SortBy, request.Order); var skip = (request.Page - 1) * BooksPerPage; return(await this.bookRepository.GetBookListings <TOutputModel>( bookSpecification, authorSpecification, searchOrder, skip, take : BooksPerPage, cancellationToken)); }
private Specification <Book> GetBookSpecification(BooksQuery request, bool onlyAvailable) => new BookByPublisherSpecification(request.Publisher) .And(new BookByPriceSpecification(request.MinPrice, request.MaxPrice)) .And(new BookOnlyAvailableSpecification(onlyAvailable));
private Specification <Author> GetAuthorSpecification(BooksQuery request, int?authorId) => new AuthorByIdSpecification(authorId) .And(new AuthorByNameSpecification(request.Author));