POST-endpoint in the box

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
This commit is contained in:
Sindre Kjelsrud 2023-09-26 09:47:41 +02:00
parent 251d551c3f
commit a134a5e376
2 changed files with 34 additions and 11 deletions

View file

@ -76,15 +76,30 @@ public class MovieController: ControllerBase
}
}
// [HttpPost(Name = "PostMovie")]
// public ActionResult<> Post([FromQuery] string movieTitle) {
// try
// {
// }
// catch (Exception ex)
// {
// }
// }
[HttpPost(Name = "PostMovie")]
public ActionResult Post(
[FromQuery] string s,
[FromQuery] string y,
[FromQuery] string imdbID,
[FromQuery] string type,
[FromQuery] string poster
) {
try
{
MovieDB newMovie = new(s, y, imdbID, type, poster);
var movies = _context.Movies.Where(m => m.imdbID.ToLower().Contains(imdbID.ToLower()));
if (movies.Count() == 0) {
_context.Add(newMovie);
_context.SaveChanges();
return Ok("Successfully added new movie");
} else {
return StatusCode(409, "Conflict, imdbID already exists");
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error posting movie");
return StatusCode(500, "Internal server error");
}
}
}

View file

@ -18,4 +18,12 @@ public class MovieDB
public string Type { get; set; }
public string Poster { get; set; }
public MovieDB(string Title, string Year, string imdbID, string Type, string Poster) {
this.Title = Title;
this.Year = Year;
this.imdbID = imdbID;
this.Type = Type;
this.Poster = Poster;
}
}