Added endpoint delete venue floor
DELETE /api/v1/summits/{id}/locations/venues/{venue_id}/floors/{floor_id} Change-Id: I2833f70ba553b9974ae32a674f86a6d529cf3641
This commit is contained in:
parent
19161fb734
commit
246e3deb4b
|
@ -1160,6 +1160,27 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
}
|
||||
|
||||
public function deleteVenueFloor($summit_id, $venue_id, $floor_id){
|
||||
try {
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$this->location_service->deleteVenueFloor($summit, $venue_id, $floor_id);
|
||||
|
||||
return $this->deleted();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,13 +47,13 @@ class SummitVenue extends SummitGeoLocatedLocation
|
|||
private $is_main;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitVenueRoom", mappedBy="venue", cascade={"persist"})
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitVenueRoom", mappedBy="venue", cascade={"persist"}, orphanRemoval=true)
|
||||
* @var SummitVenueRoom[]
|
||||
*/
|
||||
private $rooms;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitVenueFloor", mappedBy="venue", cascade={"persist"})
|
||||
* @ORM\OneToMany(targetEntity="models\summit\SummitVenueFloor", mappedBy="venue", cascade={"persist"}, orphanRemoval=true)
|
||||
* @var SummitVenueFloor[]
|
||||
*/
|
||||
private $floors;
|
||||
|
@ -63,6 +63,11 @@ class SummitVenue extends SummitGeoLocatedLocation
|
|||
$floor->setVenue($this);
|
||||
}
|
||||
|
||||
public function addRoom(SummitVenueRoom $room){
|
||||
$this->rooms->add($room);
|
||||
$room->setVenue($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -152,4 +157,14 @@ class SummitVenue extends SummitGeoLocatedLocation
|
|||
return $floor === false ? null:$floor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitVenueFloor $floor
|
||||
* @return $this
|
||||
*/
|
||||
public function removeFloor(SummitVenueFloor $floor){
|
||||
$this->floors->removeElement($floor);
|
||||
$floor->setVenue(null);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -54,7 +54,7 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
|||
private $rooms;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File", fetch="EAGER")
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File", fetch="EAGER", cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="ImageID", referencedColumnName="ID")
|
||||
* @var File
|
||||
*/
|
||||
|
|
|
@ -181,4 +181,21 @@ class SummitVenueRoom extends SummitAbstractLocation
|
|||
$criteria = Criteria::create()->where(Criteria::expr()->eq("id", $type_id));
|
||||
return $this->metrics->matching($criteria)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitVenue $venue
|
||||
*/
|
||||
public function setVenue(SummitVenue $venue)
|
||||
{
|
||||
$this->venue = $venue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitVenueFloor $floor
|
||||
*/
|
||||
public function setFloor(SummitVenueFloor $floor)
|
||||
{
|
||||
$this->floor = $floor;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Events\FloorDeleted;
|
||||
use App\Events\FloorInserted;
|
||||
use App\Events\FloorUpdated;
|
||||
use App\Events\LocationDeleted;
|
||||
|
@ -335,7 +336,7 @@ final class LocationService implements ILocationService
|
|||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.addVenueFloor.VenueNotFound',
|
||||
'not_found_errors.LocationService.addVenueFloor.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
|
@ -407,6 +408,7 @@ final class LocationService implements ILocationService
|
|||
public function updateVenueFloor(Summit $summit, $venue_id, $floor_id, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $venue_id, $floor_id, $data) {
|
||||
|
||||
$venue = $summit->getLocation($venue_id);
|
||||
|
||||
if(is_null($venue)){
|
||||
|
@ -428,7 +430,7 @@ final class LocationService implements ILocationService
|
|||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.LocationService.updateVenueFloor.VenueNotFound',
|
||||
'not_found_errors.LocationService.updateVenueFloor.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
|
@ -516,6 +518,61 @@ final class LocationService implements ILocationService
|
|||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $venue_id, $floor_id) {
|
||||
|
||||
$venue = $summit->getLocation($venue_id);
|
||||
|
||||
if(is_null($venue)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.deleteVenueFloor.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(!$venue instanceof SummitVenue){
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.deleteVenueFloor.VenueNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'venue_id' => $venue_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$floor = $venue->getFloor($floor_id);
|
||||
|
||||
if(is_null($floor)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.LocationService.deleteVenueFloor.FloorNotFound',
|
||||
[
|
||||
'floor_id' => $floor_id,
|
||||
'venue_id' => $venue_id
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Event::fire(new FloorDeleted
|
||||
(
|
||||
$floor->getVenue()->getSummitId(),
|
||||
$floor->getVenueId(),
|
||||
$floor->getId()
|
||||
)
|
||||
);
|
||||
|
||||
$venue->removeFloor($floor);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -20,4 +20,6 @@ return [
|
|||
'LocationService.addVenueFloor.VenueNotFound' => 'venue :venue_id not found on summit :summit_id',
|
||||
'LocationService.updateVenueFloor.FloorNotFound' => 'floor :floor_id does not belongs to venue :venue_id',
|
||||
'LocationService.updateVenueFloor.VenueNotFound' => 'venue :venue_id not found on summit :summit_id',
|
||||
'LocationService.deleteVenueFloor.FloorNotFound' => 'floor :floor_id does not belongs to venue :venue_id',
|
||||
'LocationService.deleteVenueFloor.VenueNotFound' => 'venue :venue_id not found on summit :summit_id',
|
||||
];
|
|
@ -697,12 +697,16 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
|||
* @param int $number
|
||||
* @return mixed
|
||||
*/
|
||||
public function testAddVenueFloor($summit_id = 23, $venue_id = 292, $number = 0){
|
||||
public function testAddVenueFloor($summit_id = 23, $venue_id = 292, $number = null){
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id
|
||||
];
|
||||
|
||||
if(is_null($number))
|
||||
$number = rand(0,1000);
|
||||
|
||||
$name = str_random(16).'_floor';
|
||||
$data = [
|
||||
'name' => $name,
|
||||
|
@ -733,9 +737,14 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
|||
return $floor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @param int $venue_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testUpdateVenueFloor($summit_id = 23, $venue_id = 292){
|
||||
|
||||
$floor = $this->testAddVenueFloor($summit_id, $venue_id, 50);
|
||||
$floor = $this->testAddVenueFloor($summit_id, $venue_id, rand(0,1000));
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id,
|
||||
|
@ -769,4 +778,38 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
|||
$this->assertTrue(!is_null($floor));
|
||||
return $floor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @param int $venue_id
|
||||
*/
|
||||
public function testDeleteVenueFloor($summit_id = 23, $venue_id = 292){
|
||||
|
||||
$floor = $this->testAddVenueFloor($summit_id, $venue_id, rand(0,1000));
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'venue_id' => $venue_id,
|
||||
'floor_id' => $floor->id
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"DELETE",
|
||||
"OAuth2SummitLocationsApiController@deleteVenueFloor",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue