Update Summit API
* now summit list return only the summit marked as available for api. that allows us to control which summits will be public availbable ( instead of everything as formerly) * also current summit query was updated to check the api availability flag. Change-Id: Ib344d7fe899a5802c195326fbbb5028f4807ebc0
This commit is contained in:
parent
c92167b0b3
commit
a14a4e8ec9
@ -16,6 +16,7 @@ use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\oauth2\IResourceServerContext;
|
||||
@ -76,10 +77,11 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController
|
||||
public function getSummits()
|
||||
{
|
||||
try {
|
||||
$summits = array();
|
||||
|
||||
foreach($this->repository->getAll() as $summit){
|
||||
$summits[] = SerializerRegistry::getInstance()->getSerializer($summit)->serialize();
|
||||
$summits = [];
|
||||
|
||||
foreach($this->repository->getAvailables() as $summit){
|
||||
$summits[] = SerializerRegistry::getInstance()->getSerializer($summit)->serialize(Input::get('expand',''));
|
||||
}
|
||||
|
||||
$response = new PagingResponse
|
||||
@ -90,6 +92,7 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController
|
||||
1,
|
||||
$summits
|
||||
);
|
||||
|
||||
return $this->ok($response->toArray());
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
@ -335,6 +338,11 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $external_order_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExternalOrder($summit_id, $external_order_id){
|
||||
try {
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
|
||||
@ -356,6 +364,12 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $external_order_id
|
||||
* @param $external_attendee_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function confirmExternalOrderAttendee($summit_id, $external_order_id, $external_attendee_id){
|
||||
try {
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
|
||||
|
@ -164,7 +164,8 @@ final class OAuth2SummitAttendeesApiController extends OAuth2ProtectedController
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$attendee = CheckAttendeeStrategyFactory::build(CheckAttendeeStrategyFactory::Own, $this->resource_server_context)->check($attendee_id, $summit);
|
||||
$type = $attendee_id === 'me' ? CheckAttendeeStrategyFactory::Me : CheckAttendeeStrategyFactory::Own;
|
||||
$attendee = CheckAttendeeStrategyFactory::build($type, $this->resource_server_context)->check($attendee_id, $summit);
|
||||
if(is_null($attendee)) return $this->error404();
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($attendee)->serialize($expand));
|
||||
|
@ -134,6 +134,15 @@ final class SummitSerializer extends SilverStripeSerializer
|
||||
$values['speakers'] = $speakers;
|
||||
}
|
||||
break;
|
||||
case 'type':{
|
||||
if(isset($values['type_id']))
|
||||
{
|
||||
unset($values['type_id']);
|
||||
$values['type'] = $summit->hasType() ?
|
||||
SerializerRegistry::getInstance()->getSerializer($summit->getType())->serialize() : null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,4 +20,9 @@ interface ISummitRepository extends IBaseRepository
|
||||
* @return Summit
|
||||
*/
|
||||
public function getCurrent();
|
||||
|
||||
/**
|
||||
* @return Summit[]
|
||||
*/
|
||||
public function getAvailables();
|
||||
}
|
@ -169,6 +169,28 @@ class Summit extends SilverstripeBaseModel
|
||||
*/
|
||||
private $active;
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAvailableOnApi()
|
||||
{
|
||||
return $this->available_on_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $available_on_api
|
||||
*/
|
||||
public function setAvailableOnApi($available_on_api)
|
||||
{
|
||||
$this->available_on_api = $available_on_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="AvailableOnApi", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $available_on_api;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ExternalEventId", type="string")
|
||||
* @var string
|
||||
@ -186,7 +208,12 @@ class Summit extends SilverstripeBaseModel
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
try {
|
||||
return $this->type;
|
||||
}
|
||||
catch (\Exception $ex){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,6 +236,13 @@ class Summit extends SilverstripeBaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasType(){
|
||||
return $this->getTypeId() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="SummitType", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinColumn(name="TypeID", referencedColumnName="ID")
|
||||
|
@ -34,6 +34,7 @@ final class DoctrineSummitRepository extends SilverStripeDoctrineRepository impl
|
||||
->select("s")
|
||||
->from(\models\summit\Summit::class, "s")
|
||||
->where('s.active = 1')
|
||||
->andWhere('s.available_on_api = 1')
|
||||
->orderBy('s.begin_date', 'DESC')
|
||||
->getQuery()
|
||||
->setCacheable(true)
|
||||
@ -42,4 +43,20 @@ final class DoctrineSummitRepository extends SilverStripeDoctrineRepository impl
|
||||
if (count($res) == 0) return null;
|
||||
return $res[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Summit[]
|
||||
*/
|
||||
public function getAvailables()
|
||||
{
|
||||
return $this->getEntityManager()->createQueryBuilder()
|
||||
->select("s")
|
||||
->from(\models\summit\Summit::class, "s")
|
||||
->where('s.available_on_api = 1')
|
||||
->orderBy('s.begin_date', 'ASC')
|
||||
->getQuery()
|
||||
->setCacheable(true)
|
||||
->setCacheRegion("summit_region")
|
||||
->getResult();
|
||||
}
|
||||
}
|
@ -18,8 +18,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
public function testGetSummits()
|
||||
{
|
||||
|
||||
$params = array
|
||||
();
|
||||
$params = ['expand' => 'type'];
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
$response = $this->action(
|
||||
@ -96,7 +95,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
$params = array
|
||||
(
|
||||
'expand' => 'schedule,speakers',
|
||||
'id' => 22
|
||||
'id' => 7
|
||||
);
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
@ -195,13 +194,13 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
|
||||
|
||||
$params = array
|
||||
(
|
||||
'expand' => 'schedule',
|
||||
'id' => 6,
|
||||
'attendee_id' => 'me',
|
||||
'expand' => 'schedule',
|
||||
'id' => 6,
|
||||
'attendee_id' => 'me',
|
||||
'access_token' => $this->access_token
|
||||
);
|
||||
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
$headers = array("HTTP_Authorization" => " Bearer " . $this->access_token);
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitAttendeesApiController@getAttendee",
|
||||
|
Loading…
x
Reference in New Issue
Block a user