From 9364b5cfc4d4883719418b2acacd80aeb204c9db Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Mon, 2 Oct 2023 10:21:02 +0200 Subject: [PATCH] :sparkles: Can now get all movies from API Co-authored-by: haraldnilsen --- backend/Controllers/MovieController.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/Controllers/MovieController.cs b/backend/Controllers/MovieController.cs index a605c14..0780271 100644 --- a/backend/Controllers/MovieController.cs +++ b/backend/Controllers/MovieController.cs @@ -1,3 +1,4 @@ +using System.Collections; using Microsoft.AspNetCore.Mvc; using Microsoft.OpenApi.Writers; @@ -23,7 +24,7 @@ public class MovieController: ControllerBase [HttpGet(Name = "GetMovies")] public ActionResult> Get( - [FromQuery] string s, + [FromQuery] string? s, [FromQuery] string? type, [FromQuery] string? y, [FromQuery] string? sort, @@ -32,8 +33,11 @@ public class MovieController: ControllerBase ) { try { - if (!IsValidS(s)) return StatusCode(400, "Bad Request: Invalid title"); - var movies = _context.Movies.Where(m => m.Title.ToLower().Contains(s.ToLower())); + var movies = _context.Movies.AsQueryable(); + if (s != null) { + if (!IsValidS(s)) return StatusCode(400, "Bad Request: Invalid title"); + movies = _context.Movies.Where(m => m.Title.ToLower().Contains(s.ToLower())); + } if (type != null) { if (!IsValidType(type)) return StatusCode(400, "Bad Request: Invalid type");