✨ introducing pagination in the api!
Co-authored-by: haraldnilsen <harald_998@hotmail.com>
This commit is contained in:
parent
f2d00947c8
commit
6ef2a4f8af
1 changed files with 8 additions and 1 deletions
|
@ -22,7 +22,14 @@ public class MovieController: ControllerBase
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var movies = _context.Movies.ToList();
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
Reference in a new issue