Added endpoints
GET /api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id} PUT /api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id} Payload Base Payload * class_name (string:in:RSVPMemberEmailQuestionTemplate, RSVPMemberFirstNameQuestionTemplate, RSVPMemberLastNameQuestionTemplate, RSVPTextBoxQuestionTemplate, RSVPTextAreaQuestionTemplate, RSVPCheckBoxListQuestionTemplate, RSVPRadioButtonListQuestionTemplate, RSVPDropDownQuestionTemplate, RSVPLiteralContentQuestionTemplate ) * name (sometimes|alpha_dash|max:255) * label (sometimes|string) * is_mandatory (sometimes|boolean) * is_read_only (sometimes|boolean) RSVPTextBoxQuestionTemplate, RSVPTextAreaQuestionTemplate * initial_value (string|sometimes) RSVPCheckBoxListQuestionTemplate,RSVPRadioButtonListQuestionTemplate * empty_string (sometimes|string) RSVPDropDownQuestionTemplate * is_multiselect (sometimes|boolean) * is_country_selector (sometimes|boolean) * use_chosen_plugin (sometimes|boolean) RSVPLiteralContentQuestionTemplate * content (sometimes|string) Change-Id: If25eaca50a8b727317ebf15774300753557facdc
This commit is contained in:
parent
888bed528b
commit
8b8e08e051
|
@ -237,6 +237,41 @@ final class OAuth2SummitRSVPTemplatesApiController extends OAuth2ProtectedContro
|
|||
* Questions endpoints
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $template_id
|
||||
* @param $question_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRSVPTemplateQuestion($summit_id, $template_id, $question_id){
|
||||
try {
|
||||
|
||||
|
||||
$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();
|
||||
|
||||
$question = $template->getQuestionById($question_id);
|
||||
if (is_null($question)) return $this->error404();
|
||||
return $this->ok(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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $template_id
|
||||
|
@ -282,4 +317,51 @@ final class OAuth2SummitRSVPTemplatesApiController extends OAuth2ProtectedContro
|
|||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $template_id
|
||||
* @param $question_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateRSVPTemplateQuestion($summit_id, $template_id, $question_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, true);
|
||||
// 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->updateQuestion($summit, $template_id, $question_id, $payload);
|
||||
|
||||
return $this->updated(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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -172,6 +172,10 @@ Route::group([
|
|||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@deleteRSVPTemplate']);
|
||||
Route::group(['prefix' => 'questions'], function () {
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@addRSVPTemplateQuestion']);
|
||||
Route::group(['prefix' => '{question_id}'], function () {
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@updateRSVPTemplateQuestion']);
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@getRSVPTemplateQuestion']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,4 +39,16 @@ interface IRSVPTemplateService
|
|||
* @throws ValidationException
|
||||
*/
|
||||
public function addQuestion(Summit $summit, $template_id, array $payload);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $template_id
|
||||
* @param int $question_id
|
||||
* @param array $payload
|
||||
* @return RSVPQuestionTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateQuestion(Summit $summit, $template_id, $question_id, array $payload);
|
||||
|
||||
}
|
|
@ -18,7 +18,6 @@ use libs\utils\ITransactionService;
|
|||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\summit\Summit;
|
||||
|
||||
/**
|
||||
* Class RSVPTemplateService
|
||||
* @package App\Services\Model
|
||||
|
@ -61,7 +60,14 @@ final class RSVPTemplateService implements IRSVPTemplateService
|
|||
if(is_null($template))
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans()
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.deleteTemplate.TemplateNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$summit->removeRSVPTemplate($template);
|
||||
|
@ -87,7 +93,7 @@ final class RSVPTemplateService implements IRSVPTemplateService
|
|||
(
|
||||
trans
|
||||
(
|
||||
'',
|
||||
'not_found_errors.RSVPTemplateService.addQuestion.TemplateNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
|
@ -101,7 +107,7 @@ final class RSVPTemplateService implements IRSVPTemplateService
|
|||
(
|
||||
trans
|
||||
(
|
||||
'',
|
||||
'validation_errors.RSVPTemplateService.addQuestion.QuestionNameAlreadyExists',
|
||||
[
|
||||
'template_id' => $template_id,
|
||||
'name' => $data['name']
|
||||
|
@ -117,4 +123,69 @@ final class RSVPTemplateService implements IRSVPTemplateService
|
|||
return $question;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $template_id
|
||||
* @param int $question_id
|
||||
* @param array $data
|
||||
* @return RSVPQuestionTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateQuestion(Summit $summit, $template_id, $question_id, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $template_id, $question_id, $data){
|
||||
|
||||
$template = $summit->getRSVPTemplateById($template_id);
|
||||
|
||||
if(is_null($template))
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.updateQuestion.TemplateNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$question = $template->getQuestionById($question_id);
|
||||
if(is_null($question))
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.updateQuestion.QuestionNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
'question_id' => $question_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
if(isset($data['name'])) {
|
||||
$former_question = $template->getQuestionByName($data['name']);
|
||||
if (!is_null($former_question) && $former_question->getId() != $question_id) {
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.RSVPTemplateService.updateQuestion.QuestionNameAlreadyExists',
|
||||
[
|
||||
'template_id' => $template_id,
|
||||
'name' => $data['name']
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return SummitRSVPTemplateQuestionFactory::populate($question, $data);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -41,4 +41,9 @@ return [
|
|||
'LocationService.updateLocationImage.ImageNotFound' => 'image :image_id does not belongs to location :location_id',
|
||||
'LocationService.deleteLocationImage.LocationNotFound' => 'location :location_id not found on summit :summit_id',
|
||||
'LocationService.deleteLocationImage.ImageNotFound' => 'image :image_id not found on location :location_id',
|
||||
// RSVP Template Service
|
||||
'RSVPTemplateService.deleteTemplate.TemplateNotFound' => 'template :template_id not found on summit :summit_id',
|
||||
'RSVPTemplateService.addQuestion.TemplateNotFound' => 'template :template_id not found on summit :summit_id',
|
||||
'RSVPTemplateService.updateQuestion.TemplateNotFound' => 'template :template_id not found on summit :summit_id',
|
||||
'RSVPTemplateService.updateQuestion.QuestionNotFound' => 'question :question_id not found on template :template_id',
|
||||
];
|
|
@ -51,4 +51,7 @@ return [
|
|||
'LocationService.addLocationImage.FileMaxSize' => 'file exceeds max_file_size (:max_file_size MB)',
|
||||
'LocationService.updateLocationImage.FileNotAllowedExtension' => 'file extension is not allowed (:allowed_extensions)',
|
||||
'LocationService.updateLocationImage.FileMaxSize' => 'file exceeds max_file_size (:max_file_size MB)',
|
||||
// RSVP Template Service
|
||||
'RSVPTemplateService.addQuestion.QuestionNameAlreadyExists' => 'question name :name already exists for template :template_id',
|
||||
'RSVPTemplateService.updateQuestion.QuestionNameAlreadyExists' => 'question name :name already exists for template :template_id',
|
||||
];
|
|
@ -52,7 +52,6 @@ final class OAuth2SummitRSVPTemplateApiTest extends ProtectedApiTest
|
|||
|
||||
$templates = $this->testGetSummitRSVPTemplates($summit_id);
|
||||
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'template_id' => $templates->data[0]->id,
|
||||
|
@ -201,4 +200,46 @@ final class OAuth2SummitRSVPTemplateApiTest extends ProtectedApiTest
|
|||
$this->assertTrue(!is_null($question));
|
||||
return $question;
|
||||
}
|
||||
|
||||
public function testUpdateRSVPTemplateQuestion($summit_id = 24){
|
||||
|
||||
$templates = $this->testGetSummitRSVPTemplates($summit_id);
|
||||
$template = $templates->data[0];
|
||||
$question = $template->questions[0];
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'template_id' => $template->id,
|
||||
'question_id' => $question->id
|
||||
];
|
||||
|
||||
$data = [
|
||||
'name' => $question->name,
|
||||
'label' => $question->label.' update!',
|
||||
'class_name' => $question->class_name
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"PUT",
|
||||
"OAuth2SummitRSVPTemplatesApiController@updateRSVPTemplateQuestion",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
|
||||
$question = json_decode($content);
|
||||
$this->assertTrue(!is_null($question));
|
||||
return $question;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue