Resolve "Rider Rating API" #828
2 changed files with 63 additions and 0 deletions
|
|
@ -84,3 +84,8 @@ api_rider_status:
|
||||||
path: /api/rider
|
path: /api/rider
|
||||||
controller: App\Controller\APIController::getRiderStatus
|
controller: App\Controller\APIController::getRiderStatus
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
|
api_rider_rating_add:
|
||||||
|
path: /api/rider_rating
|
||||||
|
controller: App\Controller\APIController::addRiderRating
|
||||||
|
methods: [POST]
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ use App\Entity\CustomerVehicle;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
use App\Entity\Promo;
|
use App\Entity\Promo;
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
|
use App\Entity\RiderRating;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
|
|
@ -1063,4 +1064,61 @@ class APIController extends Controller
|
||||||
|
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addRiderRating(Request $req)
|
||||||
|
{
|
||||||
|
$required_params = [
|
||||||
|
'jo_id',
|
||||||
|
'rating',
|
||||||
|
];
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||||
|
if ($res->isError())
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$cust = $this->session->getCustomer();
|
||||||
|
if ($cust == null)
|
||||||
|
{
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorMessage('No customer information found');
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get job order
|
||||||
|
$jo_id = $req->request->get('jo_id');
|
||||||
|
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
||||||
|
if ($jo == null)
|
||||||
|
{
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorMessage('No job order found');
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rider
|
||||||
|
$rider = $jo->getRider();
|
||||||
|
if ($rider == null)
|
||||||
|
{
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorMessage('No rider found');
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: check job order status if it's
|
||||||
|
|
||||||
|
// add rider rating
|
||||||
|
$rating_num = $req->request->get('rating');
|
||||||
|
$rating = new RiderRating();
|
||||||
|
$rating->setRider($rider)
|
||||||
|
->setCustomer($cust)
|
||||||
|
->setJobOrder($jo)
|
||||||
|
->setRating($rating_num);
|
||||||
|
|
||||||
|
$em->persist($rating);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$res->setData([]);
|
||||||
|
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue