Added enpoint to add summit venue floor
POST /api/v1/summits/{id}/locations/venues/{venue_id}/floors Payload * name (required|string|max:50) * number (required|integer) * description (sometimes|string) Change-Id: Ib2773ed9f9280c593051779ab1c50ee8fd9bf330
This commit is contained in:
parent
e3ea12ff97
commit
b66129b7cd
@ -782,6 +782,55 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $venue_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function addVenueFloor($summit_id, $venue_id){
|
||||
try {
|
||||
if(!Request::isJson()) return $this->error403();
|
||||
$payload = Input::json()->all();
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$payload['class_name'] = SummitAirport::ClassName;
|
||||
$rules = [
|
||||
'name' => 'required|string|max:50',
|
||||
'number' => 'required|integer',
|
||||
'description' => 'sometimes|string',
|
||||
];
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$floor = $this->location_service->addVenueFloor($summit, $venue_id, $payload);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($floor)->serialize());
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Location Endpoints
|
||||
*/
|
||||
|
@ -290,6 +290,11 @@ Route::group([
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addVenue']);
|
||||
Route::group(['prefix' => '{venue_id}'], function () {
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateVenue']);
|
||||
|
||||
Route::group(['prefix' => 'floors'], function () {
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addVenueFloor']);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use models\summit\SummitVenueFloor;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
use ModelSerializers\SilverStripeSerializer;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
@ -39,17 +40,21 @@ final class SummitVenueFloorSerializer extends SilverStripeSerializer
|
||||
{
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$floor = $this->object;
|
||||
|
||||
if(!$floor instanceof SummitVenueFloor) return [];
|
||||
|
||||
// floor image
|
||||
$values['image']= ($floor->getImage() !== null) ?
|
||||
Config::get("server.assets_base_url", 'https://www.openstack.org/').$floor->getImage()->getFilename()
|
||||
: null;
|
||||
// rooms
|
||||
$rooms = [];
|
||||
$rooms = [];
|
||||
$expand_rooms = !empty($expand) && strstr('rooms',$expand) !== false;
|
||||
|
||||
foreach($floor->getRooms() as $room)
|
||||
{
|
||||
|
||||
$rooms[] = $expand_rooms ?SerializerRegistry::getInstance()->getSerializer($room)->serialize($expand, $fields, $relations, $params) :
|
||||
$rooms[] = $expand_rooms ? SerializerRegistry::getInstance()->getSerializer($room)->serialize($expand, $fields, $relations, $params) :
|
||||
intval($room->getId());
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
<?php namespace App\Models\Foundation\Summit\Factories;
|
||||
/**
|
||||
* Copyright 2018 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use models\summit\SummitVenueFloor;
|
||||
/**
|
||||
* Class SummitVenueFloorFactory
|
||||
* @package App\Models\Foundation\Summit\Factories
|
||||
*/
|
||||
final class SummitVenueFloorFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
* @return SummitVenueFloor
|
||||
*/
|
||||
static public function build(array $data){
|
||||
return self::populate(new SummitVenueFloor, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitVenueFloor $floor
|
||||
* @param array $data
|
||||
* @return SummitVenueFloor
|
||||
*/
|
||||
static public function populate(SummitVenueFloor $floor, array $data){
|
||||
|
||||
if(isset($data['name']))
|
||||
$floor->setName(trim($data['name']));
|
||||
|
||||
if(isset($data['description']))
|
||||
$floor->setDescription(trim($data['description']));
|
||||
|
||||
if(isset($data['number']))
|
||||
$floor->setNumber(intval($data['number']));
|
||||
|
||||
return $floor;
|
||||
}
|
||||
}
|
@ -58,6 +58,11 @@ class SummitVenue extends SummitGeoLocatedLocation
|
||||
*/
|
||||
private $floors;
|
||||
|
||||
public function addFloor(SummitVenueFloor $floor){
|
||||
$this->floors->add($floor);
|
||||
$floor->setVenue($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -125,4 +130,26 @@ class SummitVenue extends SummitGeoLocatedLocation
|
||||
return array_merge(SummitGeoLocatedLocation::getMetadata(), self::$metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $floor_name
|
||||
* @return SummitVenueFloor|null
|
||||
*/
|
||||
public function getFloorByName($floor_name){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('name', trim($floor_name)));
|
||||
$floor = $this->floors->matching($criteria)->first();
|
||||
return $floor === false ? null:$floor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $floor_number
|
||||
* @return SummitVenueFloor|null
|
||||
*/
|
||||
public function getFloorByNumber($floor_number){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('number', intval($floor_number)));
|
||||
$floor = $this->floors->matching($criteria)->first();
|
||||
return $floor === false ? null:$floor;
|
||||
}
|
||||
|
||||
}
|
@ -11,13 +11,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Query;
|
||||
use models\main\File;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="SummitVenueFloor")
|
||||
@ -26,13 +24,6 @@ use models\utils\SilverstripeBaseModel;
|
||||
*/
|
||||
class SummitVenueFloor extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName(){
|
||||
return 'SummitVenueFloor';
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Name", type="string")
|
||||
*/
|
||||
@ -43,6 +34,39 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Number", type="integer")
|
||||
*/
|
||||
private $number;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="models\summit\SummitVenue", inversedBy="floors")
|
||||
* @ORM\JoinColumn(name="VenueID", referencedColumnName="ID")
|
||||
* @var SummitVenue
|
||||
*/
|
||||
private $venue;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitVenueRoom", mappedBy="floor", cascade={"persist"})
|
||||
* @var SummitVenueRoom[]
|
||||
*/
|
||||
private $rooms;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File", fetch="EAGER")
|
||||
* @ORM\JoinColumn(name="ImageID", referencedColumnName="ID")
|
||||
* @var File
|
||||
*/
|
||||
private $image;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName(){
|
||||
return 'SummitVenueFloor';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@ -111,18 +135,6 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Number", type="integer")
|
||||
*/
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File", fetch="EAGER")
|
||||
* @ORM\JoinColumn(name="ImageID", referencedColumnName="ID")
|
||||
* @var File
|
||||
*/
|
||||
private $image;
|
||||
|
||||
/**
|
||||
* @return File
|
||||
*/
|
||||
@ -131,20 +143,6 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="models\summit\SummitVenue", inversedBy="floors")
|
||||
* @ORM\JoinColumn(name="VenueID", referencedColumnName="ID")
|
||||
* @var SummitVenue
|
||||
*/
|
||||
private $venue;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitVenueRoom", mappedBy="floor", cascade={"persist"})
|
||||
* @var SummitVenueRoom[]
|
||||
*/
|
||||
private $rooms;
|
||||
|
||||
/**
|
||||
* @return SummitVenueRoom[]
|
||||
*/
|
||||
@ -158,4 +156,20 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
||||
$this->rooms = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitVenue $venue
|
||||
*/
|
||||
public function setVenue($venue)
|
||||
{
|
||||
$this->venue = $venue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param File $image
|
||||
*/
|
||||
public function setImage($image)
|
||||
{
|
||||
$this->image = $image;
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitAbstractLocation;
|
||||
use models\summit\SummitVenue;
|
||||
use models\summit\SummitVenueFloor;
|
||||
/**
|
||||
* Interface ILocationService
|
||||
* @package App\Services\Model
|
||||
@ -49,4 +49,35 @@ interface ILocationService
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteLocation(Summit $summit, $location_id);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param array $data
|
||||
* @return SummitVenueFloor
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addVenueFloor(Summit $summit, $venue_id, array $data);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $floor_id
|
||||
* @param array $data
|
||||
* @return SummitVenueFloor
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateVenueFloor(Summit $summit, $venue_id, $floor_id, array $data);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $floor_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteVenueFloor(Summit $summit, $venue_id, $floor_id);
|
||||
}
|
@ -16,6 +16,7 @@ use App\Events\LocationDeleted;
|
||||
use App\Events\LocationInserted;
|
||||
use App\Events\LocationUpdated;
|
||||
use App\Models\Foundation\Summit\Factories\SummitLocationFactory;
|
||||
use App\Models\Foundation\Summit\Factories\SummitVenueFloorFactory;
|
||||
use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository;
|
||||
use App\Services\Apis\GeoCodingApiException;
|
||||
use App\Services\Apis\IGeoCodingAPI;
|
||||
@ -28,7 +29,8 @@ use models\exceptions\ValidationException;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitAbstractLocation;
|
||||
use models\summit\SummitGeoLocatedLocation;
|
||||
|
||||
use models\summit\SummitVenue;
|
||||
use models\summit\SummitVenueFloor;
|
||||
/**
|
||||
* Class LocationService
|
||||
* @package App\Services\Model
|
||||
@ -297,4 +299,116 @@ final class LocationService implements ILocationService
|
||||
$summit->removeLocation($location);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param array $data
|
||||
* @return SummitVenueFloor
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addVenueFloor(Summit $summit, $venue_id, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $venue_id, $data) {
|
||||
|
||||
$venue = $summit->getLocation($venue_id);
|
||||
|
||||
if(is_null($venue)){
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.addVenueFloor.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(!$venue instanceof SummitVenue){
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.addVenueFloor.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$former_floor = $venue->getFloorByName(trim($data['name']));
|
||||
|
||||
if(!is_null($former_floor)){
|
||||
throw new ValidationException(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.addVenueFloor.FloorNameAlreadyExists',
|
||||
[
|
||||
'venue_id' => $venue_id,
|
||||
'floor_name' => trim($data['name'])
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$former_floor = $venue->getFloorByNumber(intval($data['number']));
|
||||
|
||||
if(!is_null($former_floor)){
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.addVenueFloor.FloorNumberAlreadyExists',
|
||||
[
|
||||
'venue_id' => $venue_id,
|
||||
'floor_number' => intval($data['number'])
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$floor = SummitVenueFloorFactory::build($data);
|
||||
|
||||
$venue->addFloor($floor);
|
||||
|
||||
return $floor;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $floor_id
|
||||
* @param array $data
|
||||
* @return SummitVenueFloor
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateVenueFloor(Summit $summit, $venue_id, $floor_id, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $venue_id, $floor_id, $data) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $floor_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteVenueFloor(Summit $summit, $venue_id, $floor_id)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $venue_id, $floor_id) {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
@ -536,6 +536,33 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-venue-floor',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
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)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-external-locations',
|
||||
'route' => '/api/v1/summits/{id}/locations/external-locations',
|
||||
|
@ -34,4 +34,7 @@ return [
|
||||
'LocationService.updateLocation.LocationNameAlreadyExists' => 'there is already another location with same name for summit :summit_id',
|
||||
'LocationService.updateLocation.LocationNotFoundOnSummit' => 'location :location_id not found on summit :summit_id',
|
||||
'LocationService.updateLocation.ClassNameMissMatch' => 'location :location_id on summit :summit_id does not belongs to class name :class_name',
|
||||
'LocationService.addVenueFloor.VenueNotFound' => 'venue :venue_id not found on summit :summit_id',
|
||||
'LocationService.addVenueFloor.FloorNameAlreadyExists' => 'floor name :floor_name already belongs to another floor on venue :venue_id',
|
||||
'LocationService.addVenueFloor.FloorNumberAlreadyExists' => 'floor number :floor_number already belongs to another floor on venue :venue_id',
|
||||
];
|
@ -691,4 +691,39 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
|
||||
public function testAddVenueFloor($summit_id = 23, $venue_id = 292){
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id
|
||||
];
|
||||
|
||||
$data = [
|
||||
'name' => 'test floor',
|
||||
'description' => 'test floor',
|
||||
'number' => -1
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitLocationsApiController@addVenueFloor",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$floor = json_decode($content);
|
||||
$this->assertTrue(!is_null($floor));
|
||||
return $floor;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user