Added endpoint to update summit venue rooms
PUT /api/v1/summits/{id}/locations/venues/{venue_id}/rooms/{room_id} PUT /api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}/rooms/{room_id} Payload * name (sometimes|string:max:255) * description (sometimes|string) * override_blackouts (sometimes|boolean) * capacity (sometimes|integer:min:0) * order (sometimes|integer:min:1) * floor_id (sometimes|integer) Change-Id: Id05be351fb6378ee97c45ac07554097434a2b07c
This commit is contained in:
parent
8481288e88
commit
a50d7f9a4f
@ -17,16 +17,17 @@ use models\summit\CalendarSync\WorkQueue\AdminSummitEventActionSyncWorkRequest;
|
||||
* Class AdminSummitEventActionSyncWorkRequestPersister
|
||||
* @package App\EntityPersisters
|
||||
*/
|
||||
class AdminSummitEventActionSyncWorkRequestPersister extends BasePersister
|
||||
final class AdminSummitEventActionSyncWorkRequestPersister extends BasePersister
|
||||
{
|
||||
/**
|
||||
* @param AdminSummitEventActionSyncWorkRequest $request
|
||||
*/
|
||||
public static function persist(AdminSummitEventActionSyncWorkRequest $request){
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO AbstractCalendarSyncWorkRequest
|
||||
(`Type`, IsProcessed, ProcessedDate, Created, LastEdited, ClassName)
|
||||
VALUES (:Type, 0, NULL, NOW(), NOW(), 'AdminSummitEventActionSyncWorkRequest');
|
||||
INSERT INTO AdminScheduleSummitActionSyncWorkRequest (ID, CreatedByID) VALUES (LAST_INSERT_ID(), :CreatedByID)
|
||||
INSERT INTO AdminSummitEventActionSyncWorkRequest (ID, SummitEventID) VALUES (LAST_INSERT_ID(), :SummitEventID);
|
||||
SQL;
|
||||
|
||||
$bindings = [
|
||||
@ -43,5 +44,15 @@ SQL;
|
||||
|
||||
self::insert($sql, $bindings, $types);
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO AdminScheduleSummitActionSyncWorkRequest (ID, CreatedByID) VALUES (LAST_INSERT_ID(), :CreatedByID)
|
||||
SQL;
|
||||
self::insert($sql, $bindings, $types);
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO AdminSummitEventActionSyncWorkRequest (ID, SummitEventID) VALUES (LAST_INSERT_ID(), :SummitEventID);
|
||||
SQL;
|
||||
self::insert($sql, $bindings, $types);
|
||||
|
||||
}
|
||||
}
|
@ -11,10 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use models\summit\CalendarSync\WorkQueue\AdminSummitLocationActionSyncWorkRequest;
|
||||
|
||||
|
||||
/**
|
||||
* Class AdminSummitLocationActionSyncWorkRequestPersister
|
||||
* @package App\EntityPersisters
|
||||
@ -30,8 +27,6 @@ final class AdminSummitLocationActionSyncWorkRequestPersister extends BasePersis
|
||||
INSERT INTO AbstractCalendarSyncWorkRequest
|
||||
(`Type`, IsProcessed, ProcessedDate, Created, LastEdited, ClassName)
|
||||
VALUES (:Type, 0, NULL, NOW(), NOW(), 'AdminSummitLocationActionSyncWorkRequest');
|
||||
INSERT INTO AdminScheduleSummitActionSyncWorkRequest (ID, CreatedByID) VALUES (LAST_INSERT_ID(), :CreatedByID)
|
||||
INSERT INTO AdminSummitLocationActionSyncWorkRequest (ID, LocationID) VALUES (LAST_INSERT_ID(), :LocationID);
|
||||
SQL;
|
||||
|
||||
$bindings = [
|
||||
@ -47,5 +42,17 @@ SQL;
|
||||
];
|
||||
|
||||
self::insert($sql, $bindings, $types);
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO AdminScheduleSummitActionSyncWorkRequest (ID, CreatedByID) VALUES (LAST_INSERT_ID(), :CreatedByID)
|
||||
SQL;
|
||||
self::insert($sql, $bindings, $types);
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO AdminSummitLocationActionSyncWorkRequest (ID, LocationID) VALUES (LAST_INSERT_ID(), :LocationID);
|
||||
SQL;
|
||||
|
||||
self::insert($sql, $bindings, $types);
|
||||
|
||||
}
|
||||
}
|
66
app/Events/SummitVenueRoomUpdated.php
Normal file
66
app/Events/SummitVenueRoomUpdated.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php namespace App\Events;
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Class SummitVenueRoomUpdated
|
||||
* @package App\Events
|
||||
*/
|
||||
final class SummitVenueRoomUpdated extends LocationAction
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $old_floor_id;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $new_floor_id;
|
||||
|
||||
/**
|
||||
* SummitVenueRoomUpdated constructor.
|
||||
* @param int $summit_id
|
||||
* @param int $location_id
|
||||
* @param array $related_event_ids
|
||||
* @param int $old_floor_id
|
||||
* @param int $new_floor_id
|
||||
*/
|
||||
public function __construct($summit_id, $location_id, array $related_event_ids = [], $old_floor_id = 0, $new_floor_id = 0)
|
||||
{
|
||||
parent::__construct(
|
||||
$summit_id,
|
||||
$location_id,
|
||||
'SummitVenueRoom',
|
||||
$related_event_ids
|
||||
);
|
||||
$this->old_floor_id = $old_floor_id;
|
||||
$this->new_floor_id = $new_floor_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getOldFloorId()
|
||||
{
|
||||
return $this->old_floor_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNewFloorId()
|
||||
{
|
||||
return $this->new_floor_id;
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ final class AdminSummitLocationActionSyncWorkRequestFactory
|
||||
{
|
||||
/**
|
||||
* @param LocationAction $event
|
||||
* @param string $type
|
||||
* @return AdminSummitLocationActionSyncWorkRequest
|
||||
*/
|
||||
public static function build(LocationAction $event, $type){
|
||||
@ -40,7 +41,8 @@ final class AdminSummitLocationActionSyncWorkRequestFactory
|
||||
|
||||
$request->setLocation($location);
|
||||
|
||||
$request->Type = $type;
|
||||
$request->setType($type);
|
||||
|
||||
if($owner_id > 0){
|
||||
$member = $member_repository->getById($owner_id);
|
||||
$request->setCreatedBy($member);
|
||||
|
@ -12,6 +12,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Events\LocationAction;
|
||||
use App\Events\SummitVenueRoomUpdated;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use models\main\IMemberRepository;
|
||||
use models\oauth2\IResourceServerContext;
|
||||
@ -48,8 +49,20 @@ final class LocationActionEntityEventFactory
|
||||
$entity_event->setOwner($member);
|
||||
}
|
||||
|
||||
$metadata = '';
|
||||
|
||||
if($event instanceof SummitVenueRoomUpdated){
|
||||
$old_floor_id = $event->getOldFloorId();
|
||||
$new_floor_id = $event->getNewFloorId();
|
||||
|
||||
if($old_floor_id != $new_floor_id){
|
||||
$metadata = json_encode( ['floor_old' => $old_floor_id, 'floor_new' => $new_floor_id]);
|
||||
}
|
||||
}
|
||||
|
||||
$entity_event->setSummit($summit);
|
||||
$entity_event->setMetadata('');
|
||||
$entity_event->setMetadata($metadata);
|
||||
|
||||
return $entity_event;
|
||||
}
|
||||
}
|
@ -1076,6 +1076,100 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $venue_id
|
||||
* @param $room_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateVenueRoom($summit_id, $venue_id, $room_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'] = SummitVenueRoom::ClassName;
|
||||
$rules = SummitLocationValidationRulesFactory::build($payload, true);
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$room = $this->location_service->updateVenueRoom($summit, $venue_id, $room_id, $payload);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($room)->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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $venue_id
|
||||
* @param $floor_id
|
||||
* @param $room_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateVenueFloorRoom($summit_id, $venue_id, $floor_id, $room_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'] = SummitVenueRoom::ClassName;
|
||||
$rules = SummitLocationValidationRulesFactory::build($payload, true);
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
if(isset($payload['floor_id']))
|
||||
$payload['floor_id'] = intval($floor_id);
|
||||
|
||||
$room = $this->location_service->updateVenueRoom($summit, $venue_id, $room_id, $payload);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($room)->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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
|
@ -31,6 +31,7 @@ final class SummitVenueRoomValidationRulesFactory
|
||||
return array_merge([
|
||||
'capacity' => 'sometimes|integer:min:0',
|
||||
'override_blackouts' => 'sometimes|boolean',
|
||||
'floor_id' => 'sometimes|integer',
|
||||
], $rules);
|
||||
}
|
||||
|
||||
|
@ -294,6 +294,9 @@ Route::group([
|
||||
|
||||
Route::group(['prefix' => 'rooms'], function () {
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addVenueRoom']);
|
||||
Route::group(['prefix' => '{room_id}'], function () {
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateVenueRoom']);
|
||||
});
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'floors'], function () {
|
||||
@ -304,7 +307,7 @@ Route::group([
|
||||
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::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateVenueFloorRoom']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -14,6 +14,8 @@
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use models\exceptions\ValidationException;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="SummitVenue")
|
||||
@ -68,6 +70,44 @@ class SummitVenue extends SummitGeoLocatedLocation
|
||||
$room->setVenue($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitVenueRoom $room
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateRoomsOrder(SummitVenueRoom $room, $new_order){
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
$rooms = $this->rooms->matching($criteria)->toArray();
|
||||
$rooms = array_slice($rooms,0, count($rooms), false);
|
||||
$max_order = count($rooms);
|
||||
$former_order = 1;
|
||||
foreach ($rooms as $r){
|
||||
if($r->getId() == $room->getId()) break;
|
||||
$former_order++;
|
||||
}
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
unset($rooms[$former_order - 1]);
|
||||
|
||||
$rooms = array_merge
|
||||
(
|
||||
array_slice($rooms, 0, $new_order -1 , true) ,
|
||||
[$room] ,
|
||||
array_slice($rooms, $new_order -1 , count($rooms), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
foreach($rooms as $r){
|
||||
$r->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -11,9 +11,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Query;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\File;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
/**
|
||||
@ -180,5 +182,42 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
||||
$room->setFloor($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitVenueRoom $room
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateRoomsOrder(SummitVenueRoom $room, $new_order){
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
$rooms = $this->rooms->matching($criteria)->toArray();
|
||||
$rooms = array_slice($rooms,0, count($rooms), false);
|
||||
$max_order = count($rooms);
|
||||
$former_order = 1;
|
||||
foreach ($rooms as $r){
|
||||
if($r->getId() == $room->getId()) break;
|
||||
$former_order++;
|
||||
}
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
unset($rooms[$former_order - 1]);
|
||||
|
||||
$rooms = array_merge
|
||||
(
|
||||
array_slice($rooms, 0, $new_order -1 , true) ,
|
||||
[$room] ,
|
||||
array_slice($rooms, $new_order -1 , count($rooms), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
foreach($rooms as $r){
|
||||
$r->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1679,15 +1679,16 @@ SQL;
|
||||
$former_order = $location->getOrder();
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
$locations = $this->locations->matching($criteria)->toArray();
|
||||
$max_order = count($locations);
|
||||
|
||||
$filtered_locations = [];
|
||||
|
||||
foreach($locations as $l){
|
||||
foreach($this->locations->matching($criteria)->toArray() as $l){
|
||||
if($l instanceof SummitVenue || $l instanceof SummitHotel || $l instanceof SummitAirport || $l instanceof SummitExternalLocation)
|
||||
$filtered_locations[] = $l;
|
||||
$filtered_locations[] = $l;
|
||||
}
|
||||
|
||||
$filtered_locations = array_slice($filtered_locations,0, count($filtered_locations), false);
|
||||
$max_order = count($filtered_locations);
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
@ -1697,7 +1698,7 @@ SQL;
|
||||
(
|
||||
array_slice($filtered_locations, 0, $new_order -1 , true) ,
|
||||
[$location] ,
|
||||
array_slice($filtered_locations, $new_order -1 , count($filtered_locations) - $new_order - 1, true)
|
||||
array_slice($filtered_locations, $new_order -1 , count($filtered_locations), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
@ -1705,7 +1706,6 @@ SQL;
|
||||
$l->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,12 +176,25 @@ final class EventServiceProvider extends ServiceProvider
|
||||
|
||||
// locations events
|
||||
|
||||
Event::listen(\App\Events\LocationInserted::class, function($event)
|
||||
|
||||
Event::listen(\App\Events\SummitVenueRoomInserted::class, function($event)
|
||||
{
|
||||
EntityEventPersister::persist(LocationActionEntityEventFactory::build($event, 'INSERT'));
|
||||
});
|
||||
|
||||
Event::listen(\App\Events\SummitVenueRoomInserted::class, function($event)
|
||||
Event::listen(\App\Events\SummitVenueRoomUpdated::class, function($event)
|
||||
{
|
||||
EntityEventPersister::persist(LocationActionEntityEventFactory::build($event, 'UPDATE'));
|
||||
$published_events = $event->getRelatedEventIds();
|
||||
if(count($published_events) > 0){
|
||||
AdminSummitLocationActionSyncWorkRequestPersister::persist
|
||||
(
|
||||
AdminSummitLocationActionSyncWorkRequestFactory::build($event, 'UPDATE')
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Event::listen(\App\Events\LocationInserted::class, function($event)
|
||||
{
|
||||
EntityEventPersister::persist(LocationActionEntityEventFactory::build($event, 'INSERT'));
|
||||
});
|
||||
|
@ -91,4 +91,25 @@ interface ILocationService
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addVenueRoom(Summit $summit, $venue_id, array $data);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $room_id
|
||||
* @param array $payload
|
||||
* @return SummitVenueRoom
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateVenueRoom(Summit $summit, $venue_id, $room_id, array $payload);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $room_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteVenueRoom(Summit $summit, $venue_id, $room_id);
|
||||
}
|
@ -19,6 +19,7 @@ use App\Events\LocationDeleted;
|
||||
use App\Events\LocationInserted;
|
||||
use App\Events\LocationUpdated;
|
||||
use App\Events\SummitVenueRoomInserted;
|
||||
use App\Events\SummitVenueRoomUpdated;
|
||||
use App\Models\Foundation\Summit\Factories\SummitLocationFactory;
|
||||
use App\Models\Foundation\Summit\Factories\SummitVenueFloorFactory;
|
||||
use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository;
|
||||
@ -36,7 +37,6 @@ use models\summit\SummitGeoLocatedLocation;
|
||||
use models\summit\SummitVenue;
|
||||
use models\summit\SummitVenueFloor;
|
||||
use models\summit\SummitVenueRoom;
|
||||
|
||||
/**
|
||||
* Class LocationService
|
||||
* @package App\Services\Model
|
||||
@ -125,11 +125,11 @@ final class LocationService implements ILocationService
|
||||
case IGeoCodingAPI::ResponseStatusZeroResults: {
|
||||
$validation_msg = trans('validation_errors.LocationService.addLocation.InvalidAddressOrCoordinates');
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case IGeoCodingAPI::ResponseStatusOverQueryLimit: {
|
||||
$validation_msg = trans('validation_errors.LocationService.addLocation.OverQuotaLimit');
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
throw new ValidationException($validation_msg);
|
||||
} catch (\Exception $ex) {
|
||||
@ -201,7 +201,7 @@ final class LocationService implements ILocationService
|
||||
}
|
||||
|
||||
if ($location->getClassName() != $data['class_name']) {
|
||||
throw new EntityNotFoundException(
|
||||
throw new ValidationException(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.updateLocation.ClassNameMissMatch',
|
||||
@ -335,7 +335,7 @@ final class LocationService implements ILocationService
|
||||
}
|
||||
|
||||
if(!$venue instanceof SummitVenue){
|
||||
throw new ValidationException
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
@ -429,7 +429,7 @@ final class LocationService implements ILocationService
|
||||
}
|
||||
|
||||
if(!$venue instanceof SummitVenue){
|
||||
throw new ValidationException
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
@ -538,7 +538,7 @@ final class LocationService implements ILocationService
|
||||
}
|
||||
|
||||
if(!$venue instanceof SummitVenue){
|
||||
throw new ValidationException
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
@ -625,7 +625,7 @@ final class LocationService implements ILocationService
|
||||
}
|
||||
|
||||
if(!$venue instanceof SummitVenue){
|
||||
throw new ValidationException
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
@ -690,4 +690,164 @@ final class LocationService implements ILocationService
|
||||
|
||||
return $room;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $room_id
|
||||
* @param array $data
|
||||
* @return SummitVenueRoom
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateVenueRoom(Summit $summit, $venue_id, $room_id, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $venue_id, $room_id, $data) {
|
||||
|
||||
if (isset($data['name'])) {
|
||||
$old_location = $summit->getLocationByName(trim($data['name']));
|
||||
|
||||
if (!is_null($old_location)) {
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.updateVenueRoom.LocationNameAlreadyExists',
|
||||
[
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$venue = $summit->getLocation($venue_id);
|
||||
|
||||
if(is_null($venue)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.updateVenueRoom.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(!$venue instanceof SummitVenue){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.updateVenueRoom.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$room = $summit->getLocation($room_id);
|
||||
if (is_null($room)) {
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.updateVenueRoom.RoomNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
'room_id' => $room_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$room instanceof SummitVenueRoom) {
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.updateVenueRoom.RoomNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
'room_id' => $room_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
$old_floor_id = $room->getFloorId();
|
||||
$new_floor_id = $room->getFloorId();
|
||||
$room = SummitLocationFactory::populate($room, $data);
|
||||
$floor = null;
|
||||
if(isset($data['floor_id'])){
|
||||
$new_floor_id = intval($data['floor_id']);
|
||||
$floor = $venue->getFloor($new_floor_id);
|
||||
|
||||
if(is_null($floor)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.updateVenueRoom.FloorNotFound',
|
||||
[
|
||||
'floor_id' => $new_floor_id,
|
||||
'venue_id' => $venue_id
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$floor->addRoom($room);
|
||||
}
|
||||
|
||||
$summit->addLocation($room);
|
||||
$venue->addRoom($room);
|
||||
|
||||
// request to update order
|
||||
if (isset($data['order']) && intval($data['order']) != $room->getOrder()) {
|
||||
|
||||
if(!is_null($floor)){
|
||||
$floor->recalculateRoomsOrder($room, intval($data['order']));
|
||||
}
|
||||
else
|
||||
{
|
||||
$venue->recalculateRoomsOrder($room, intval($data['order']));
|
||||
}
|
||||
}
|
||||
|
||||
Event::fire
|
||||
(
|
||||
new SummitVenueRoomUpdated
|
||||
(
|
||||
$room->getSummitId(),
|
||||
$room->getId(),
|
||||
$summit->getScheduleEventsIdsPerLocation($room),
|
||||
$old_floor_id,
|
||||
$new_floor_id
|
||||
)
|
||||
);
|
||||
|
||||
return $room;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $venue_id
|
||||
* @param int $room_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteVenueRoom(Summit $summit, $venue_id, $room_id)
|
||||
{
|
||||
// TODO: Implement deleteVenueRoom() method.
|
||||
}
|
||||
}
|
@ -554,6 +554,15 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-venue-room',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/rooms/{room_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-venue-floor-room',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}/rooms',
|
||||
@ -563,6 +572,15 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::WriteLocationsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-venue-floor-room',
|
||||
'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id}/rooms/{room_id}',
|
||||
'http_method' => 'PUT',
|
||||
'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}',
|
||||
|
@ -24,4 +24,6 @@ return [
|
||||
'LocationService.deleteVenueFloor.VenueNotFound' => 'venue :venue_id not found on summit :summit_id',
|
||||
'LocationService.addVenueRoom.FloorNotFound' => 'floor :floor_id does not belongs to venue :venue_id',
|
||||
'LocationService.addVenueRoom.VenueNotFound' => 'venue :venue_id not found on summit :summit_id',
|
||||
'LocationService.updateVenueRoom.FloorNotFound' => 'floor :floor_id does not belongs to venue :venue_id',
|
||||
'LocationService.updateVenueRoom.VenueNotFound' => 'venue :venue_id not found on summit :summit_id',
|
||||
];
|
@ -41,4 +41,5 @@ return [
|
||||
'LocationService.updateVenueFloor.FloorNumberAlreadyExists' => 'floor number :floor_number already belongs to another floor on venue :venue_id',
|
||||
'LocationService.addVenueRoom.InvalidClassName' => 'invalid class name',
|
||||
'LocationService.addVenueRoom.LocationNameAlreadyExists' => 'there is already another location with same name for summit :summit_id',
|
||||
'LocationService.updateVenueRoom.LocationNameAlreadyExists' => 'there is already another location with same name for summit :summit_id',
|
||||
];
|
@ -820,7 +820,6 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
||||
*/
|
||||
public function testAddVenueRoom($summit_id = 23, $venue_id = 292){
|
||||
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id,
|
||||
@ -833,7 +832,6 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
||||
'description' => 'test room',
|
||||
];
|
||||
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
@ -903,4 +901,47 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($room));
|
||||
return $room;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @param int $venue_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testUpdateVenueRoomWithFloor($summit_id = 23, $venue_id = 292){
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id,
|
||||
'floor_id' => 22,
|
||||
'room_id' => 307
|
||||
];
|
||||
|
||||
$data = [
|
||||
'description' => 'Pyrmont Theatre',
|
||||
'order' => 2,
|
||||
'capacity' => 1000,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"PUT",
|
||||
"OAuth2SummitLocationsApiController@updateVenueFloorRoom",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$room = json_decode($content);
|
||||
$this->assertTrue(!is_null($room));
|
||||
return $room;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user