introducing pagination in the api!

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
This commit is contained in:
Sindre Kjelsrud 2023-09-19 11:14:59 +02:00
parent f2d00947c8
commit 6ef2a4f8af

View file

@ -22,7 +22,14 @@ public class MovieController: ControllerBase
try
{
var movies = _context.Movies.ToList();
return Ok(movies);
var totalMovies = movies.Count;
var totalPages = Math.Ceiling((double)totalMovies / pageSize);
IEnumerable<MovieDB> resultSkip = movies.Skip(pageSize * (pageNumber - 1));
IEnumerable<MovieDB> resultTake = resultSkip.Take(pageSize);
return Ok(resultTake);
}
catch (Exception ex)
{