diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2TrackQuestionsTemplateApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2TrackQuestionsTemplateApiController.php index 5f90e95dc..aeac3f10d 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2TrackQuestionsTemplateApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2TrackQuestionsTemplateApiController.php @@ -15,9 +15,11 @@ use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplateConstants; use App\Models\Foundation\Summit\Repositories\ITrackQuestionTemplateRepository; use App\Services\Model\ITrackQuestionTemplateService; +use Illuminate\Http\Response; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Request; use libs\utils\PaginationValidationRules; +use OpenApi\Attributes as OA; use models\exceptions\EntityNotFoundException; use models\exceptions\ValidationException; use Exception; @@ -65,6 +67,30 @@ public function __construct /** * @return mixed */ + #[OA\Get( + path: '/api/v1/track-question-templates', + summary: 'Get all track question templates', + description: 'Returns a paginated list of track question templates', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + parameters: [ + new OA\Parameter(name: 'page', in: 'query', required: false, schema: new OA\Schema(type: 'integer', default: 1)), + new OA\Parameter(name: 'per_page', in: 'query', required: false, schema: new OA\Schema(type: 'integer', default: 5)), + new OA\Parameter(name: 'filter', in: 'query', required: false, description: 'Filter by name, label or class_name', schema: new OA\Schema(type: 'string')), + new OA\Parameter(name: 'order', in: 'query', required: false, description: 'Order by id, name, or label', schema: new OA\Schema(type: 'string')), + new OA\Parameter(name: 'expand', in: 'query', required: false, description: 'Expand relations (tracks)', schema: new OA\Schema(type: 'string')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Success', + content: new OA\JsonContent(ref: '#/components/schemas/PaginatedTrackQuestionTemplatesResponse') + ), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function getTrackQuestionTemplates(){ $values = Request::all(); $rules = PaginationValidationRules::get(); @@ -160,6 +186,32 @@ public function getTrackQuestionTemplates(){ /** * @return mixed */ + #[OA\Post( + path: '/api/v1/track-question-templates', + summary: 'Create a new track question template', + description: 'Creates a new track question template', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionTemplateRequest') + ), + parameters: [ + new OA\Parameter(name: 'expand', in: 'query', required: false, description: 'Expand relations', schema: new OA\Schema(type: 'string')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_CREATED, + description: 'Track Question Template Created', + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionTemplate') + ), + new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function addTrackQuestionTemplate(){ try { @@ -205,6 +257,28 @@ public function addTrackQuestionTemplate(){ * @param $track_question_template_id * @return mixed */ + #[OA\Get( + path: '/api/v1/track-question-templates/{track_question_template_id}', + summary: 'Get a track question template by id', + description: 'Returns a single track question template', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + parameters: [ + new OA\Parameter(name: 'track_question_template_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template id'), + new OA\Parameter(name: 'expand', in: 'query', required: false, description: 'Expand relations', schema: new OA\Schema(type: 'string')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Success', + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionTemplate') + ), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function getTrackQuestionTemplate($track_question_template_id){ try { @@ -234,6 +308,33 @@ public function getTrackQuestionTemplate($track_question_template_id){ * @param $track_question_template_id * @return mixed */ + #[OA\Put( + path: '/api/v1/track-question-templates/{track_question_template_id}', + summary: 'Update a track question template', + description: 'Updates an existing track question template', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionTemplateRequest') + ), + parameters: [ + new OA\Parameter(name: 'track_question_template_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template id'), + new OA\Parameter(name: 'expand', in: 'query', required: false, description: 'Expand relations', schema: new OA\Schema(type: 'string')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Track Question Template Updated', + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionTemplate') + ), + new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function updateTrackQuestionTemplate($track_question_template_id){ try { @@ -278,6 +379,23 @@ public function updateTrackQuestionTemplate($track_question_template_id){ * @param $track_question_template_id * @return mixed */ + #[OA\Delete( + path: '/api/v1/track-question-templates/{track_question_template_id}', + summary: 'Delete a track question template', + description: 'Deletes a track question template', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + parameters: [ + new OA\Parameter(name: 'track_question_template_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template id'), + ], + responses: [ + new OA\Response(response: Response::HTTP_NO_CONTENT, description: 'Track Question Template Deleted'), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function deleteTrackQuestionTemplate($track_question_template_id){ try { @@ -302,6 +420,27 @@ public function deleteTrackQuestionTemplate($track_question_template_id){ /** * @return mixed */ + #[OA\Get( + path: '/api/v1/track-question-templates/metadata', + summary: 'Get track question templates metadata', + description: 'Returns metadata about available track question template types', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Success', + content: new OA\JsonContent( + type: 'object', + properties: [ + new OA\Property(property: 'class_names', type: 'array', items: new OA\Items(type: 'string')), + ] + ) + ), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function getTrackQuestionTemplateMetadata(){ return $this->ok ( @@ -318,6 +457,28 @@ public function getTrackQuestionTemplateMetadata(){ * @param $track_question_template_value_id * @return mixed */ + #[OA\Get( + path: '/api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}', + summary: 'Get a track question template value', + description: 'Returns a single track question template value', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + parameters: [ + new OA\Parameter(name: 'track_question_template_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template id'), + new OA\Parameter(name: 'track_question_template_value_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template value id'), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Success', + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionValueTemplate') + ), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function getTrackQuestionTemplateValue($track_question_template_id, $track_question_template_value_id){ try { @@ -350,6 +511,33 @@ public function getTrackQuestionTemplateValue($track_question_template_id, $trac * @param $track_question_template_id * @return mixed */ + #[OA\Post( + path: '/api/v1/track-question-templates/{track_question_template_id}/values', + summary: 'Add a value to a track question template', + description: 'Adds a new value to a multi-value track question template', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionValueTemplateRequest') + ), + parameters: [ + new OA\Parameter(name: 'track_question_template_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template id'), + new OA\Parameter(name: 'expand', in: 'query', required: false, description: 'Expand relations', schema: new OA\Schema(type: 'string')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_CREATED, + description: 'Track Question Template Value Created', + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionValueTemplate') + ), + new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function addTrackQuestionTemplateValue($track_question_template_id){ try { @@ -399,6 +587,34 @@ public function addTrackQuestionTemplateValue($track_question_template_id){ * @param $track_question_template_value_id * @return mixed */ + #[OA\Put( + path: '/api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}', + summary: 'Update a track question template value', + description: 'Updates an existing track question template value', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionValueTemplateRequest') + ), + parameters: [ + new OA\Parameter(name: 'track_question_template_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template id'), + new OA\Parameter(name: 'track_question_template_value_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template value id'), + new OA\Parameter(name: 'expand', in: 'query', required: false, description: 'Expand relations', schema: new OA\Schema(type: 'string')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Track Question Template Value Updated', + content: new OA\JsonContent(ref: '#/components/schemas/TrackQuestionValueTemplate') + ), + new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function updateTrackQuestionTemplateValue($track_question_template_id, $track_question_template_value_id){ try { @@ -449,6 +665,24 @@ public function updateTrackQuestionTemplateValue($track_question_template_id, $t * @param $track_question_template_value_id * @return mixed */ + #[OA\Delete( + path: '/api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}', + summary: 'Delete a track question template value', + description: 'Deletes a track question template value', + tags: ['track-question-templates'], + security: [['Bearer' => []]], + parameters: [ + new OA\Parameter(name: 'track_question_template_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template id'), + new OA\Parameter(name: 'track_question_template_value_id', in: 'path', required: true, schema: new OA\Schema(type: 'integer'), description: 'The track question template value id'), + ], + responses: [ + new OA\Response(response: Response::HTTP_NO_CONTENT, description: 'Track Question Template Value Deleted'), + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"), + new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function deleteTrackQuestionTemplateValue($track_question_template_id, $track_question_template_value_id){ try { $this->track_question_template_service->deleteTrackQuestionValueTemplate @@ -472,4 +706,4 @@ public function deleteTrackQuestionTemplateValue($track_question_template_id, $t return $this->error500($ex); } } -} \ No newline at end of file +} diff --git a/app/Swagger/SummitPresentationTrackQuestionsSchemas.php b/app/Swagger/SummitPresentationTrackQuestionsSchemas.php index 6b3e2f895..e4b7895d3 100644 --- a/app/Swagger/SummitPresentationTrackQuestionsSchemas.php +++ b/app/Swagger/SummitPresentationTrackQuestionsSchemas.php @@ -4,4 +4,98 @@ use OpenApi\Attributes as OA; -// +#[OA\Schema( + schema: 'TrackQuestionTemplate', + type: 'object', + required: ['id', 'created', 'last_edited', 'name', 'label', 'is_mandatory', 'is_read_only', 'class_name', 'tracks'], + properties: [ + new OA\Property(property: 'id', type: 'integer', example: 1), + new OA\Property(property: 'created', type: 'integer', example: 1634567890), + new OA\Property(property: 'last_edited', type: 'integer', example: 1634567890), + new OA\Property(property: 'name', type: 'string', example: 'my_question'), + new OA\Property(property: 'label', type: 'string', example: 'What is your question?'), + new OA\Property(property: 'is_mandatory', type: 'boolean', example: true), + new OA\Property(property: 'is_read_only', type: 'boolean', example: false), + new OA\Property(property: 'after_question', type: 'string', example: 'previous_question'), + new OA\Property(property: 'class_name', type: 'string', example: 'TrackTextBoxQuestionTemplate'), + new OA\Property( + property: 'tracks', + type: 'array', + items: new OA\Items( + anyOf: [ + new OA\Schema(type: 'integer'), + new OA\Schema(type: 'PresentationCategory') + ] + ) + ), + ] +)] +class TrackQuestionTemplate {} + +#[OA\Schema( + schema: 'PaginatedTrackQuestionTemplatesResponse', + allOf: [ + new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'), + new OA\Schema( + type: 'object', + properties: [ + new OA\Property( + property: 'data', + type: 'array', + items: new OA\Items(ref: '#/components/schemas/TrackQuestionTemplate') + ) + ] + ) + ] +)] +class PaginatedTrackQuestionTemplatesResponse {} + +#[OA\Schema( + schema: 'TrackQuestionValueTemplate', + type: 'object', + required: ['id', 'created', 'last_edited', 'value', 'label', 'order', 'owner_id'], + properties: [ + new OA\Property(property: 'id', type: 'integer', example: 1), + new OA\Property(property: 'created', type: 'integer', example: 1634567890), + new OA\Property(property: 'last_edited', type: 'integer', example: 1634567890), + new OA\Property(property: 'value', type: 'string', example: 'option_value'), + new OA\Property(property: 'label', type: 'string', example: 'Option Label'), + new OA\Property(property: 'order', type: 'integer', example: 1), + new OA\Property(property: 'owner_id', type: 'integer', example: 1), + ] +)] +class TrackQuestionValueTemplate {} + +#[OA\Schema( + schema: 'TrackQuestionTemplateRequest', + type: 'object', + required: ['name', 'label', 'class_name'], + properties: [ + new OA\Property(property: 'name', type: 'string', maxLength: 255, example: 'my_question'), + new OA\Property(property: 'label', type: 'string', example: 'What is your question?'), + new OA\Property(property: 'class_name', type: 'string', example: 'TrackTextBoxQuestionTemplate'), + new OA\Property(property: 'is_mandatory', type: 'boolean', example: true), + new OA\Property(property: 'is_read_only', type: 'boolean', example: false), + new OA\Property(property: 'tracks', type: 'array', items: new OA\Items(type: 'integer'), example: [1, 2, 3]), + new OA\Property(property: 'initial_value', type: 'string', example: 'Default value'), + new OA\Property(property: 'empty_string', type: 'string', example: '-- Select --'), + new OA\Property(property: 'default_value_id', type: 'integer', example: 1), + new OA\Property(property: 'is_multiselect', type: 'boolean', example: false), + new OA\Property(property: 'is_country_selector', type: 'boolean', example: false), + new OA\Property(property: 'content', type: 'string', example: 'Some literal content'), + ] +)] +class TrackQuestionTemplateRequest {} + +#[OA\Schema( + schema: 'TrackQuestionValueTemplateRequest', + type: 'object', + required: ['value', 'label'], + properties: [ + new OA\Property(property: 'value', type: 'string', example: 'option_value'), + new OA\Property(property: 'label', type: 'string', example: 'Option Label'), + new OA\Property(property: 'order', type: 'integer', example: 1), + ] +)] +class TrackQuestionValueTemplateRequest {} +