✨ POST-endpoint in the box
Co-authored-by: haraldnilsen <harald_998@hotmail.com>
This commit is contained in:
parent
251d551c3f
commit
a134a5e376
2 changed files with 34 additions and 11 deletions
backend
|
@ -76,15 +76,30 @@ public class MovieController: ControllerBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// [HttpPost(Name = "PostMovie")]
|
[HttpPost(Name = "PostMovie")]
|
||||||
// public ActionResult<> Post([FromQuery] string movieTitle) {
|
public ActionResult Post(
|
||||||
// try
|
[FromQuery] string s,
|
||||||
// {
|
[FromQuery] string y,
|
||||||
|
[FromQuery] string imdbID,
|
||||||
// }
|
[FromQuery] string type,
|
||||||
// catch (Exception ex)
|
[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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -18,4 +18,12 @@ public class MovieDB
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
|
|
||||||
public string Poster { 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;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in a new issue