Skip to content

Commit

Permalink
[REVIEWS-96] Added body fields validations for post methods rest api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturo777 committed May 31, 2022
1 parent b05e0e7 commit cb70e76
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Added body fields validations for post methods rest api.

## [3.8.14] - 2022-05-24

### Added
Expand Down
57 changes: 57 additions & 0 deletions dotnet/Controllers/RoutesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ public async Task<IActionResult> ProcessReviewApiAction(string requestedAction,
}

Review newReview = JsonConvert.DeserializeObject<Review>(bodyAsText);

if(newReview.ProductId == null)
{
return BadRequest("ProductId is missing.");
}
if(newReview.Rating == null)
{
return BadRequest("Rating is missing.");
}
if(newReview.Title == null)
{
return BadRequest("Title is missing.");
}
if(newReview.Text == null)
{
return BadRequest("Text is missing.");
}
if(newReview.ReviewerName == null)
{
return BadRequest("ReviewerName is missing.");
}
if(newReview.Approved == null)
{
return BadRequest("Approved is missing.");
}

bool hasShopperReviewed = await _productReviewsService.HasShopperReviewed(validatedUser.User, newReview.ProductId);
if (hasShopperReviewed)
{
Expand Down Expand Up @@ -114,6 +140,37 @@ public async Task<IActionResult> ProcessReviewApiAction(string requestedAction,
IList<Review> reviews = JsonConvert.DeserializeObject<IList<Review>>(bodyAsText);
List<string> ids = new List<string>();
foreach (Review review in reviews)
{
if(review.VerifiedPurchaser == null)
{
review.VerifiedPurchaser = false;
}
if(review.ProductId == null)
{
return BadRequest("ProductId is missing for one or more reviews.");
}
if(review.Rating == null)
{
return BadRequest("Rating is missing for one or more reviews.");
}
if(review.Title == null)
{
return BadRequest("Title is missing for one or more reviews.");
}
if(review.Text == null)
{
return BadRequest("Text is missing for one or more reviews.");
}
if(review.ReviewerName == null)
{
return BadRequest("ReviewerName is missing for one or more reviews.");
}
if(review.Approved == null)
{
return BadRequest("Approved is missing for one or more reviews.");
}
}
foreach (Review review in reviews)
{
var reviewsResponse = await this._productReviewsService.NewReview(review, false);
ids.Add(reviewsResponse.Id);
Expand Down

0 comments on commit cb70e76

Please sign in to comment.