Skip to content

Commit

Permalink
Feat: adds stars to RatingResponse (#265)
Browse files Browse the repository at this point in the history
* fix: typo

* feat: adds stars (one to five) to response

* chore: updates CHANGELOG

* feat: adds productId validation check

* feat: removes validation since we do not know if the stores handle this in frontend

* Trigger build

---------

Co-authored-by: Wender <[email protected]>
  • Loading branch information
eduardoformiga and wender authored Jan 29, 2025
1 parent 99ab584 commit d58c39a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 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]

### Added

- StarsFive, StarsFour, StarsThree, StarsTwo, StarsOne to the RatingResponse
-
## [3.17.0] - 2025-01-29


Expand Down
5 changes: 5 additions & 0 deletions dotnet/Controllers/RoutesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ public async Task<IActionResult> ProcessReviewApiAction(string requestedAction,
RatingResponse ratingResponse = new RatingResponse
{
Average = average.Average,
StarsFive = average.StarsFive,
StarsFour = average.StarsFour,
StarsThree = average.StarsThree,
StarsTwo = average.StarsTwo,
StarsOne = average.StarsOne,
TotalCount = wrapper.Range.Total
};

Expand Down
15 changes: 15 additions & 0 deletions dotnet/Models/RatingResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ public class RatingResponse
[JsonProperty("average")]
public decimal Average { get; set; }

[JsonProperty("starsFive")]
public int StarsFive { get; set; }

[JsonProperty("starsFour")]
public int StarsFour { get; set; }

[JsonProperty("starsThree")]
public int StarsThree { get; set; }

[JsonProperty("starsTwo")]
public int StarsTwo { get; set; }

[JsonProperty("starsOne")]
public int StarsOne { get; set; }

[JsonProperty("totalCount")]
public long TotalCount { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Services/ProductReviewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public async Task<AverageCount> GetAverageRatingByProductId(string productId)

}

AverageCount avergae = new AverageCount
AverageCount average = new AverageCount
{
Average = decimal.Round(averageRating, 2, MidpointRounding.AwayFromZero),
StarsFive = stars5,
Expand All @@ -172,7 +172,7 @@ public async Task<AverageCount> GetAverageRatingByProductId(string productId)
StarsOne = stars1,
Total = numberOfReviews
};
return avergae;
return average;
}

public async Task<Review> GetReview(string Id)
Expand Down

0 comments on commit d58c39a

Please sign in to comment.