Skip to content
Snippets Groups Projects
Commit 0ef2b66f authored by Tomáš Zaťko's avatar Tomáš Zaťko
Browse files

fixed ReviewController methods

parent 637542a8
No related branches found
No related tags found
2 merge requests!31Milestone 1,!25fix: fixed ReviewController methods
......@@ -362,4 +362,7 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd
DataAccessLayer/Migrations
\ No newline at end of file
DataAccessLayer/Migrations
/WebAPI/BookHubDB.db
/WebAPI/BookHubDB.db-shm
/WebAPI/BookHubDB.db-wal
......@@ -84,6 +84,13 @@ namespace WebAPI.Controllers
[Route("create")]
public async Task<IActionResult> AddReview([FromBody] ReviewDTO reviewModel)
{
var book = await _dbContext.Books.FindAsync(reviewModel.BookId);
if (book == null)
{
return BadRequest("Book was not found.");
}
// TODO: add 'var userId = await GetUserId()' when the user is logged in at the next stage of the project
var review = new Review
{
......@@ -99,9 +106,10 @@ namespace WebAPI.Controllers
return Ok("Review added.");
}
[HttpPut]
[Route("{id}/update")]
public async Task<IActionResult> UpdateReview(int id, [FromBody] ReviewDTO reviewModel)
public async Task<IActionResult> UpdateReview(int id, [FromBody] UpdateReviewDTO reviewModel)
{
var review = await _dbContext.Reviews.FindAsync(id);
if (review == null)
......
......@@ -7,4 +7,11 @@
public double Rating { get; set; }
public string Description { get; set; }
}
public class UpdateReviewDTO
{
public double Rating { get; set; }
public string Description { get; set; }
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment