New Locations endpoints

added endpoints to get locations by type:
* Venue
* External Location
* Hotel
* Airport

Change-Id: I08816d1f3a1dd0020290775f8be663df6ee387c8
This commit is contained in:
Sebastian Marcet 2016-09-26 17:18:56 -03:00
parent e1334a0f49
commit bf35c0c927
6 changed files with 311 additions and 3 deletions

View File

@ -262,4 +262,104 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
}
}
/**
* @param $summit_id
* @return mixed
*/
public function getVenues($summit_id)
{
try {
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
if (is_null($summit)) return $this->error404();
//locations
$locations = array();
foreach ($summit->getVenues() as $location)
{
$locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize();
}
return $this->ok($locations);
} catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
/**
* @param $summit_id
* @return mixed
*/
public function getExternalLocations($summit_id)
{
try {
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
if (is_null($summit)) return $this->error404();
//locations
$locations = array();
foreach ($summit->getExternalLocations() as $location)
{
$locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize();
}
return $this->ok($locations);
} catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
/**
* @param $summit_id
* @return mixed
*/
public function getHotels($summit_id)
{
try {
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
if (is_null($summit)) return $this->error404();
//locations
$locations = array();
foreach ($summit->getHotels() as $location)
{
$locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize();
}
return $this->ok($locations);
} catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
/**
* @param $summit_id
* @return mixed
*/
public function getAirports($summit_id)
{
try {
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
if (is_null($summit)) return $this->error404();
//locations
$locations = array();
foreach ($summit->getAirports() as $location)
{
$locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize();
}
return $this->ok($locations);
} catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
}

View File

@ -129,7 +129,10 @@ Route::group(array(
Route::group(array('prefix' => 'locations'), function () {
Route::get('', 'OAuth2SummitLocationsApiController@getLocations');
Route::get('/venues', 'OAuth2SummitLocationsApiController@getVenues');
Route::get('/external-locations', 'OAuth2SummitLocationsApiController@getExternalLocations');
Route::get('/hotels', 'OAuth2SummitLocationsApiController@getHotels');
Route::get('/airports', 'OAuth2SummitLocationsApiController@getAirports');
Route::group(array('prefix' => '{location_id}'), function () {
Route::get('', 'OAuth2SummitLocationsApiController@getLocation');
Route::get('/events/published','OAuth2SummitLocationsApiController@getLocationEvents');

View File

@ -37,20 +37,22 @@ final class SummitVenueSerializer extends SummitGeoLocatedLocationSerializer
$values = parent::serialize($expand, $fields, $relations, $params);
$venue = $this->object;
// rooms
$rooms = array();
$rooms = [];
foreach($venue->getRooms() as $room)
{
$rooms[] = SerializerRegistry::getInstance()->getSerializer($room)->serialize($expand, $fields, $relations, $params);
}
if(count($rooms) > 0)
$values['rooms'] = $rooms;
// floors
$floors = array();
$floors = [];
foreach($venue->getFloors() as $floor)
{
$floors[] = SerializerRegistry::getInstance()->getSerializer($floor)->serialize($expand, $fields, $relations, $params);
}
if(count($floors) > 0)
$values['floors'] = $floors;

View File

@ -330,6 +330,33 @@ class Summit extends SilverstripeBaseModel
});
}
/**
* @return SummitHotel[]
*/
public function getHotels(){
return $this->locations->filter(function($e){
return $e instanceof SummitHotel;
});
}
/**
* @return SummitAirport[]
*/
public function getAirports(){
return $this->locations->filter(function($e){
return $e instanceof SummitAirport;
});
}
/**
* @return SummitExternalLocation[]
*/
public function getExternalLocations(){
return $this->locations->filter(function($e){
return $e->getClassName() == 'SummitExternalLocation';
});
}
/**
* @return ArrayCollection
*/

View File

@ -472,6 +472,46 @@ class ApiEndpointsSeeder extends Seeder
)
);
ApiEndpoint::create(
array(
'name' => 'get-venues',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/venues',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
array(
'name' => 'get-external-locations',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/external-locations',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
array(
'name' => 'get-hotels',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/hotels',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
array(
'name' => 'get-airports',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/airports',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
array(
'name' => 'get-location',
@ -653,6 +693,14 @@ class ApiEndpointsSeeder extends Seeder
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-locations')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-venues')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-hotels')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-airports')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-external-locations')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-event-types')->first();
@ -663,6 +711,7 @@ class ApiEndpointsSeeder extends Seeder
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
// read external orders
$endpoint = ApiEndpoint::where('name', '=', 'get-external-order')->first();

View File

@ -1451,6 +1451,133 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$this->assertTrue(!is_null($locations));
}
public function testGetCurrentSummitVenues()
{
$params = array
(
'id' => 'current',
);
$headers = array
(
"HTTP_Authorization" => " Bearer " .$this->access_token,
"CONTENT_TYPE" => "application/json"
);
$response = $this->action
(
"GET",
"OAuth2SummitLocationsApiController@getVenues",
$params,
array(),
array(),
array(),
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$locations = json_decode($content);
$this->assertTrue(!is_null($locations));
}
public function testGetCurrentSummitHotels()
{
$params = array
(
'id' => 'current',
);
$headers = array
(
"HTTP_Authorization" => " Bearer " .$this->access_token,
"CONTENT_TYPE" => "application/json"
);
$response = $this->action
(
"GET",
"OAuth2SummitLocationsApiController@getHotels",
$params,
array(),
array(),
array(),
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$locations = json_decode($content);
$this->assertTrue(!is_null($locations));
}
public function testGetCurrentSummitAirports()
{
$params = array
(
'id' => 'current',
);
$headers = array
(
"HTTP_Authorization" => " Bearer " .$this->access_token,
"CONTENT_TYPE" => "application/json"
);
$response = $this->action
(
"GET",
"OAuth2SummitLocationsApiController@getAirports",
$params,
array(),
array(),
array(),
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$locations = json_decode($content);
$this->assertTrue(!is_null($locations));
}
public function testGetCurrentSummitExternalLocations()
{
$params = array
(
'id' => 'current',
);
$headers = array
(
"HTTP_Authorization" => " Bearer " .$this->access_token,
"CONTENT_TYPE" => "application/json"
);
$response = $this->action
(
"GET",
"OAuth2SummitLocationsApiController@getExternalLocations",
$params,
array(),
array(),
array(),
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$locations = json_decode($content);
$this->assertTrue(!is_null($locations));
}
public function testGetCurrentSummitLocation()
{
$params = array