Added endpoints to add/remove track groups from Selection Plan
PUT /api/v1/summits/{id}/selection-plans/{selection_plan_id}/track-groups/{track_group_id} DELETE /api/v1/summits/{id}/selection-plans/{selection_plan_id}/track-groups/{track_group_id} Change-Id: I50755c69bda23cff9f3f9067008ca7415d572160
This commit is contained in:
parent
1f240e6deb
commit
5b649adca1
|
@ -208,4 +208,66 @@ final class OAuth2SummitSelectionPlansApiController extends OAuth2ProtectedContr
|
|||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $selection_plan_id
|
||||
* @param $track_group_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function addTrackGroupToSelectionPlan($summit_id, $selection_plan_id, $track_group_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->addTrackGroupToSelectionPlan($summit, $selection_plan_id, $track_group_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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $selection_plan_id
|
||||
* @param $track_group_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteTrackGroupToSelectionPlan($summit_id, $selection_plan_id, $track_group_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->deleteTrackGroupToSelectionPlan($summit, $selection_plan_id, $track_group_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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -117,7 +117,8 @@ Route::group([
|
|||
Route::get('', ['uses' => 'OAuth2SummitSelectionPlansApiController@getSelectionPlan']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSelectionPlansApiController@deleteSelectionPlan']);
|
||||
Route::group(['prefix' => 'track-groups'], function () {
|
||||
|
||||
Route::put('{track_group_id}', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSelectionPlansApiController@addTrackGroupToSelectionPlan']);
|
||||
Route::delete('{track_group_id}', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSelectionPlansApiController@removeTrackGroupToSelectionPlan']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -49,11 +49,12 @@ final class SelectionPlanSerializer extends SilverStripeSerializer
|
|||
foreach ($selection_plan->getCategoryGroups() as $group) {
|
||||
$category_groups[] = $group->getId();
|
||||
}
|
||||
|
||||
$values['track_groups'] = $category_groups;
|
||||
|
||||
if (!empty($expand)) {
|
||||
$expand = explode(',', $expand);
|
||||
foreach ($expand as $relation) {
|
||||
$relations = explode(',', $expand);
|
||||
foreach ($relations as $relation) {
|
||||
switch (trim($relation)) {
|
||||
case 'track_groups':{
|
||||
$category_groups = [];
|
||||
|
|
|
@ -257,4 +257,20 @@ class SelectionPlan extends SilverstripeBaseModel
|
|||
return $this->category_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationCategoryGroup $track_group
|
||||
*/
|
||||
public function addTrackGroup(PresentationCategoryGroup $track_group){
|
||||
if($this->category_groups->contains($track_group)) return;
|
||||
$this->category_groups->add($track_group);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationCategoryGroup $track_group
|
||||
*/
|
||||
public function removeTrackGroup(PresentationCategoryGroup $track_group){
|
||||
if(!$this->category_groups->contains($track_group)) return;
|
||||
$this->category_groups->removeElement($track_group);
|
||||
}
|
||||
|
||||
}
|
|
@ -46,4 +46,24 @@ interface ISummitSelectionPlanService
|
|||
* @return void
|
||||
*/
|
||||
public function deleteSelectionPlan(Summit $summit, $selection_plan_id);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $selection_plan_id
|
||||
* @param int $track_group_id
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @return void
|
||||
*/
|
||||
public function addTrackGroupToSelectionPlan(Summit $summit, $selection_plan_id, $track_group_id);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $selection_plan_id
|
||||
* @param int $track_group_id
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTrackGroupToSelectionPlan(Summit $summit, $selection_plan_id, $track_group_id);
|
||||
}
|
|
@ -123,4 +123,74 @@ final class SummitSelectionPlanService
|
|||
$summit->removeSelectionSelectionPlan($selection_plan);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $selection_plan_id
|
||||
* @param int $track_group_id
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @return void
|
||||
*/
|
||||
public function addTrackGroupToSelectionPlan(Summit $summit, $selection_plan_id, $track_group_id)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $selection_plan_id, $track_group_id){
|
||||
|
||||
$selection_plan = $summit->getSelectionPlanById($selection_plan_id);
|
||||
if(is_null($selection_plan))
|
||||
throw new EntityNotFoundException(trans
|
||||
('not_found_errors.SummitSelectionPlanService.addTrackGroupToSelectionPlan.SelectionPlanNotFound',
|
||||
[
|
||||
'selection_plan_id' => $selection_plan_id,
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
|
||||
$track_group = $summit->getCategoryGroupById($track_group_id);
|
||||
if(is_null($track_group))
|
||||
throw new EntityNotFoundException(trans
|
||||
('not_found_errors.SummitSelectionPlanService.addTrackGroupToSelectionPlan.TrackGroupNotFound',
|
||||
[
|
||||
'track_group_id' => $track_group_id,
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
$selection_plan->addTrackGroup($track_group);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $selection_plan_id
|
||||
* @param int $track_group_id
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTrackGroupToSelectionPlan(Summit $summit, $selection_plan_id, $track_group_id)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $selection_plan_id, $track_group_id){
|
||||
|
||||
$selection_plan = $summit->getSelectionPlanById($selection_plan_id);
|
||||
if(is_null($selection_plan))
|
||||
throw new EntityNotFoundException(trans
|
||||
('not_found_errors.SummitSelectionPlanService.deleteTrackGroupToSelectionPlan.SelectionPlanNotFound',
|
||||
[
|
||||
'selection_plan_id' => $selection_plan_id,
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
|
||||
$track_group = $summit->getCategoryGroupById($track_group_id);
|
||||
if(is_null($track_group))
|
||||
throw new EntityNotFoundException(trans
|
||||
('not_found_errors.SummitSelectionPlanService.deleteTrackGroupToSelectionPlan.TrackGroupNotFound',
|
||||
[
|
||||
'track_group_id' => $track_group_id,
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
$selection_plan->removeTrackGroup($track_group);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1637,6 +1637,22 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-track-group-2-selection-plan',
|
||||
'route' => '/api/v1/summits/{id}/selection-plans/{selection_plan_id}/track-groups/{track_group_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-track-group-2-selection-plan',
|
||||
'route' => '/api/v1/summits/{id}/selection-plans/{selection_plan_id}/track-groups/{track_group_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,4 +79,8 @@ return [
|
|||
'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',
|
||||
'SummitSelectionPlanService.addTrackGroupToSelectionPlan.SelectionPlanNotFound' => 'selection plan :selection_plan_id not found on summit :summit_id',
|
||||
'SummitSelectionPlanService.addTrackGroupToSelectionPlan.TrackGroupNotFound' => 'track group :track_group_id not found on summit :summit_id',
|
||||
'SummitSelectionPlanService.deleteTrackGroupToSelectionPlan.SelectionPlanNotFound' => 'selection plan :selection_plan_id not found on summit :summit_id',
|
||||
'SummitSelectionPlanService.deleteTrackGroupToSelectionPlan.TrackGroupNotFound' => 'track group :track_group_id not found on summit :summit_id',
|
||||
];
|
|
@ -97,4 +97,36 @@ final class OAuth2SelectionPlansApiTest extends ProtectedApiTest
|
|||
$this->assertEquals(false, $selection_plan->is_enabled);
|
||||
return $selection_plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
*/
|
||||
public function testAddTrackGroupToSelectionPlan($summit_id = 24){
|
||||
|
||||
$selection_plan = $this->testAddSelectionPlan($summit_id);
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'selection_plan_id' => $selection_plan->id,
|
||||
'track_group_id' => 1
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"PUT",
|
||||
"OAuth2SummitSelectionPlansApiController@addTrackGroupToSelectionPlan",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(404);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue