Added endpoints to get venue rooms and venue floors by id
GET /api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id} GET /api/v1/summits/{id}/locations/venues/{venue_id}/rooms/{room_id} GET /api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}/rooms/{room_id} Change-Id: I154e395b2d34003a478f1d7a9b9acd1539406c84
This commit is contained in:
parent
5d883d96d8
commit
ec4a3474ad
|
@ -27,6 +27,7 @@ use models\summit\IEventFeedbackRepository;
|
|||
use models\summit\ISpeakerRepository;
|
||||
use models\summit\ISummitEventRepository;
|
||||
use models\summit\ISummitRepository;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitAirport;
|
||||
use models\summit\SummitExternalLocation;
|
||||
use models\summit\SummitHotel;
|
||||
|
@ -389,6 +390,11 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
if (is_null($location)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
if (!Summit::isPrimaryLocation($location)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($location)->serialize($expand,[], $relations));
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
|
@ -552,6 +558,161 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $venue_id
|
||||
* @param $floor_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVenueFloor($summit_id, $venue_id, $floor_id){
|
||||
try {
|
||||
|
||||
$expand = Request::input('expand', '');
|
||||
$relations = Request::input('relations', '');
|
||||
$relations = !empty($relations) ? explode(',', $relations) : [];
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$venue = $summit->getLocation($venue_id);
|
||||
|
||||
if (is_null($venue)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
if (!$venue instanceof SummitVenue) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
$floor = $venue->getFloor($floor_id);
|
||||
|
||||
if (is_null($floor)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($floor)->serialize($expand,[], $relations));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $venue_id
|
||||
* @param $room_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVenueRoom($summit_id, $venue_id, $room_id){
|
||||
try {
|
||||
|
||||
$expand = Request::input('expand', '');
|
||||
$relations = Request::input('relations', '');
|
||||
$relations = !empty($relations) ? explode(',', $relations) : [];
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$venue = $summit->getLocation($venue_id);
|
||||
|
||||
if (is_null($venue)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
if (!$venue instanceof SummitVenue) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
|
||||
$room = $venue->getRoom($room_id);
|
||||
|
||||
if (is_null($room)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($room)->serialize($expand,[], $relations));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $venue_id
|
||||
* @param $floor_id
|
||||
* @param $room_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVenueFloorRoom($summit_id, $venue_id, $floor_id, $room_id){
|
||||
try {
|
||||
|
||||
$expand = Request::input('expand', '');
|
||||
$relations = Request::input('relations', '');
|
||||
$relations = !empty($relations) ? explode(',', $relations) : [];
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$venue = $summit->getLocation($venue_id);
|
||||
|
||||
if (is_null($venue)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
if (!$venue instanceof SummitVenue) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
$floor = $venue->getFloor($floor_id);
|
||||
|
||||
if (is_null($floor)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
$room = $floor->getRoom($room_id);
|
||||
|
||||
if (is_null($room)) {
|
||||
return $this->error404();
|
||||
}
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($room)->serialize($expand,[], $relations));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Add Locations Endpoints
|
||||
*/
|
||||
|
|
|
@ -303,11 +303,13 @@ Route::group([
|
|||
Route::group(['prefix' => 'floors'], function () {
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addVenueFloor']);
|
||||
Route::group(['prefix' => '{floor_id}'], function () {
|
||||
Route::get('', 'OAuth2SummitLocationsApiController@getVenueFloor');
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateVenueFloor']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@deleteVenueFloor']);
|
||||
Route::group(['prefix' => 'rooms'], function () {
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addVenueFloorRoom']);
|
||||
Route::group(['prefix' => '{room_id}'], function () {
|
||||
Route::get('', 'OAuth2SummitLocationsApiController@getVenueFloorRoom');
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateVenueFloorRoom']);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -152,6 +152,17 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
|||
return $this->rooms;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $room_id
|
||||
* @return SummitVenueRoom
|
||||
*/
|
||||
public function getRoom($room_id){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('id', intval($room_id)));
|
||||
$room = $this->rooms->matching($criteria)->first();
|
||||
return $room === false ? null : $room;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
|
|
@ -745,6 +745,17 @@ class Summit extends SilverstripeBaseModel
|
|||
return $location === false ? null : $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitAbstractLocation $location
|
||||
* @return bool
|
||||
*/
|
||||
static public function isPrimaryLocation(SummitAbstractLocation $location){
|
||||
return ($location instanceof SummitVenue
|
||||
|| $location instanceof SummitHotel
|
||||
|| $location instanceof SummitAirport
|
||||
|| $location instanceof SummitExternalLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SummitEventType[]
|
||||
*/
|
||||
|
@ -1682,7 +1693,7 @@ SQL;
|
|||
$filtered_locations = [];
|
||||
|
||||
foreach($this->locations->matching($criteria)->toArray() as $l){
|
||||
if($l instanceof SummitVenue || $l instanceof SummitHotel || $l instanceof SummitAirport || $l instanceof SummitExternalLocation)
|
||||
if(Summit::isPrimaryLocation($l))
|
||||
$filtered_locations[] = $l;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,8 @@ final class AdminActionsCalendarSyncProcessingService
|
|||
foreach ($page_response->getItems() as $schedule_event){
|
||||
if(!$schedule_event instanceof ScheduleCalendarSyncInfo) continue;
|
||||
$work_request = new MemberEventScheduleSummitActionSyncWorkRequest();
|
||||
$work_request->setType($request->getType());
|
||||
// always is update no matter what
|
||||
$work_request->setType(AbstractCalendarSyncWorkRequest::TypeUpdate);
|
||||
$work_request->setCalendarSyncInfo($schedule_event->getCalendarSyncInfo());
|
||||
$work_request->setOwner($schedule_event->getMember());
|
||||
$work_request->setSummitEventId($schedule_event->getSummitEvent()->getId());
|
||||
|
|
|
@ -204,6 +204,19 @@ final class LocationService implements ILocationService
|
|||
);
|
||||
}
|
||||
|
||||
if(!Summit::isPrimaryLocation($location)){
|
||||
throw new EntityNotFoundException(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.updateLocation.LocationNotFoundOnSummit',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'location_id' => $location_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($location->getClassName() != $data['class_name']) {
|
||||
throw new ValidationException(
|
||||
trans
|
||||
|
@ -297,11 +310,7 @@ final class LocationService implements ILocationService
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!($location instanceof SummitVenue
|
||||
|| $location instanceof SummitHotel
|
||||
|| $location instanceof SummitAirport
|
||||
|| $location instanceof SummitExternalLocation)) {
|
||||
if(!Summit::isPrimaryLocation($location)){
|
||||
throw new EntityNotFoundException(
|
||||
trans
|
||||
(
|
||||
|
|
|
@ -536,6 +536,16 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
// floors
|
||||
[
|
||||
'name' => 'get-venue-floor',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-venue-floor',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors',
|
||||
|
@ -545,6 +555,34 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-venue-floor',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-venue-floor',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
// rooms
|
||||
[
|
||||
'name' => 'get-venue-room',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/rooms/{room_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-venue-room',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/rooms',
|
||||
|
@ -572,6 +610,16 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
// floor rooms
|
||||
[
|
||||
'name' => 'get-venue-floor-room',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}/rooms/{room_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-venue-floor-room',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}/rooms',
|
||||
|
@ -590,24 +638,7 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-venue-floor',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-venue-floor',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
// external locations
|
||||
[
|
||||
'name' => 'get-external-locations',
|
||||
'route' => '/api/v1/summits/{id}/locations/external-locations',
|
||||
|
|
|
@ -976,4 +976,67 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
|||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
|
||||
public function testGetFloorById($summit_id = 23, $venue_id = 292, $floor_id = 23){
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id,
|
||||
'floor_id' => $floor_id,
|
||||
'expand' => 'rooms'
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitLocationsApiController@getVenueFloor",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(200);
|
||||
$floor = json_decode($content);
|
||||
$this->assertTrue(!is_null($floor));
|
||||
return $floor;
|
||||
}
|
||||
|
||||
public function testGetVenueFloorRoomById($summit_id = 23, $venue_id = 292, $floor_id = 23, $room_id = 309){
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id,
|
||||
'floor_id' => $floor_id,
|
||||
'room_id' => $room_id,
|
||||
'expand' => 'floor,venue'
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitLocationsApiController@getVenueFloorRoom",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(200);
|
||||
$room = json_decode($content);
|
||||
$this->assertTrue(!is_null($room));
|
||||
return $room;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue