Added endpoint to delete push notifications
DELETE /api/v1/summits/{id}/notifications/{notification_id} Change-Id: I62f92fdd9ccf242d9b799e35635c1f47e0502a27
This commit is contained in:
parent
f36d3a9da8
commit
6f70e897f0
@ -272,6 +272,30 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $notification_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteNotification($summit_id, $notification_id){
|
||||
try {
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$this->push_notification_service->deleteNotification($summit, $notification_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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $notification_id
|
||||
@ -330,7 +354,6 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
|
@ -245,6 +245,7 @@ Route::group([
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@getById']);
|
||||
Route::put('approve', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@approveNotification']);
|
||||
Route::delete('approve', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@unApproveNotification']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@deleteNotification']);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -2024,6 +2024,16 @@ SQL;
|
||||
return $notification === false ? null : $notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitPushNotification $notification
|
||||
* @return $this
|
||||
*/
|
||||
public function removeNotification(SummitPushNotification $notification){
|
||||
$this->notifications->removeElement($notification);
|
||||
$notification->clearSummit();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@ -51,4 +51,13 @@ interface ISummitPushNotificationService
|
||||
* @throws EntityNotFoundException
|
||||
*/
|
||||
public function unApproveNotification(Summit $summit, Member $current_member, $notification_id);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $notification_id
|
||||
* @return void
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
*/
|
||||
public function deleteNotification(Summit $summit, $notification_id);
|
||||
}
|
@ -212,7 +212,7 @@ final class SummitPushNotificationService
|
||||
(
|
||||
trans
|
||||
(
|
||||
"not_found_errors.SummitPushNotificationService.approveNotification.unApproveNotification",
|
||||
"not_found_errors.SummitPushNotificationService.unApproveNotification.NotificationNotFound",
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'notification_id' => $notification_id
|
||||
@ -225,4 +225,34 @@ final class SummitPushNotificationService
|
||||
return $notification->unApprove();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $notification_id
|
||||
* @return void
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
*/
|
||||
public function deleteNotification(Summit $summit, $notification_id)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $notification_id){
|
||||
$notification = $summit->getNotificationById($notification_id);
|
||||
if(is_null($notification)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
"not_found_errors.SummitPushNotificationService.deleteNotification.NotificationNotFound",
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'notification_id' => $notification_id
|
||||
]
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
$summit->removeNotification($notification);
|
||||
});
|
||||
}
|
||||
}
|
@ -1455,6 +1455,15 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::WriteNotifications, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-notification',
|
||||
'route' => '/api/v1/summits/{id}/notifications/{notification_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteNotifications, $current_realm)
|
||||
],
|
||||
],
|
||||
// promo codes
|
||||
[
|
||||
'name' => 'get-promo-codes',
|
||||
|
@ -74,6 +74,7 @@ return [
|
||||
'SummitPushNotificationService.addPushNotification.EventNotFound' => 'event :event_id does not belongs to summit :summit_id schedule',
|
||||
'SummitPushNotificationService.addPushNotification.GroupNotFound' => 'group :group_id not found',
|
||||
'SummitPushNotificationService.addPushNotification.MemberNotFound' => 'member :member_id not found',
|
||||
'SummitPushNotificationService.approveNotification.approveNotification' => 'notification :notification_id not found on summit :summit_id',
|
||||
'SummitPushNotificationService.approveNotification.unApproveNotification'=> 'notification :notification_id not found on summit :summit_id',
|
||||
'SummitPushNotificationService.approveNotification.NotificationNotFound' => 'notification :notification_id not found on summit :summit_id',
|
||||
'SummitPushNotificationService.unApproveNotification.NotificationNotFound'=> 'notification :notification_id not found on summit :summit_id',
|
||||
'SummitPushNotificationService.deleteNotification.NotificationNotFound'=> 'notification :notification_id not found on summit :summit_id',
|
||||
];
|
Loading…
x
Reference in New Issue
Block a user