Added endpoints to get by id summit push notification
GET /api/v1/summits/{id}/notifications/{notification_id} Change-Id: I325bc804788ed1883230f6c75b246b742d387cf2
This commit is contained in:
parent
e1b4a16bc5
commit
8dad96af84
@ -11,6 +11,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Http\Utils\BooleanCellFormatter;
|
||||
use App\Http\Utils\EpochCellFormatter;
|
||||
use App\Http\Utils\PagingConstants;
|
||||
use App\Services\Model\ISummitPushNotificationService;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
@ -159,6 +161,117 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAllCSV($summit_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
|
||||
// default values
|
||||
$page = 1;
|
||||
$per_page = PHP_INT_MAX;
|
||||
|
||||
|
||||
$filter = null;
|
||||
if (Input::has('filter')) {
|
||||
$filter = FilterParser::parse(Input::get('filter'), [
|
||||
'channel' => ['=='],
|
||||
'sent_date' => ['>', '<', '<=', '>=', '=='],
|
||||
'created' => ['>', '<', '<=', '>=', '=='],
|
||||
'is_sent' => ['=='],
|
||||
'approved' => ['=='],
|
||||
'event_id' => ['=='],
|
||||
]);
|
||||
}
|
||||
|
||||
if(is_null($filter)) $filter = new Filter();
|
||||
|
||||
$filter->validate([
|
||||
'channel' => 'sometimes|in:EVERYONE,SPEAKERS,ATTENDEES,MEMBERS,SUMMIT,EVENT,GROUP',
|
||||
'sent_date' => 'sometimes|date_format:U',
|
||||
'created' => 'sometimes|date_format:U',
|
||||
'is_sent' => 'sometimes|boolean',
|
||||
'approved' => 'sometimes|boolean',
|
||||
'event_id' => 'sometimes|integer',
|
||||
]);
|
||||
|
||||
$order = null;
|
||||
|
||||
if (Input::has('order'))
|
||||
{
|
||||
$order = OrderParser::parse(Input::get('order'), [
|
||||
|
||||
'sent_date',
|
||||
'created',
|
||||
'id',
|
||||
]);
|
||||
}
|
||||
|
||||
$data = $this->repository->getAllByPageBySummit($summit, new PagingInfo($page, $per_page), $filter, $order);
|
||||
$filename = "push-notification-" . date('Ymd');
|
||||
$list = $data->toArray();
|
||||
return $this->export
|
||||
(
|
||||
'csv',
|
||||
$filename,
|
||||
$list['data'],
|
||||
[
|
||||
'created' => new EpochCellFormatter,
|
||||
'last_edited' => new EpochCellFormatter,
|
||||
'sent_date' => new EpochCellFormatter,
|
||||
'is_sent' => new BooleanCellFormatter,
|
||||
'approved' => new BooleanCellFormatter,
|
||||
]
|
||||
);
|
||||
}
|
||||
catch (EntityNotFoundException $ex1)
|
||||
{
|
||||
Log::warning($ex1);
|
||||
return $this->error404();
|
||||
}
|
||||
catch (ValidationException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error412($ex2->getMessages());
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $notification_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getById($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();
|
||||
$notification = $summit->getNotificationById($notification_id);
|
||||
if(is_null($notification))
|
||||
return $this->error404();
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($notification)->serialize( Request::input('expand', '')));
|
||||
} 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
|
||||
* @return mixed
|
||||
|
@ -239,7 +239,11 @@ Route::group([
|
||||
// notifications
|
||||
Route::group(['prefix' => 'notifications'], function () {
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@getAll']);
|
||||
Route::get('csv', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@getAllCSV']);
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@addPushNotification']);
|
||||
Route::group(['prefix' => '{notification_id}'], function () {
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitNotificationsApiController@getById']);
|
||||
});
|
||||
});
|
||||
|
||||
// speakers
|
||||
|
@ -1796,7 +1796,6 @@ SQL;
|
||||
return $rsvp_template === false ? null : $rsvp_template;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param RSVPTemplate $template
|
||||
* @return $this
|
||||
@ -2013,4 +2012,31 @@ SQL;
|
||||
{
|
||||
$this->secondary_registration_label = $secondary_registration_label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $notification_id
|
||||
* @return SummitPushNotification|null
|
||||
*/
|
||||
public function getNotificationById($notification_id){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('id', intval($notification_id)));
|
||||
$notification = $this->notifications->matching($criteria)->first();
|
||||
return $notification === false ? null : $notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCalendarSyncName()
|
||||
{
|
||||
return $this->calendar_sync_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCalendarSyncDesc()
|
||||
{
|
||||
return $this->calendar_sync_desc;
|
||||
}
|
||||
}
|
@ -1409,6 +1409,26 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadNotifications, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-notifications-csv',
|
||||
'route' => '/api/v1/summits/{id}/notifications/csv',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadNotifications, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-notification-by-id',
|
||||
'route' => '/api/v1/summits/{id}/notifications/{notification_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
|
||||
sprintf(SummitScopes::ReadNotifications, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-notifications',
|
||||
'route' => '/api/v1/summits/{id}/notifications',
|
||||
'http_method' => 'POST',
|
||||
|
@ -60,6 +60,44 @@ final class OAuth2SummitNotificationsApiControllerTest extends ProtectedApiTest
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testGetPushNotificationById($summit_id = 24){
|
||||
$notifications_response = $this->testGetApprovedSummitNotifications($summit_id);
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'notification_id' => $notifications_response->data[0]->id
|
||||
];
|
||||
|
||||
$headers = [
|
||||
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"GET",
|
||||
"OAuth2SummitNotificationsApiController@getById",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(200);
|
||||
|
||||
$notification = json_decode($content);
|
||||
$this->assertTrue(!is_null($notification));
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
|
Loading…
x
Reference in New Issue
Block a user