Add review tags api #730
This commit is contained in:
parent
a821c42f0d
commit
e235026197
3 changed files with 119 additions and 2 deletions
|
|
@ -234,5 +234,14 @@ apiv2_customer_hash_get:
|
||||||
# motolite events
|
# motolite events
|
||||||
apiv2_motolite_events:
|
apiv2_motolite_events:
|
||||||
path: /apiv2/motolite_events
|
path: /apiv2/motolite_events
|
||||||
controller: App\Controller\CustomerAppAPI\MotoliteEventController:getEvents
|
controller: App\Controller\CustomerAppAPI\MotoliteEventController::getEvents
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
|
# review tags
|
||||||
|
apiv2_partner_review_tags:
|
||||||
|
path: /apiv2/review_tags/partner
|
||||||
|
controller: App\Controller\CustomerAppAPI\ReviewTagController::getPartnerReviewTags
|
||||||
|
|
||||||
|
apiv2_rider_review_tags:
|
||||||
|
path: /apiv2/review_tags/rider
|
||||||
|
controller: App\Controller\CustomerAppAPI\ReviewTagController::getPartnerReviewTags
|
||||||
46
src/Controller/CustomerAppAPI/ReviewTagController.php
Normal file
46
src/Controller/CustomerAppAPI/ReviewTagController.php
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\CustomerAppAPI;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
||||||
|
|
||||||
|
use App\Entity\ReviewTag;
|
||||||
|
|
||||||
|
class ReviewTagController extends ApiController
|
||||||
|
{
|
||||||
|
public function getPartnerReviewTags(Request $req)
|
||||||
|
{
|
||||||
|
return $this->getTags($req, "partner");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRiderReviewTags(Request $req)
|
||||||
|
{
|
||||||
|
return $this->getTags($req, "rider");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTags(Request $req, $tag_type)
|
||||||
|
{
|
||||||
|
// validate params
|
||||||
|
$validity = $this->validateRequest($req);
|
||||||
|
|
||||||
|
if (!$validity['is_valid']) {
|
||||||
|
return new ApiResponse(false, $validity['error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get manufacturer list
|
||||||
|
$tags = $this->em->getRepository(ReviewTag::class)->findBy(['type' => $tag_type], ['name' => 'asc']);
|
||||||
|
$tag_list = [];
|
||||||
|
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tag_list[] = [
|
||||||
|
'id' => $tag->getID(),
|
||||||
|
'name' => $tag->getName(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ApiResponse(true, '', [
|
||||||
|
'tags' => $tag_list,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
62
src/Entity/ReviewTag.php
Normal file
62
src/Entity/ReviewTag.php
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="review_tag")
|
||||||
|
*/
|
||||||
|
class ReviewTag
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $type;
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type)
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue