Added filtering by message to push notifications
Change-Id: I785939bd07892ec74dd693f1e0a997f62b39cc65
This commit is contained in:
parent
2b41e04669
commit
28a96f33c1
@ -207,7 +207,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
|
||||
$summit = SummitFinderStrategyFactory::build($this->getRepository(), $this->getResourceServerContext())->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
return $this->getAll(
|
||||
return $this->_getAll(
|
||||
function(){
|
||||
return [
|
||||
'tag' => ['=@', '=='],
|
||||
@ -247,7 +247,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return \Illuminate\Http\JsonResponse|mixed
|
||||
*/
|
||||
public function getAllEvents()
|
||||
{
|
||||
|
@ -13,7 +13,6 @@
|
||||
**/
|
||||
use App\Http\Utils\BooleanCellFormatter;
|
||||
use App\Http\Utils\EpochCellFormatter;
|
||||
use App\Http\Utils\PagingConstants;
|
||||
use App\Services\Model\ISummitPushNotificationService;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
@ -23,21 +22,22 @@ use models\summit\ISummitNotificationRepository;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use models\summit\ISummitRepository;
|
||||
use models\summit\SummitPushNotificationChannel;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
use utils\Filter;
|
||||
use utils\FilterElement;
|
||||
use utils\FilterParser;
|
||||
use utils\OrderParser;
|
||||
use utils\PagingInfo;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Exception;
|
||||
/**
|
||||
* Class OAuth2SummitNotificationsApiController
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
{
|
||||
|
||||
use ParametrizedGetAll;
|
||||
|
||||
/**
|
||||
* @var ISummitRepository
|
||||
*/
|
||||
@ -84,91 +84,60 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
*/
|
||||
public function getAll($summit_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$summit = SummitFinderStrategyFactory::build($this->getRepository(), $this->getResourceServerContext())->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$values = Input::all();
|
||||
|
||||
$rules = [
|
||||
'page' => 'integer|min:1',
|
||||
'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize),
|
||||
];
|
||||
|
||||
$validation = Validator::make($values, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$ex = new ValidationException();
|
||||
throw $ex->setMessages($validation->messages()->toArray());
|
||||
}
|
||||
|
||||
// default values
|
||||
$page = 1;
|
||||
$per_page = PagingConstants::DefaultPageSize;
|
||||
|
||||
if (Input::has('page')) {
|
||||
$page = intval(Input::get('page'));
|
||||
$per_page = intval(Input::get('per_page'));
|
||||
}
|
||||
|
||||
$filter = null;
|
||||
if (Input::has('filter')) {
|
||||
$filter = FilterParser::parse(Input::get('filter'), [
|
||||
return $this->_getAll(
|
||||
function(){
|
||||
return [
|
||||
'message' => ['=@', '=='],
|
||||
'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'))
|
||||
];
|
||||
},
|
||||
function(){
|
||||
return [
|
||||
'message' => 'sometimes|string',
|
||||
'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',
|
||||
];
|
||||
},
|
||||
function()
|
||||
{
|
||||
$order = OrderParser::parse(Input::get('order'), [
|
||||
return [
|
||||
|
||||
'sent_date',
|
||||
'created',
|
||||
'id',
|
||||
]);
|
||||
}
|
||||
|
||||
$result = $this->repository->getAllByPageBySummit($summit, new PagingInfo($page, $per_page), $filter, $order);
|
||||
|
||||
return $this->ok
|
||||
(
|
||||
$result->toArray(Request::input('expand', ''),[],[],['summit_id' => $summit_id])
|
||||
);
|
||||
}
|
||||
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);
|
||||
}
|
||||
];
|
||||
},
|
||||
function($filter) use($summit){
|
||||
return $filter;
|
||||
},
|
||||
function(){
|
||||
return SerializerRegistry::SerializerType_Public;
|
||||
},
|
||||
null,
|
||||
null,
|
||||
function ($page, $per_page, $filter, $order, $applyExtraFilters) use ($summit){
|
||||
return $this->repository->getAllByPageBySummit
|
||||
(
|
||||
$summit,
|
||||
new PagingInfo($page, $per_page),
|
||||
call_user_func($applyExtraFilters, $filter),
|
||||
$order
|
||||
);
|
||||
},
|
||||
['summit_id' => $summit_id]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -177,89 +146,59 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
* @return \Illuminate\Http\JsonResponse|mixed
|
||||
*/
|
||||
public function getAllApprovedByUser($summit_id){
|
||||
try
|
||||
{
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$current_member = $this->resource_server_context->getCurrentUser();
|
||||
$values = Input::all();
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$rules = [
|
||||
'page' => 'integer|min:1',
|
||||
'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize),
|
||||
];
|
||||
$current_member = $this->resource_server_context->getCurrentUser();
|
||||
|
||||
$validation = Validator::make($values, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$ex = new ValidationException();
|
||||
throw $ex->setMessages($validation->messages()->toArray());
|
||||
}
|
||||
|
||||
// default values
|
||||
$page = 1;
|
||||
$per_page = PagingConstants::DefaultPageSize;
|
||||
|
||||
if (Input::has('page')) {
|
||||
$page = intval(Input::get('page'));
|
||||
}
|
||||
|
||||
if (Input::has('per_page')) {
|
||||
$per_page = intval(Input::get('per_page'));
|
||||
}
|
||||
|
||||
$filter = null;
|
||||
if (Input::has('filter')) {
|
||||
$filter = FilterParser::parse(Input::get('filter'), [
|
||||
return $this->_getAll(
|
||||
function(){
|
||||
return [
|
||||
'message' => ['=@', '=='],
|
||||
'sent_date' => ['>', '<', '<=', '>=', '=='],
|
||||
'created' => ['>', '<', '<=', '>=', '=='],
|
||||
]);
|
||||
}
|
||||
|
||||
if(is_null($filter)) $filter = new Filter();
|
||||
|
||||
$filter->validate([
|
||||
'sent_date' => 'sometimes|date_format:U',
|
||||
'created' => 'sometimes|date_format:U',
|
||||
]);
|
||||
|
||||
$order = null;
|
||||
|
||||
if (Input::has('order'))
|
||||
];
|
||||
},
|
||||
function(){
|
||||
return [
|
||||
'message' => 'sometimes|string',
|
||||
'sent_date' => 'sometimes|date_format:U',
|
||||
'created' => 'sometimes|date_format:U',
|
||||
];
|
||||
},
|
||||
function()
|
||||
{
|
||||
$order = OrderParser::parse(Input::get('order'), [
|
||||
|
||||
return [
|
||||
'sent_date',
|
||||
'created',
|
||||
'id',
|
||||
]);
|
||||
}
|
||||
|
||||
$filter->addFilterCondition(FilterElement::makeEqual("is_sent", true));
|
||||
|
||||
$result = $this->repository->getAllByPageByUserBySummit($current_member, $summit, new PagingInfo($page, $per_page), $filter, $order);
|
||||
|
||||
return $this->ok
|
||||
(
|
||||
$result->toArray(Request::input('expand', ''),[],[],['summit_id' => $summit_id])
|
||||
);
|
||||
}
|
||||
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);
|
||||
}
|
||||
];
|
||||
},
|
||||
function($filter) use($summit){
|
||||
if($filter instanceof Filter) {
|
||||
$filter->addFilterCondition(FilterElement::makeEqual("is_sent", true));
|
||||
}
|
||||
return $filter;
|
||||
},
|
||||
function(){
|
||||
return SerializerRegistry::SerializerType_Public;
|
||||
},
|
||||
null,
|
||||
null,
|
||||
function ($page, $per_page, $filter, $order, $applyExtraFilters) use ($current_member, $summit){
|
||||
return $this->repository->getAllByPageByUserBySummit
|
||||
(
|
||||
$current_member,
|
||||
$summit,
|
||||
new PagingInfo($page, $per_page),
|
||||
call_user_func($applyExtraFilters, $filter),
|
||||
$order
|
||||
);
|
||||
},
|
||||
['summit_id' => $summit_id]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,83 +207,72 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
*/
|
||||
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;
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
|
||||
$filter = null;
|
||||
if (Input::has('filter')) {
|
||||
$filter = FilterParser::parse(Input::get('filter'), [
|
||||
return $this->_getAllCSV(
|
||||
function(){
|
||||
return [
|
||||
'message' => ['=@', '=='],
|
||||
'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'))
|
||||
];
|
||||
},
|
||||
function(){
|
||||
return [
|
||||
'message' => 'sometimes|string',
|
||||
'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',
|
||||
];
|
||||
},
|
||||
function()
|
||||
{
|
||||
$order = OrderParser::parse(Input::get('order'), [
|
||||
return [
|
||||
|
||||
'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'],
|
||||
[
|
||||
];
|
||||
},
|
||||
function($filter) use($summit){
|
||||
return $filter;
|
||||
},
|
||||
function(){
|
||||
return SerializerRegistry::SerializerType_Public;
|
||||
},
|
||||
function(){
|
||||
return [
|
||||
'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);
|
||||
}
|
||||
];
|
||||
},
|
||||
function(){
|
||||
return [];
|
||||
},
|
||||
"push-notification-" . date('Ymd'),
|
||||
['summit_id' => $summit_id],
|
||||
function ($page, $per_page, $filter, $order, $applyExtraFilters) use ($summit){
|
||||
return $this->repository->getAllByPageBySummit
|
||||
(
|
||||
$summit,
|
||||
new PagingInfo($page, $per_page),
|
||||
call_user_func($applyExtraFilters, $filter),
|
||||
$order
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -483,7 +411,7 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
@ -24,6 +25,7 @@ use utils\OrderParser;
|
||||
use utils\PagingInfo;
|
||||
use App\Http\Utils\PagingConstants;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Trait ParametrizedGetAll
|
||||
* @package App\Http\Controllers
|
||||
@ -40,8 +42,9 @@ trait ParametrizedGetAll
|
||||
* @param callable $applyExtraFilters
|
||||
* @return \utils\PagingResponse
|
||||
*/
|
||||
protected function defaultQuery(int $page, int $per_page, Filter $filter, Order $order, callable $applyExtraFilters){
|
||||
return $this->getRepository()->getAllByPage
|
||||
protected function defaultQuery(int $page, int $per_page, Filter $filter, Order $order, callable $applyExtraFilters)
|
||||
{
|
||||
return $this->getRepository()->getAllByPage
|
||||
(
|
||||
new PagingInfo($page, $per_page),
|
||||
call_user_func($applyExtraFilters, $filter),
|
||||
@ -57,9 +60,11 @@ trait ParametrizedGetAll
|
||||
* @param callable $serializerType
|
||||
* @param callable|null $defaultOrderRules
|
||||
* @param callable|null $defaultPageSize
|
||||
* @param callable|null $queryCallable
|
||||
* @param array $serializerParams
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAll
|
||||
public function _getAll
|
||||
(
|
||||
callable $getFilterRules,
|
||||
callable $getFilterValidatorRules,
|
||||
@ -67,15 +72,16 @@ trait ParametrizedGetAll
|
||||
callable $applyExtraFilters,
|
||||
callable $serializerType,
|
||||
callable $defaultOrderRules = null,
|
||||
callable $defaultPageSize = null,
|
||||
callable $queryCallable = null
|
||||
callable $defaultPageSize = null,
|
||||
callable $queryCallable = null,
|
||||
array $serializerParams = []
|
||||
)
|
||||
{
|
||||
$values = Input::all();
|
||||
|
||||
$rules = [
|
||||
$rules = [
|
||||
|
||||
'page' => 'integer|min:1',
|
||||
'page' => 'integer|min:1',
|
||||
'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize),
|
||||
];
|
||||
|
||||
@ -89,11 +95,11 @@ trait ParametrizedGetAll
|
||||
}
|
||||
|
||||
// default values
|
||||
$page = 1;
|
||||
$page = 1;
|
||||
$per_page = is_null($defaultPageSize) ? PagingConstants::DefaultPageSize : call_user_func($defaultPageSize);
|
||||
|
||||
if (Input::has('page')) {
|
||||
$page = intval(Input::get('page'));
|
||||
$page = intval(Input::get('page'));
|
||||
}
|
||||
|
||||
if (Input::has('per_page')) {
|
||||
@ -106,26 +112,24 @@ trait ParametrizedGetAll
|
||||
$filter = FilterParser::parse(Input::get('filter'), call_user_func($getFilterRules));
|
||||
}
|
||||
|
||||
if(is_null($filter)) $filter = new Filter();
|
||||
if (is_null($filter)) $filter = new Filter();
|
||||
|
||||
$filter_validator_rules = call_user_func($getFilterValidatorRules);
|
||||
if(count($filter_validator_rules)) {
|
||||
if (count($filter_validator_rules)) {
|
||||
$filter->validate($filter_validator_rules);
|
||||
}
|
||||
|
||||
$order = null;
|
||||
|
||||
if (Input::has('order'))
|
||||
{
|
||||
if (Input::has('order')) {
|
||||
$order = OrderParser::parse(Input::get('order'), call_user_func($getOrderRules));
|
||||
}
|
||||
else{
|
||||
if(!is_null($defaultOrderRules)){
|
||||
} else {
|
||||
if (!is_null($defaultOrderRules)) {
|
||||
$order = call_user_func($defaultOrderRules);
|
||||
}
|
||||
}
|
||||
|
||||
if(!is_null($queryCallable))
|
||||
if (!is_null($queryCallable))
|
||||
$data = call_user_func($queryCallable,
|
||||
$page,
|
||||
$per_page,
|
||||
@ -133,7 +137,7 @@ trait ParametrizedGetAll
|
||||
$order,
|
||||
$applyExtraFilters);
|
||||
else
|
||||
$data = $this->defaultQuery
|
||||
$data = $this->defaultQuery
|
||||
(
|
||||
$page,
|
||||
$per_page,
|
||||
@ -142,11 +146,11 @@ trait ParametrizedGetAll
|
||||
$applyExtraFilters
|
||||
);
|
||||
|
||||
$fields = Request::input('fields', '');
|
||||
$fields = Request::input('fields', '');
|
||||
$relations = Request::input('relations', '');
|
||||
|
||||
$relations = !empty($relations) ? explode(',', $relations) : [];
|
||||
$fields = !empty($fields) ? explode(',', $fields) : [];
|
||||
$fields = !empty($fields) ? explode(',', $fields) : [];
|
||||
|
||||
return $this->ok
|
||||
(
|
||||
@ -155,27 +159,20 @@ trait ParametrizedGetAll
|
||||
Request::input('expand', ''),
|
||||
$fields,
|
||||
$relations,
|
||||
[],
|
||||
$serializerParams,
|
||||
call_user_func($serializerType)
|
||||
)
|
||||
);
|
||||
}
|
||||
catch (ValidationException $ex1)
|
||||
{
|
||||
} catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch (EntityNotFoundException $ex2)
|
||||
{
|
||||
} catch (EntityNotFoundException $ex2) {
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message' => $ex2->getMessage()));
|
||||
}
|
||||
catch(\HTTP401UnauthorizedException $ex3)
|
||||
{
|
||||
} catch (\HTTP401UnauthorizedException $ex3) {
|
||||
Log::warning($ex3);
|
||||
return $this->error401();
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
@ -189,11 +186,12 @@ trait ParametrizedGetAll
|
||||
* @param callable $serializerType
|
||||
* @param callable $getFormatters
|
||||
* @param callable $getColumns
|
||||
* @param $file_prefix
|
||||
* @param array $serializer_params
|
||||
* @param string $file_prefix
|
||||
* @param array $serializerParams
|
||||
* @param callable|null $queryCallable
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAllCSV
|
||||
public function _getAllCSV
|
||||
(
|
||||
callable $getFilterRules,
|
||||
callable $getFilterValidatorRules,
|
||||
@ -202,13 +200,14 @@ trait ParametrizedGetAll
|
||||
callable $serializerType,
|
||||
callable $getFormatters,
|
||||
callable $getColumns,
|
||||
$file_prefix,
|
||||
array $serializer_params = []
|
||||
string $file_prefix = 'file-',
|
||||
array $serializerParams = [],
|
||||
callable $queryCallable = null
|
||||
)
|
||||
{
|
||||
$values = Input::all();
|
||||
$rules = [
|
||||
'page' => 'integer|min:1',
|
||||
$rules = [
|
||||
'page' => 'integer|min:1',
|
||||
'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize),
|
||||
];
|
||||
|
||||
@ -222,11 +221,11 @@ trait ParametrizedGetAll
|
||||
}
|
||||
|
||||
// default values
|
||||
$page = 1;
|
||||
$page = 1;
|
||||
$per_page = PHP_INT_MAX;
|
||||
|
||||
if (Input::has('page')) {
|
||||
$page = intval(Input::get('page'));
|
||||
$page = intval(Input::get('page'));
|
||||
$per_page = intval(Input::get('per_page'));
|
||||
}
|
||||
|
||||
@ -240,36 +239,53 @@ trait ParametrizedGetAll
|
||||
$filter = FilterParser::parse(Input::get('filter'), call_user_func($getFilterRules));
|
||||
}
|
||||
|
||||
if(is_null($filter)) $filter = new Filter();
|
||||
if (is_null($filter)) $filter = new Filter();
|
||||
|
||||
$filter_validator_rules = call_user_func($getFilterValidatorRules);
|
||||
if(count($filter_validator_rules)) {
|
||||
if (count($filter_validator_rules)) {
|
||||
$filter->validate($filter_validator_rules);
|
||||
}
|
||||
|
||||
$order = null;
|
||||
|
||||
if (Input::has('order'))
|
||||
{
|
||||
if (Input::has('order')) {
|
||||
$order = OrderParser::parse(Input::get('order'), call_user_func($getOrderRules));
|
||||
}
|
||||
|
||||
$data = $this->getRepository()->getAllByPage
|
||||
(
|
||||
new PagingInfo($page, $per_page),
|
||||
call_user_func($applyExtraFilters, $filter),
|
||||
$order
|
||||
);
|
||||
if (!is_null($queryCallable))
|
||||
$data = call_user_func($queryCallable,
|
||||
$page,
|
||||
$per_page,
|
||||
$filter,
|
||||
$order,
|
||||
$applyExtraFilters);
|
||||
else
|
||||
$data = $this->defaultQuery
|
||||
(
|
||||
$page,
|
||||
$per_page,
|
||||
$filter,
|
||||
$order,
|
||||
$applyExtraFilters
|
||||
);
|
||||
|
||||
$filename = $file_prefix . date('Ymd');
|
||||
$list = $data->toArray
|
||||
|
||||
$fields = Request::input('fields', '');
|
||||
$relations = Request::input('relations', '');
|
||||
|
||||
$relations = !empty($relations) ? explode(',', $relations) : [];
|
||||
$fields = !empty($fields) ? explode(',', $fields) : [];
|
||||
|
||||
$list = $data->toArray
|
||||
(
|
||||
Request::input('expand', ''),
|
||||
[],
|
||||
[],
|
||||
$serializer_params,
|
||||
$fields,
|
||||
$relations,
|
||||
$serializerParams,
|
||||
call_user_func($serializerType)
|
||||
);
|
||||
|
||||
return $this->export
|
||||
(
|
||||
'csv',
|
||||
@ -278,23 +294,16 @@ trait ParametrizedGetAll
|
||||
call_user_func($getFormatters),
|
||||
call_user_func($getColumns)
|
||||
);
|
||||
}
|
||||
catch (ValidationException $ex1)
|
||||
{
|
||||
} catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412($ex1->getMessages());
|
||||
}
|
||||
catch (EntityNotFoundException $ex2)
|
||||
{
|
||||
} catch (EntityNotFoundException $ex2) {
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message' => $ex2->getMessage()));
|
||||
}
|
||||
catch(\HTTP401UnauthorizedException $ex3)
|
||||
{
|
||||
} catch (\HTTP401UnauthorizedException $ex3) {
|
||||
Log::warning($ex3);
|
||||
return $this->error401();
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
|
@ -11,6 +11,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use Libs\ModelSerializers\AbstractSerializer;
|
||||
use models\main\PushNotificationMessage;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
use ModelSerializers\SilverStripeSerializer;
|
||||
@ -46,20 +48,20 @@ class PushNotificationMessageSerializer extends SilverStripeSerializer
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
|
||||
if (!empty($expand)) {
|
||||
$exp_expand = explode(',', $expand);
|
||||
foreach ($exp_expand as $relation) {
|
||||
switch (trim($relation)) {
|
||||
foreach (explode(',', $expand) as $relation) {
|
||||
$relation = trim($relation);
|
||||
switch ($relation) {
|
||||
|
||||
case 'owner': {
|
||||
if(!$notification->hasOwner()) continue;
|
||||
unset($values['owner_id']);
|
||||
$values['owner'] = SerializerRegistry::getInstance()->getSerializer($notification->getOwner())->serialize();
|
||||
$values['owner'] = SerializerRegistry::getInstance()->getSerializer($notification->getOwner())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
}
|
||||
break;
|
||||
case 'approved_by': {
|
||||
if(!$notification->hasApprovedBy()) continue;
|
||||
unset($values['approved_by_id']);
|
||||
$values['approved_by'] = SerializerRegistry::getInstance()->getSerializer($notification->getApprovedBy())->serialize();
|
||||
$values['approved_by'] = SerializerRegistry::getInstance()->getSerializer($notification->getApprovedBy())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\ModelSerializers\PushNotificationMessageSerializer;
|
||||
use Libs\ModelSerializers\AbstractSerializer;
|
||||
use models\main\Member;
|
||||
use models\summit\SummitPushNotification;
|
||||
use models\summit\SummitPushNotificationChannel;
|
||||
|
||||
@ -41,17 +43,46 @@ final class SummitPushNotificationSerializer extends PushNotificationMessageSeri
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
|
||||
if($notification->getChannel() == SummitPushNotificationChannel::Event){
|
||||
$values['event'] = SerializerRegistry::getInstance()->getSerializer($notification->getSummitEvent())->serialize();
|
||||
$values['event_id'] = $notification->getSummitEvent()->getId();
|
||||
}
|
||||
|
||||
if($notification->getChannel() == SummitPushNotificationChannel::Group){
|
||||
$values['group'] = SerializerRegistry::getInstance()->getSerializer($notification->getGroup())->serialize();
|
||||
$values['group_id'] = $notification->getGroup()->getId();
|
||||
}
|
||||
|
||||
if($notification->getChannel() == SummitPushNotificationChannel::Members){
|
||||
$values['recipients'] = [];
|
||||
foreach ($notification->getRecipients() as $recipient)
|
||||
$values['recipients'][] = SerializerRegistry::getInstance()->getSerializer($recipient)->serialize();
|
||||
foreach ($notification->getRecipients() as $recipient) {
|
||||
if (!$recipient instanceof Member) continue;
|
||||
$values['recipients'][] = $recipient->getId();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($expand)) {
|
||||
foreach (explode(',', $expand) as $relation) {
|
||||
$relation = trim($relation);
|
||||
switch ($relation) {
|
||||
case 'event': {
|
||||
if($notification->getChannel() != SummitPushNotificationChannel::Event) continue;
|
||||
unset($values['event_id']);
|
||||
$values['event'] = SerializerRegistry::getInstance()->getSerializer($notification->getSummitEvent())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
}
|
||||
break;
|
||||
case 'group': {
|
||||
if($notification->getChannel() != SummitPushNotificationChannel::Group) continue;
|
||||
unset($values['group_id']);
|
||||
$values['group'] = SerializerRegistry::getInstance()->getSerializer($notification->getGroup())->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
}
|
||||
break;
|
||||
case 'recipients': {
|
||||
if($notification->getChannel() != SummitPushNotificationChannel::Members) continue;
|
||||
$values['recipients'] = [];
|
||||
foreach ($notification->getRecipients() as $recipient)
|
||||
$values['recipients'][] = SerializerRegistry::getInstance()->getSerializer($recipient)->serialize(AbstractSerializer::filterExpandByPrefix($relation, $expand));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
@ -172,8 +172,8 @@ final class DoctrineSummitEventRepository
|
||||
protected function getOrderMappings()
|
||||
{
|
||||
return [
|
||||
'title' => 'e.title',
|
||||
'id' => 'e.id',
|
||||
'title' => 'e.title',
|
||||
'start_date' => 'e.start_date',
|
||||
'end_date' => 'e.end_date',
|
||||
'created' => 'e.created',
|
||||
@ -211,10 +211,14 @@ final class DoctrineSummitEventRepository
|
||||
|
||||
if (!is_null($order)) {
|
||||
$order->apply2Query($query, $this->getOrderMappings());
|
||||
if(!$order->hasOrder('id')) {
|
||||
$query = $query->addOrderBy("e.id", 'ASC');
|
||||
}
|
||||
} else {
|
||||
//default order
|
||||
$query = $query->addOrderBy("e.start_date",'ASC');
|
||||
$query = $query->addOrderBy("e.end_date", 'ASC');
|
||||
$query = $query->addOrderBy("e.id", 'ASC');
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,6 +42,7 @@ final class DoctrineSummitNotificationRepository
|
||||
{
|
||||
return [
|
||||
'event_id' => 'e.id:json_int',
|
||||
'message' => 'n.message:json_string',
|
||||
'channel' => 'n.channel:json_string',
|
||||
'sent_date' => 'n.sent_date:datetime_epoch',
|
||||
'created' => 'n.created:datetime_epoch',
|
||||
|
@ -7,8 +7,7 @@
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
stopOnFailure="false">
|
||||
<testsuites>
|
||||
<testsuite name="Application Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
|
@ -612,6 +612,10 @@ final class OAuth2SummitEventsApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($events));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @param string $level
|
||||
*/
|
||||
public function testGetScheduledEventsBySummitAndLevel($summit_id = 27, $level = 'N/A')
|
||||
{
|
||||
$params = [
|
||||
@ -646,6 +650,43 @@ final class OAuth2SummitEventsApiTest extends ProtectedApiTest
|
||||
$this->assertTrue(!is_null($events));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
*/
|
||||
public function testGetScheduledEventsBySummit($summit_id = 27)
|
||||
{
|
||||
$params = [
|
||||
|
||||
'id' => $summit_id,
|
||||
'expand' => 'type,track,location,location.venue,location.floor',
|
||||
'page' => 2,
|
||||
'per_page' => 100,
|
||||
'order' => '+start_date'
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"GET",
|
||||
"OAuth2SummitEventsApiController@getScheduledEvents",
|
||||
$params,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(200);
|
||||
|
||||
$events = json_decode($content);
|
||||
$this->assertTrue(!is_null($events));
|
||||
}
|
||||
|
||||
public function testGetScheduledEventsTags($summit_id = 27)
|
||||
{
|
||||
$params = [
|
||||
|
@ -21,7 +21,7 @@ final class OAuth2SummitNotificationsApiControllerTest extends ProtectedApiTest
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testGetApprovedSummitNotifications($summit_id = 24)
|
||||
public function testGetApprovedSummitNotifications($summit_id = 27)
|
||||
{
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
@ -67,11 +67,12 @@ final class OAuth2SummitNotificationsApiControllerTest extends ProtectedApiTest
|
||||
public function testGetSentSummitNotifications($summit_id = 27)
|
||||
{
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'page' => 1,
|
||||
'id' => $summit_id,
|
||||
'page' => 1,
|
||||
'per_page' => 15,
|
||||
'order' => '+sent_date',
|
||||
'expand' => 'owner,approved_by',
|
||||
'order' => '+sent_date',
|
||||
// 'filter' => 'message=@Shanghai',
|
||||
//'expand' => 'owner,approved_by',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
|
Loading…
Reference in New Issue
Block a user