Exemplo n.º 1
0
        public async Task <IActionResult> ListAsync(
            [FromQuery] int skip = 0,
            [FromQuery] int top  = 100)
        {
            var query = new ListBucketQuery
            {
                Skip = skip,
                Top  = top
            };

            var result = await _queryExecutor.ExecuteAsync <ListBucketQuery, PaginationCollection <BucketDocument> >(query);

            return(Ok(result));
        }
        public async Task <Result <PaginationCollection <BucketDocument> > > HandleAsync(ListBucketQuery query, CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(query, nameof(query));
            cancellationToken.ThrowIfCancellationRequested();

            var userId = _userContext.UserId;

            var totalCount = await _readOnlyRepository.CountAsync(p => p.UserId == userId, cancellationToken);

            var buckets = await _readOnlyRepository.ListAsync(p => p.UserId == userId, query.Top, query.Skip, cancellationToken);

            var documents            = buckets.Select(_mapperDefinition.Map).ToList();
            var paginationCollection = new PaginationCollection <BucketDocument>()
            {
                Items = documents,
                Count = totalCount
            };

            return(Result.Ok(paginationCollection));
        }