Added endpoint to delete selection plan by summit

DELETE /api/v1/summits/{id}/selection-plans/{selection_plan_id}

Change-Id: I3893e5dea6b604874932466598dcb79940c5321e
This commit is contained in:
Sebastian Marcet 2018-06-07 14:11:58 -07:00
parent 48b79c69d1
commit 1f240e6deb
5 changed files with 115 additions and 46 deletions

View File

@ -57,51 +57,6 @@ final class OAuth2SummitSelectionPlansApiController extends OAuth2ProtectedContr
$this->selection_plan_service = $selection_plan_service;
}
/**
* @param $summit_id
* @return mixed
*/
public function addSelectionPlan($summit_id){
try {
if(!Request::isJson()) return $this->error400();
$payload = Input::json()->all();
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) return $this->error404();
$rules = SummitSelectionPlanValidationRulesFactory::build($payload);
// Creates a Validator instance and validates the data.
$validation = Validator::make($payload, $rules);
if ($validation->fails()) {
$messages = $validation->messages()->toArray();
return $this->error412
(
$messages
);
}
$selection_plan = $this->selection_plan_service->addSelectionPlan($summit, $payload);
return $this->created(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize());
}
catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412([$ex1->getMessage()]);
}
catch(EntityNotFoundException $ex2)
{
Log::warning($ex2);
return $this->error404(['message'=> $ex2->getMessage()]);
}
catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
/**
* @param $summit_id
* @param $selection_plan_id
@ -116,7 +71,7 @@ final class OAuth2SummitSelectionPlansApiController extends OAuth2ProtectedContr
$selection_plan = $summit->getSelectionPlanById($selection_plan_id);
if (is_null($selection_plan)) return $this->error404();
return $this->ok(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize());
return $this->ok(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize(Request::input('expand', '')));
}
catch (ValidationException $ex1) {
Log::warning($ex1);
@ -178,4 +133,79 @@ final class OAuth2SummitSelectionPlansApiController extends OAuth2ProtectedContr
return $this->error500($ex);
}
}
/**
* @param $summit_id
* @return mixed
*/
public function addSelectionPlan($summit_id){
try {
if(!Request::isJson()) return $this->error400();
$payload = Input::json()->all();
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) return $this->error404();
$rules = SummitSelectionPlanValidationRulesFactory::build($payload);
// Creates a Validator instance and validates the data.
$validation = Validator::make($payload, $rules);
if ($validation->fails()) {
$messages = $validation->messages()->toArray();
return $this->error412
(
$messages
);
}
$selection_plan = $this->selection_plan_service->addSelectionPlan($summit, $payload);
return $this->created(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize());
}
catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412([$ex1->getMessage()]);
}
catch(EntityNotFoundException $ex2)
{
Log::warning($ex2);
return $this->error404(['message'=> $ex2->getMessage()]);
}
catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
/**
* @param $summit_id
* @param $selection_plan_id
* @return mixed
*/
public function deleteSelectionPlan($summit_id, $selection_plan_id){
try {
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
if (is_null($summit)) return $this->error404();
$this->selection_plan_service->deleteSelectionPlan($summit, $selection_plan_id);
return $this->deleted();
}
catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412([$ex1->getMessage()]);
}
catch(EntityNotFoundException $ex2)
{
Log::warning($ex2);
return $this->error404(['message'=> $ex2->getMessage()]);
}
catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
}

View File

@ -115,6 +115,10 @@ Route::group([
Route::group(['prefix' => '{selection_plan_id}'], function () {
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSelectionPlansApiController@updateSelectionPlan']);
Route::get('', ['uses' => 'OAuth2SummitSelectionPlansApiController@getSelectionPlan']);
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSelectionPlansApiController@deleteSelectionPlan']);
Route::group(['prefix' => 'track-groups'], function () {
});
});
});

View File

@ -12,6 +12,7 @@
* limitations under the License.
**/
use App\Models\Foundation\Summit\SelectionPlan;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\summit\Summit;
/**
@ -34,6 +35,15 @@ interface ISummitSelectionPlanService
* @param array $payload
* @return SelectionPlan
* @throws ValidationException
* @throws EntityNotFoundException
*/
public function updateSelectionPlan(Summit $summit, $selection_plan_id, array $payload);
/**
* @param Summit $summit
* @param int $selection_plan_id
* @throws EntityNotFoundException
* @return void
*/
public function deleteSelectionPlan(Summit $summit, $selection_plan_id);
}

View File

@ -99,4 +99,28 @@ final class SummitSelectionPlanService
return $selection_plan;
});
}
/**
* @param Summit $summit
* @param int $selection_plan_id
* @throws EntityNotFoundException
* @return void
*/
public function deleteSelectionPlan(Summit $summit, $selection_plan_id)
{
return $this->tx_service->transaction(function() use($summit, $selection_plan_id){
$selection_plan = $summit->getSelectionPlanById($selection_plan_id);
if(is_null($selection_plan))
throw new EntityNotFoundException(trans
('not_found_errors.SummitSelectionPlanService.deleteSelectionPlan.SelectionPlanNotFound',
[
'selection_plan_id' => $selection_plan_id,
'summit_id' => $summit->getId()
]
));
$summit->removeSelectionSelectionPlan($selection_plan);
});
}
}

View File

@ -78,4 +78,5 @@ return [
'SummitPushNotificationService.unApproveNotification.NotificationNotFound'=> 'notification :notification_id not found on summit :summit_id',
'SummitPushNotificationService.deleteNotification.NotificationNotFound'=> 'notification :notification_id not found on summit :summit_id',
'SummitSelectionPlanService.updateSelectionPlan.SelectionPlanNotFound' => 'selection plan :selection_plan_id not found on summit :summit_id',
'SummitSelectionPlanService.deleteSelectionPlan.SelectionPlanNotFound' => 'selection plan :selection_plan_id not found on summit :summit_id',
];