From 771d3ef0e6fcb25cc6ad26b6205572139fe4ffba Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Tue, 26 Sep 2023 10:25:40 +0200 Subject: [PATCH] :sparkles: PUT-endpoint: minigolf is supported Co-authored-by: haraldnilsen --- backend/Controllers/MovieController.cs | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/backend/Controllers/MovieController.cs b/backend/Controllers/MovieController.cs index b0cd81a..a605c14 100644 --- a/backend/Controllers/MovieController.cs +++ b/backend/Controllers/MovieController.cs @@ -124,4 +124,35 @@ public class MovieController: ControllerBase return StatusCode(500, "Internal server error"); } } + + [HttpPut(Name = "PutMovie")] + public ActionResult Put( + [FromQuery] string? s, + [FromQuery] string? y, + [FromQuery] string imdbID, + [FromQuery] string? type, + [FromQuery] string? poster + ) { + try + { + var movie = _context.Movies.AsEnumerable() + .Where(m => m.imdbID.ToLower().Contains(imdbID.ToLower())) + .ElementAtOrDefault(0); + if (movie != null) { + if (s != null) movie.Title = s; + if (y != null) movie.Year = y; + if (type != null) movie.Type = type; + if (poster != null) movie.Poster = poster; + _context.SaveChanges(); + return Ok("Successfully edited movie"); + } else { + return StatusCode(409, "Conflict, imdbID doesn't exists"); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error deleting movie"); + return StatusCode(500, "Internal server error"); + } + } } \ No newline at end of file