Exemplo n.º 1
0
        public async Task <ActionResult <PaginatedItemsViewModel <EmailDTO> > > ItemsAsync(
            [FromQuery] int pageSize  = 10,
            [FromQuery] int pageIndex = 0,
            [FromQuery] Dictionary <string, string> filter = default,
            [FromQuery] Dictionary <string, int> sorting   = default,
            CancellationToken cancellation = default)
        {
            var filterSpec = GenerateFilter(filter);
            var totalItems = await _emailService.CountAsync(filterSpec, cancellation);

            var pagedFilterSpec = GenerateFilter(filter, pageSize, pageIndex);
            var sortingSpec     = GenerateSortingSpec(sorting);
            var items           = await _emailService.ListAsync(pagedFilterSpec, sortingSpec, cancellation);

            var model = new PaginatedItemsViewModel <EmailDTO>(pageIndex, pageSize, totalItems, items.Select(_mapper.Map <EmailDTO>));

            return(Ok(model));
        }