Pagination in http request get by id

Viewed 25

I want to implement pagination on an api call that returns a list of strings, based on the id and I am having a little trouble here. Here is my HttpGet call

        [Route("getLogsFileNames/{id}")]
        public IActionResult GetLogsFileNames(Guid id, string include = "")
        {
            return Ok(_deidentificationService.GetLogsFileNames(id, include));
        }

And here is the implementation from the service

public List<string> GetLogsFileNames(Guid deviceId, string include = "")
        {
            var blobNames = new List<string>();
            var blobs = _blobUtils.GetBlobsFromContainer(deviceId);

            if (string.IsNullOrEmpty(include))
            {
                blobs.ToList().ForEach(blob => blobNames.Add(blob.Name));
            }
            else
            {
                blobs.Where(blob => blob.Name.ToLower().Contains(include.ToLower())).ToList()
                     .ForEach(blob => blobNames.Add(blob.Name));
            }

            return blobNames;
        }

any ideas?

1 Answers

You need to pass a PageNumber to your service. You also need to define a PageSize. Then you can implement a selection of a subset of your list:

blobNames.Skip((PageNumber-1)*PageSize).Take(PageSize);
Related