Add rider rating average computation #730

This commit is contained in:
Ramon Gutierrez 2023-05-22 13:00:54 +08:00
parent c2c4be8b7b
commit 33e6994aaa
2 changed files with 16 additions and 2 deletions

View file

@ -230,7 +230,10 @@ class RiderController extends ApiController
$this->em->persist($rating);
$this->em->flush();
// TODO: set average rating in rider entity
// TODO: preliminary rating computation on the entity for now
$rider->updateRatingAverage();
$this->em->persist($rider);
$this->em->flush();
// response
return new ApiResponse();

View file

@ -81,7 +81,7 @@ class Rider
// current rating of rider
/**
* @ORM\Column(type="integer")
* @ORM\Column(type="float")
*/
protected $curr_rating;
@ -241,6 +241,17 @@ class Rider
return $this->image_file;
}
public function updateRatingAverage()
{
$total = 0;
foreach ($this->ratings as $rating) {
$total += $rating->getRating();
}
$this->setCurrentRating(round($total / $this->ratings->count(), 2));
}
public function setCurrentRating($rating)
{
$this->curr_rating = $rating;