Add api support for motolite events #730
This commit is contained in:
parent
9c36baa3d3
commit
58eafabdcf
4 changed files with 182 additions and 0 deletions
|
|
@ -230,3 +230,9 @@ apiv2_customer_hash_get:
|
||||||
# path: /apiv2/job_orders/completed
|
# path: /apiv2/job_orders/completed
|
||||||
# controller: App\Controller\CustomerAppAPI\JobOrderController::getCompletedJobOrders
|
# controller: App\Controller\CustomerAppAPI\JobOrderController::getCompletedJobOrders
|
||||||
# methods: [GET]
|
# methods: [GET]
|
||||||
|
|
||||||
|
# motolite events
|
||||||
|
apiv2_motolite_events:
|
||||||
|
path: /apiv2/motolite_events
|
||||||
|
controller: App\Controller\CustomerAppAPI\MotoliteEventController:getEvents
|
||||||
|
methods: [GET]
|
||||||
46
src/Controller/CustomerAppAPI/MotoliteEventController.php
Normal file
46
src/Controller/CustomerAppAPI/MotoliteEventController.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\MotoliteEvent;
|
||||||
|
use App\Ramcar\MotoliteEventType;
|
||||||
|
|
||||||
|
class MotoliteEventController extends ApiController
|
||||||
|
{
|
||||||
|
public function getEvents(Request $req)
|
||||||
|
{
|
||||||
|
// validate params
|
||||||
|
$validity = $this->validateRequest($req);
|
||||||
|
|
||||||
|
if (!$validity['is_valid']) {
|
||||||
|
return new ApiResponse(false, $validity['error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all events
|
||||||
|
$events = $this->em->getRepository(MotoliteEvent::class)
|
||||||
|
->findBy([], ['event_time', 'asc']);
|
||||||
|
|
||||||
|
if (empty($results)) {
|
||||||
|
return new ApiResponse(false, 'No events available.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$events = [];
|
||||||
|
foreach ($results as $result) {
|
||||||
|
$events[] = [
|
||||||
|
'id' => $result->getID(),
|
||||||
|
'name' => $result->getName(),
|
||||||
|
'event_type' => MotoliteEventType::getName($result->getEventType()),
|
||||||
|
'url' => $result->getUrl(),
|
||||||
|
'image_file' => $result->getImageFile(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return new ApiResponse(true, '', [
|
||||||
|
'events' => $events,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
114
src/Entity/MotoliteEvent.php
Normal file
114
src/Entity/MotoliteEvent.php
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
use Symfony\Component\HttpFoundation\File\File;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="motolite_event")
|
||||||
|
*/
|
||||||
|
class MotoliteEvent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @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 $event_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime")
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $event_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string")
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string")
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
* @Assert\File(mimeTypes={"image/png", "image/jpeg", "image/gif", "image/webp"})
|
||||||
|
*/
|
||||||
|
protected $image_file;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->event_time = new DateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventType($event_type)
|
||||||
|
{
|
||||||
|
$this->event_type = $event_type;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventType()
|
||||||
|
{
|
||||||
|
return $this->event_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventTime($event_time)
|
||||||
|
{
|
||||||
|
$this->event_time = $event_time;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUrl($url)
|
||||||
|
{
|
||||||
|
$this->url = $url;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl()
|
||||||
|
{
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventTime()
|
||||||
|
{
|
||||||
|
return $this->event_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setImageFile(File $image_file = null)
|
||||||
|
{
|
||||||
|
$this->image_file = $image_file;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getImageFile()
|
||||||
|
{
|
||||||
|
return $this->image_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/Ramcar/MotoliteEventType.php
Normal file
16
src/Ramcar/MotoliteEventType.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ramcar;
|
||||||
|
|
||||||
|
class MotoliteEventType extends NameValue
|
||||||
|
{
|
||||||
|
const EVENT = 'event';
|
||||||
|
const News = 'news';
|
||||||
|
const Blog = 'blog';
|
||||||
|
|
||||||
|
const COLLECTION = [
|
||||||
|
'event' => 'Event',
|
||||||
|
'news' => 'News',
|
||||||
|
'blog' => 'Blog',
|
||||||
|
];
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue