public bool HasMore(int userId, BookQueryOptions options)
        {
            var query = _context.Books
                        .Where(b => b.UserId == userId);

            if (options.Search != null)
            {
                query = query
                        .Where(x => x.Title.Contains(options.Search) || x.Author.Contains(options.Search));
            }

            if (options.Category.HasValue)
            {
                query = query
                        .Where(x => x.CategoryId == options.Category.Value);
            }

            if (options.Rating.HasValue)
            {
                query = query
                        .Where(x => x.RatingId == options.Rating.Value);
            }

            var entriesPerPage = options.EntriesPerPage ?? 10;

            return(query
                   .Skip((options.Page + 1) * entriesPerPage)
                   .Any());
        }
        public IEnumerable <BookDto> GetUserBooks(int userId, BookQueryOptions options)
        {
            var query = _context.Books
                        .Where(b => b.UserId == userId);

            if (options.Search != null)
            {
                query = query
                        .Where(x => x.Title.Contains(options.Search) || x.Author.Contains(options.Search));
            }

            if (options.Category.HasValue)
            {
                query = query
                        .Where(x => x.CategoryId == options.Category.Value);
            }

            if (options.Rating.HasValue)
            {
                query = query
                        .Where(x => x.RatingId == options.Rating.Value);
            }

            var entriesPerPage = options.EntriesPerPage ?? 10;

            return(query
                   .OrderByDescending(x => x.FinishedOn)
                   .Skip(options.Page * entriesPerPage)
                   .Take(entriesPerPage)
                   .Select(b => ToBookDto(b)));
        }
        public ActionResult <BooksDto> GetUserBooks(int userId, [FromBody] BookQueryOptions queryOptions)
        {
            if (!_userRepository.UserExists(userId))
            {
                return(BadRequest($"User with Id {userId} does not exist."));
            }

            return(new BooksDto
            {
                Books = _bookRepository.GetUserBooks(userId, queryOptions),
                HasMore = _bookRepository.HasMore(userId, queryOptions)
            });
        }
        public ActionResult <BooksDto> GetCurrentUserBooks([FromBody] BookQueryOptions queryOptions)
        {
            var userId = _userHelper.GetUserId(HttpContext);

            if (!_userRepository.UserExists(userId))
            {
                return(BadRequest($"User with Id {userId} does not exist."));
            }

            return(new BooksDto
            {
                Books = _bookRepository.GetUserBooks(userId, queryOptions),
                HasMore = _bookRepository.HasMore(userId, queryOptions)
            });
        }