
POST /api/v1/summits/{id}/rsvp-templates/{template_id}/questions payload Base Payload * class_name (string:in:RSVPMemberEmailQuestionTemplate, RSVPMemberFirstNameQuestionTemplate, RSVPMemberLastNameQuestionTemplate, RSVPTextBoxQuestionTemplate, RSVPTextAreaQuestionTemplate, RSVPCheckBoxListQuestionTemplate, RSVPRadioButtonListQuestionTemplate, RSVPDropDownQuestionTemplate, RSVPLiteralContentQuestionTemplate ) * name (required|alpha_dash|max:255) * label (required|string) * is_mandatory (sometimes|boolean) * is_read_only (sometimes|boolean) RSVPTextBoxQuestionTemplate, RSVPTextAreaQuestionTemplate * initial_value (string|sometimes) RSVPCheckBoxListQuestionTemplate,RSVPRadioButtonListQuestionTemplate * empty_string (required|string) RSVPDropDownQuestionTemplate * is_multiselect (sometimes|boolean) * is_country_selector (sometimes|boolean) * use_chosen_plugin (sometimes|boolean) RSVPLiteralContentQuestionTemplate * content (required|string) Change-Id: I16ee3aaa7d556d3e0a8d41ceca2514568098b981
285 lines
8.9 KiB
PHP
285 lines
8.9 KiB
PHP
<?php namespace App\Http\Controllers;
|
|
/**
|
|
* Copyright 2018 OpenStack Foundation
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
**/
|
|
use App\Http\Utils\PagingConstants;
|
|
use App\Models\Foundation\Summit\Repositories\IRSVPTemplateRepository;
|
|
use App\Services\Model\IRSVPTemplateService;
|
|
use Illuminate\Support\Facades\Input;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use models\exceptions\EntityNotFoundException;
|
|
use models\exceptions\ValidationException;
|
|
use models\oauth2\IResourceServerContext;
|
|
use models\summit\ISummitRepository;
|
|
use ModelSerializers\SerializerRegistry;
|
|
use utils\Filter;
|
|
use utils\FilterParser;
|
|
use utils\OrderParser;
|
|
use utils\PagingInfo;
|
|
/**
|
|
* Class OAuth2SummitRSVPTemplatesApiController
|
|
* @package App\Http\Controllers
|
|
*/
|
|
final class OAuth2SummitRSVPTemplatesApiController extends OAuth2ProtectedController
|
|
{
|
|
|
|
/**
|
|
* @var ISummitRepository
|
|
*/
|
|
private $summit_repository;
|
|
|
|
/**
|
|
* @var IRSVPTemplateRepository
|
|
*/
|
|
private $rsvp_template_repository;
|
|
|
|
/**
|
|
* @var IRSVPTemplateService
|
|
*/
|
|
private $rsvp_template_service;
|
|
|
|
/**
|
|
* OAuth2SummitRSVPTemplatesApiController constructor.
|
|
* @param ISummitRepository $summit_repository
|
|
* @param IRSVPTemplateRepository $rsvp_template_repository
|
|
* @param IRSVPTemplateService $rsvp_template_service
|
|
* @param IResourceServerContext $resource_server_context
|
|
*/
|
|
public function __construct
|
|
(
|
|
ISummitRepository $summit_repository,
|
|
IRSVPTemplateRepository $rsvp_template_repository,
|
|
IRSVPTemplateService $rsvp_template_service,
|
|
IResourceServerContext $resource_server_context
|
|
)
|
|
{
|
|
parent::__construct($resource_server_context);
|
|
$this->summit_repository = $summit_repository;
|
|
$this->rsvp_template_service = $rsvp_template_service;
|
|
$this->rsvp_template_repository = $rsvp_template_repository;
|
|
}
|
|
|
|
/**
|
|
* @param $summit_id
|
|
* @return mixed
|
|
*/
|
|
public function getAllBySummit($summit_id){
|
|
|
|
$values = Input::all();
|
|
$rules = [
|
|
|
|
'page' => 'integer|min:1',
|
|
'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize),
|
|
];
|
|
|
|
try {
|
|
|
|
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
|
if (is_null($summit))
|
|
return $this->error404();
|
|
|
|
$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'), [
|
|
'title' => ['=@', '=='],
|
|
'is_enabled' => [ '=='],
|
|
]);
|
|
}
|
|
|
|
if(is_null($filter)) $filter = new Filter();
|
|
|
|
$filter->validate([
|
|
'title' => 'sometimes|string',
|
|
'is_enabled' => 'sometimes|boolean',
|
|
]);
|
|
|
|
$order = null;
|
|
|
|
if (Input::has('order'))
|
|
{
|
|
$order = OrderParser::parse(Input::get('order'), [
|
|
'id',
|
|
'title',
|
|
]);
|
|
}
|
|
|
|
$data = $this->rsvp_template_repository->getBySummit($summit, new PagingInfo($page, $per_page), $filter, $order);
|
|
|
|
return $this->ok
|
|
(
|
|
$data->toArray
|
|
(
|
|
Request::input('expand', ''),
|
|
[],
|
|
[],
|
|
[]
|
|
)
|
|
);
|
|
}
|
|
catch (ValidationException $ex1)
|
|
{
|
|
Log::warning($ex1);
|
|
return $this->error412([ $ex1->getMessage()]);
|
|
}
|
|
catch (EntityNotFoundException $ex2)
|
|
{
|
|
Log::warning($ex2);
|
|
return $this->error404(['message' => $ex2->getMessage()]);
|
|
}
|
|
catch(\HTTP401UnauthorizedException $ex3)
|
|
{
|
|
Log::warning($ex3);
|
|
return $this->error401();
|
|
}
|
|
catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
return $this->error500($ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $summit_id
|
|
* @param $template_id
|
|
* @return mixed
|
|
*/
|
|
public function getRSVPTemplate($summit_id, $template_id){
|
|
try {
|
|
|
|
$expand = Request::input('expand', '');
|
|
$relations = Request::input('relations', '');
|
|
$relations = !empty($relations) ? explode(',', $relations) : [];
|
|
|
|
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
|
if (is_null($summit)) return $this->error404();
|
|
|
|
$template = $summit->getRSVPTemplateById($template_id);
|
|
|
|
if (is_null($template)) {
|
|
return $this->error404();
|
|
}
|
|
|
|
return $this->ok(SerializerRegistry::getInstance()->getSerializer($template)->serialize($expand,[], $relations));
|
|
}
|
|
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 $template_id
|
|
* @return mixed
|
|
*/
|
|
public function deleteRSVPTemplate($summit_id, $template_id){
|
|
try {
|
|
|
|
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
|
if (is_null($summit)) return $this->error404();
|
|
|
|
$this->rsvp_template_service->deleteTemplate($summit, $template_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);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Questions endpoints
|
|
*/
|
|
|
|
/**
|
|
* @param $summit_id
|
|
* @param $template_id
|
|
* @return mixed
|
|
*/
|
|
public function addRSVPTemplateQuestion($summit_id, $template_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 = SummitRSVPTemplateQuestionValidationRulesFactory::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
|
|
);
|
|
}
|
|
|
|
$question = $this->rsvp_template_service->addQuestion($summit, $template_id, $payload);
|
|
|
|
return $this->created(SerializerRegistry::getInstance()->getSerializer($question)->serialize());
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
} |