From 6ef2a4f8afc3c3c80da1445a8d4b64ff1673dd22 Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Tue, 19 Sep 2023 11:14:59 +0200 Subject: [PATCH] :sparkles: introducing pagination in the api! Co-authored-by: haraldnilsen --- backend/Controllers/MovieController.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/Controllers/MovieController.cs b/backend/Controllers/MovieController.cs index 2dc8e4e..32b77db 100644 --- a/backend/Controllers/MovieController.cs +++ b/backend/Controllers/MovieController.cs @@ -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 resultSkip = movies.Skip(pageSize * (pageNumber - 1)); + IEnumerable resultTake = resultSkip.Take(pageSize); + + return Ok(resultTake); } catch (Exception ex) {