diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitTaxTypeApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitTaxTypeApiController.php index 6739d3ee6..879ed86ef 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitTaxTypeApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitTaxTypeApiController.php @@ -1,4 +1,7 @@ - [ + SummitScopes::ReadSummitData, + SummitScopes::ReadAllSummitData, + ] + ] + ], + tags: ['Summits Tax Types'], + parameters: [ + + new OA\Parameter( + name: 'page', + in: 'query', + required: false, + description: 'Page number for pagination', + schema: new OA\Schema(type: 'integer', example: 1) + ), + new OA\Parameter( + name: 'per_page', + in: 'query', + required: false, + description: 'Items per page', + schema: new OA\Schema(type: 'integer', example: 10, maximum: 100) + ), + new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'filter', in: 'query', description: 'Filter by name (name=@value, name==value)', schema: new OA\Schema(type: 'string')), + new OA\Parameter(name: 'order', in: 'query', description: 'Order by: +/-id, +/-name', schema: new OA\Schema(type: 'string')), + new OA\Parameter(name: 'relations', in: 'query', description: 'Relations to include: ticket_types', schema: new OA\Schema(type: 'string')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Successful response', + content: new OA\JsonContent(ref: '#/components/schemas/PaginatedSummitTaxTypesResponse') + ), + 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_FORBIDDEN, description: "Forbidden"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] + public function getAllBySummit($summit_id) + { + return parent::getAllBySummit($summit_id); + } + + #[OA\Post( + path: '/api/v1/summits/{id}/tax-types', + summary: 'Create a new tax type', + operationId: 'createTaxType', + security: [ + [ + 'tax_types_oauth2' => [ + SummitScopes::WriteSummitData, + ] + ] + ], + x: [ + 'required-groups' => [ + IGroup::SuperAdmins, + IGroup::Administrators, + IGroup::SummitAdministrators, + IGroup::SummitRegistrationAdmins, + ] + ], + tags: ['Summits Tax Types'], + parameters: [ + new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')), + ], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: '#/components/schemas/SummitTaxTypeCreateRequest') + ), + responses: [ + new OA\Response( + response: Response::HTTP_CREATED, + description: 'Tax type created', + content: new OA\JsonContent(ref: '#/components/schemas/SummitTaxType') + ), + 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_FORBIDDEN, description: "Forbidden"), + 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 add($summit_id) + { + return parent::add($summit_id); + } + + #[OA\Get( + path: '/api/v1/summits/{id}/tax-types/{tax_id}', + summary: 'Get a tax type by ID', + operationId: 'getTaxType', + security: [ + [ + 'tax_types_oauth2' => [ + SummitScopes::ReadSummitData, + SummitScopes::ReadAllSummitData, + ] + ] + ], + x: [ + 'required-groups' => [ + IGroup::SuperAdmins, + IGroup::Administrators, + IGroup::SummitAdministrators, + IGroup::SummitRegistrationAdmins, + ] + ], + tags: ['Summits Tax Types'], + parameters: [ + new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'tax_id', in: 'path', required: true, description: 'Tax Type ID', schema: new OA\Schema(type: 'integer')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Successful response', + content: new OA\JsonContent(ref: '#/components/schemas/SummitTaxType') + ), + 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_FORBIDDEN, description: "Forbidden"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] + public function get($summit_id, $tax_id) + { + return parent::get($summit_id, $tax_id); + } + + #[OA\Put( + path: '/api/v1/summits/{id}/tax-types/{tax_id}', + summary: 'Update a tax type', + operationId: 'updateTaxType', + security: [ + [ + 'tax_types_oauth2' => [ + SummitScopes::WriteSummitData, + ] + ] + ], + x: [ + 'required-groups' => [ + IGroup::SuperAdmins, + IGroup::Administrators, + IGroup::SummitAdministrators, + IGroup::SummitRegistrationAdmins, + ] + ], + tags: ['Summits Tax Types'], + parameters: [ + new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'tax_id', in: 'path', required: true, description: 'Tax Type ID', schema: new OA\Schema(type: 'integer')), + ], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: '#/components/schemas/SummitTaxTypeUpdateRequest') + ), + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Tax type updated', + content: new OA\JsonContent(ref: '#/components/schemas/SummitTaxType') + ), + 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_FORBIDDEN, description: "Forbidden"), + 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 update($summit_id, $tax_id) + { + return parent::update($summit_id, $tax_id); + } + + #[OA\Delete( + path: '/api/v1/summits/{id}/tax-types/{tax_id}', + summary: 'Delete a tax type', + operationId: 'deleteTaxType', + security: [ + [ + 'tax_types_oauth2' => [ + SummitScopes::WriteSummitData, + ] + ] + ], + x: [ + 'required-groups' => [ + IGroup::SuperAdmins, + IGroup::Administrators, + IGroup::SummitAdministrators, + IGroup::SummitRegistrationAdmins, + ] + ], + tags: ['Summits Tax Types'], + parameters: [ + new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'tax_id', in: 'path', required: true, description: 'Tax Type ID', schema: new OA\Schema(type: 'integer')), + ], + responses: [ + new OA\Response(response: Response::HTTP_NO_CONTENT, description: "No Content"), + 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_FORBIDDEN, description: "Forbidden"), + new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not found"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] + public function delete($summit_id, $tax_id) + { + return parent::delete($summit_id, $tax_id); + } + /** * @return array */ - protected function getFilterRules():array + protected function getFilterRules(): array { return [ 'name' => ['=@', '=='], @@ -62,7 +295,8 @@ protected function getFilterRules():array /** * @return array */ - protected function getFilterValidatorRules():array{ + protected function getFilterValidatorRules(): array + { return [ 'name' => 'sometimes|required|string', ]; @@ -70,7 +304,8 @@ protected function getFilterValidatorRules():array{ /** * @return array */ - protected function getOrderRules():array{ + protected function getOrderRules(): array + { return [ 'id', 'name', @@ -83,8 +318,7 @@ public function __construct ISummitRepository $summit_repository, ISummitTaxTypeService $service, IResourceServerContext $resource_server_context - ) - { + ) { parent::__construct($resource_server_context); $this->repository = $repository; $this->summit_repository = $summit_repository; @@ -163,25 +397,62 @@ protected function deleteChild(Summit $summit, $child_id): void * @param $ticket_type_id * @return \Illuminate\Http\JsonResponse|mixed */ - public function addTaxToTicketType($summit_id, $tax_id, $ticket_type_id){ + #[OA\Put( + path: '/api/v1/summits/{id}/tax-types/{tax_id}/ticket-types/{ticket_type_id}', + summary: 'Add a tax type to a ticket type', + operationId: 'addTaxTypeToTicketType', + security: [ + [ + 'tax_types_oauth2' => [ + SummitScopes::WriteSummitData, + ] + ] + ], + x: [ + 'required-groups' => [ + IGroup::SuperAdmins, + IGroup::Administrators, + IGroup::SummitAdministrators, + IGroup::SummitRegistrationAdmins, + ] + ], + tags: ['Summits Tax Types'], + parameters: [ + new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'tax_id', in: 'path', required: true, description: 'Tax Type ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'ticket_type_id', in: 'path', required: true, description: 'Ticket Type ID', schema: new OA\Schema(type: 'integer')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Tax type added to ticket type successfully', + content: new OA\JsonContent(ref: '#/components/schemas/SummitTaxType') + ), + 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_FORBIDDEN, description: "Forbidden"), + 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 addTaxToTicketType($summit_id, $tax_id, $ticket_type_id) + { try { $summit = SummitFinderStrategyFactory::build($this->getSummitRepository(), $this->getResourceServerContext())->find($summit_id); - if (is_null($summit)) return $this->error404(); + if (is_null($summit)) + return $this->error404(); $child = $this->service->addTaxTypeToTicketType($summit, $tax_id, $ticket_type_id); return $this->updated(SerializerRegistry::getInstance()->getSerializer($child)->serialize()); - } - 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 (Exception $ex) { + return $this->error404(array('message' => $ex2->getMessage())); + } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } @@ -193,25 +464,62 @@ public function addTaxToTicketType($summit_id, $tax_id, $ticket_type_id){ * @param $ticket_type_id * @return \Illuminate\Http\JsonResponse|mixed */ - public function removeTaxFromTicketType($summit_id, $tax_id, $ticket_type_id){ + #[OA\Delete( + path: '/api/v1/summits/{id}/tax-types/{tax_id}/ticket-types/{ticket_type_id}', + summary: 'Remove a tax type from a ticket type', + operationId: 'removeTaxTypeFromTicketType', + security: [ + [ + 'tax_types_oauth2' => [ + SummitScopes::WriteSummitData, + ] + ] + ], + x: [ + 'required-groups' => [ + IGroup::SuperAdmins, + IGroup::Administrators, + IGroup::SummitAdministrators, + IGroup::SummitRegistrationAdmins, + ] + ], + tags: ['Summits Tax Types'], + parameters: [ + new OA\Parameter(name: 'id', in: 'path', required: true, description: 'Summit ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'tax_id', in: 'path', required: true, description: 'Tax Type ID', schema: new OA\Schema(type: 'integer')), + new OA\Parameter(name: 'ticket_type_id', in: 'path', required: true, description: 'Ticket Type ID', schema: new OA\Schema(type: 'integer')), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: 'Tax type removed from ticket type successfully', + content: new OA\JsonContent(ref: '#/components/schemas/SummitTaxType') + ), + 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_FORBIDDEN, description: "Forbidden"), + 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 removeTaxFromTicketType($summit_id, $tax_id, $ticket_type_id) + { try { $summit = SummitFinderStrategyFactory::build($this->getSummitRepository(), $this->getResourceServerContext())->find($summit_id); - if (is_null($summit)) return $this->error404(); + if (is_null($summit)) + return $this->error404(); $child = $this->service->removeTaxTypeFromTicketType($summit, $tax_id, $ticket_type_id); return $this->updated(SerializerRegistry::getInstance()->getSerializer($child)->serialize()); - } - 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 (Exception $ex) { + return $this->error404(array('message' => $ex2->getMessage())); + } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } diff --git a/app/Swagger/Models/SummitTaxTypeSchema.php b/app/Swagger/Models/SummitTaxTypeSchema.php new file mode 100644 index 000000000..7617b9f59 --- /dev/null +++ b/app/Swagger/Models/SummitTaxTypeSchema.php @@ -0,0 +1,33 @@ + 'Read Summit Data', + SummitScopes::ReadAllSummitData => 'Read All Summit Data', + SummitScopes::WriteSummitData => 'Write Summit Data', + ], + ), + ], +) +] +class TaxTypesAuthSchema +{ +} \ No newline at end of file diff --git a/app/Swagger/SummitRegistrationSchemas.php b/app/Swagger/SummitRegistrationSchemas.php index 2d2860b2a..b0c396f20 100644 --- a/app/Swagger/SummitRegistrationSchemas.php +++ b/app/Swagger/SummitRegistrationSchemas.php @@ -4,6 +4,53 @@ use OpenApi\Attributes as OA; +#[OA\Schema( + schema: 'PaginatedSummitTaxTypesResponse', + 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/SummitTaxType') + ) + ] + ) + ] +)] +class PaginatedSummitTaxTypesResponseSchema +{ +} + +#[OA\Schema( + schema: 'SummitTaxTypeCreateRequest', + type: 'object', + required: ['name', 'rate'], + properties: [ + new OA\Property(property: 'name', type: 'string', example: 'VAT'), + new OA\Property(property: 'tax_id', type: 'string', example: 'VAT-001'), + new OA\Property(property: 'rate', type: 'number', format: 'float', example: 21.0, description: 'Rate must be greater than 0'), + ] +)] +class SummitTaxTypeCreateRequestSchema +{ +} + +#[OA\Schema( + schema: 'SummitTaxTypeUpdateRequest', + type: 'object', + properties: [ + new OA\Property(property: 'name', type: 'string', example: 'VAT'), + new OA\Property(property: 'tax_id', type: 'string', example: 'VAT-001'), + new OA\Property(property: 'rate', type: 'number', format: 'float', example: 21.0, description: 'Rate must be greater than 0'), + ] +)] +class SummitTaxTypeUpdateRequestSchema +{ +} + // Badge Types #[OA\Schema( @@ -22,7 +69,7 @@ ) ] )] -class PaginatedSummitBadgeTypesResponse +class PaginatedSummitBadgeTypesResponseSchema { } @@ -38,7 +85,7 @@ class PaginatedSummitBadgeTypesResponse new OA\Property(property: "is_default", type: "boolean", example: false), ] )] -class SummitBadgeTypeCreateRequest +class SummitBadgeTypeCreateRequestSchema { } @@ -53,12 +100,10 @@ class SummitBadgeTypeCreateRequest new OA\Property(property: "is_default", type: "boolean", nullable: true, example: false), ] )] -class SummitBadgeTypeUpdateRequest +class SummitBadgeTypeUpdateRequestSchema { } -// - // Summit Badge Feature Types #[OA\Schema( @@ -77,7 +122,9 @@ class SummitBadgeTypeUpdateRequest ) ] )] -class PaginatedSummitBadgeFeatureTypesResponseSchema {} +class PaginatedSummitBadgeFeatureTypesResponseSchema +{ +} #[OA\Schema( schema: 'SummitBadgeFeatureTypeCreateRequest', @@ -89,7 +136,9 @@ class PaginatedSummitBadgeFeatureTypesResponseSchema {} new OA\Property(property: 'template_content', type: 'string', example: '
{{name}}
'), ] )] -class SummitBadgeFeatureTypeCreateRequestSchema {} +class SummitBadgeFeatureTypeCreateRequestSchema +{ +} #[OA\Schema( schema: 'SummitBadgeFeatureTypeUpdateRequest', @@ -100,4 +149,6 @@ class SummitBadgeFeatureTypeCreateRequestSchema {} new OA\Property(property: 'template_content', type: 'string', example: '
{{name}}
'), ] )] -class SummitBadgeFeatureTypeUpdateRequestSchema {} +class SummitBadgeFeatureTypeUpdateRequestSchema +{ +} \ No newline at end of file