/// <inheritdoc/>
        public Task <IPagedData <WeightTransaction> > FetchPagedAsync(WeightTransactionFilter filter,
                                                                      IPagingOptions pagingOptions,
                                                                      ListSortDirection sortDirection,
                                                                      CancellationToken cancellationToken)
        {
            _logger.LogInformation("Fetching paged weight transactions according to a filter. {@Filter}, {@PagingOptions}, {@SortDirection}",
                                   filter,
                                   pagingOptions,
                                   sortDirection);

            return(_context.WeightTransactions.AsNoTracking()
                   .MapToWeightTransaction()
                   .FilterOnObject(filter)
                   .SortByCriteria(t => t.TransactionDate, sortDirection)
                   .PaginateAsync(pagingOptions));
        }
        public async Task <IActionResult> GetAllAsync(int pageNumber,
                                                      int pageSize,
                                                      [FromQuery] long[]?animalIds,
                                                      decimal?weightUpper,
                                                      decimal?weightLower,
                                                      bool?exclude = false)
        {
            Logger.LogInformation("Requesting {@PageSize} weight transactions for {@AnimalIds} from page {@PageNumber}...",
                                  pageSize,
                                  animalIds ?? Enumerable.Empty <long>(),
                                  pageNumber);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var pagingOptions = new PagingOptions
            {
                PageNumber = pageNumber,
                PageSize   = pageSize == 0 ? 10 : pageSize
            };

            var filter = new WeightTransactionFilter();

            if (animalIds != null)
            {
                filter.AddAnimalIds(animalIds);
            }
            filter.SetWeightBounds(weightLower, weightUpper);
            if (exclude.HasValue && exclude.Value)
            {
                filter.SetIncludeState(false);
            }

            var transactions = await _weightTransactionCrudService.FetchPagedAsync(filter,
                                                                                   pagingOptions,
                                                                                   ListSortDirection.Descending,
                                                                                   RequestAbortToken)
                               .ConfigureAwait(false);

            return(Ok(transactions));
        }