Exemple #1
0
        public async Task <IActionResult> GetBooksByUser(int libraryId,
                                                         int pageNumber = 1,
                                                         int pageSize   = 10,
                                                         [FromQuery] BookStatuses status = BookStatuses.BeingTyped,
                                                         CancellationToken token         = default(CancellationToken))
        {
            var accountId         = _userHelper.Account.Id;
            var getBookPagesQuery = new GetUserBooksQuery(libraryId, accountId, pageNumber, pageSize)
            {
                StatusFilter = status,
            };
            var result = await _queryProcessor.ExecuteAsync(getBookPagesQuery, token);

            var args = new PageRendererArgs <BookModel, BookFilter>
            {
                Page           = result,
                RouteArguments = new PagedRouteArgs {
                    PageNumber = pageNumber, PageSize = pageSize
                },
                Filters = new BookFilter {
                    Status = status
                }
            };

            return(new OkObjectResult(_bookRenderer.Render(args, libraryId)));
        }
Exemple #2
0
        public async Task <IActionResult> GetBooks(int libraryId,
                                                   string query,
                                                   int pageNumber                          = 1,
                                                   int pageSize                            = 10,
                                                   [FromQuery] int?authorId                = null,
                                                   [FromQuery] int?categoryId              = null,
                                                   [FromQuery] int?seriesId                = null,
                                                   [FromQuery] bool?favorite               = null,
                                                   [FromQuery] bool?read                   = null,
                                                   [FromQuery] BookStatuses status         = BookStatuses.Published,
                                                   [FromQuery] BookSortByType sortBy       = BookSortByType.Title,
                                                   [FromQuery] SortDirection sortDirection = SortDirection.Ascending,
                                                   CancellationToken token                 = default(CancellationToken))
        {
            var filter = new BookFilter
            {
                AuthorId   = authorId,
                CategoryId = categoryId,
                SeriesId   = seriesId,
                Favorite   = favorite,
                Read       = read,
                Status     = status
            };
            var request = new GetBooksQuery(libraryId, pageNumber, pageSize, _userHelper.Account?.Id)
            {
                Query         = query,
                Filter        = filter,
                SortBy        = sortBy,
                SortDirection = sortDirection
            };

            var books = await _queryProcessor.ExecuteAsync(request, cancellationToken : token);

            var args = new PageRendererArgs <BookModel, BookFilter>
            {
                Page           = books,
                RouteArguments = new PagedRouteArgs
                {
                    PageNumber    = pageNumber,
                    PageSize      = pageSize,
                    Query         = query,
                    SortBy        = sortBy,
                    SortDirection = sortDirection
                },
                Filters = filter,
            };

            return(new OkObjectResult(_bookRenderer.Render(args, libraryId)));
        }