diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php index de8047119..ccb9325ce 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php @@ -13,11 +13,17 @@ **/ use App\Models\Foundation\Summit\Repositories\ISponsorshipTypeRepository; use App\ModelSerializers\SerializerUtils; +use App\Security\SummitScopes; use App\Services\Model\ISponsorshipTypeService; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Log; use models\oauth2\IResourceServerContext; use models\summit\ISummitRepository; use ModelSerializers\SerializerRegistry; +use App\Models\Foundation\Main\IGroup; +use OpenApi\Attributes as OA; +use Symfony\Component\HttpFoundation\Response; + /** * Class OAuth2SponsorshipTypeApiController * @package App\Http\Controllers @@ -101,9 +107,108 @@ protected function getSummitRepository(): ISummitRepository } use GetAndValidateJsonPayload; - /** - * @return \Illuminate\Http\JsonResponse|mixed - */ + + #[OA\Get( + path: "/api/v1/sponsorship-types", + summary: "Get all sponsorship types", + operationId: 'getSponsorshipTypes', + x: [ + 'required-groups' => [ + IGroup::SummitAdministrators, + IGroup::SuperAdmins, + IGroup::Administrators + ] + ], + security: [['summit_sponsorship_oauth2' => [ + SummitScopes::ReadSummitData, + SummitScopes::ReadAllSummitData, + ]]], + tags: ["Sponsorship Types"], + parameters: [ + new OA\Parameter(name: "page", description: "Page number", in: "query", required: false, schema: new OA\Schema(type: "integer", default: 1)), + new OA\Parameter(name: "per_page", description: "Items per page", in: "query", required: false, schema: new OA\Schema(type: "integer", default: 10)), + new OA\Parameter(name: "filter", description: "Filter query (name==value, label=@value, size==value)", in: "query", required: false, schema: new OA\Schema(type: "string")), + new OA\Parameter(name: "order", description: "Order by (+id, -name, +order, +label, +size)", in: "query", required: false, schema: new OA\Schema(type: "string")), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: "OK", + content: new OA\JsonContent(ref: '#/components/schemas/PaginatedDataSponsorshipType'), + ), + 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_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] + public function getAll() + { + return $this->_getAll( + function(){ + return [ + 'name' => ['==', '=@'], + 'label' => ['==', '=@'], + 'size' => ['==', '=@'], + ]; + }, + function(){ + return [ + 'name' => 'sometimes|required|string', + 'label' => 'sometimes|required|string', + 'size' => 'sometimes|required|string', + ]; + }, + function(){ + return [ + 'id', + 'name', + 'order', + 'label', + 'size', + ]; + }, + function($filter){ + return $filter; + }, + function(){ + return SerializerRegistry::SerializerType_Public; + } + ); + } + + #[OA\Post( + path: "/api/v1/sponsorship-types", + summary: "Add a new sponsorship type", + operationId: 'addSponsorshipType', + x: [ + 'required-groups' => [ + IGroup::SummitAdministrators, + IGroup::SuperAdmins, + IGroup::Administrators + ] + ], + security: [['summit_sponsorship_oauth2' => [ + SummitScopes::WriteSummitData, + ]]], + tags: ["Sponsorship Types"], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipTypeAddRequest") + ), + responses: [ + new OA\Response( + response: Response::HTTP_CREATED, + description: "Created", + content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipType") + ), + 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_PRECONDITION_FAILED, description: "Validation Error"), + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"), + ] + )] public function add() { return $this->processRequest(function(){ @@ -124,10 +229,31 @@ public function add() }); } - /** - * @param $id - * @return \Illuminate\Http\JsonResponse|mixed - */ + #[OA\Get( + path: "/api/v1/sponsorship-types/{id}", + summary: "Get a sponsorship type by id", + operationId: 'getSponsorshipType', + security: [['summit_sponsorship_oauth2' => [ + SummitScopes::ReadSummitData, + SummitScopes::ReadAllSummitData, + ]]], + tags: ["Sponsorship Types"], + parameters: [ + new OA\Parameter(name: "id", description: "Sponsorship Type ID", in: "path", required: true, schema: new OA\Schema(type: "integer")), + ], + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: "OK", + content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipType") + ), + 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($id) { return $this->processRequest(function() use($id){ @@ -144,10 +270,42 @@ public function get($id) }); } - /** - * @param $id - * @return \Illuminate\Http\JsonResponse|mixed - */ + #[OA\Put( + path: "/api/v1/sponsorship-types/{id}", + summary: "Update a sponsorship type", + operationId: 'updateSponsorshipType', + x: [ + 'required-groups' => [ + IGroup::SummitAdministrators, + IGroup::SuperAdmins, + IGroup::Administrators + ] + ], + security: [['summit_sponsorship_oauth2' => [ + SummitScopes::WriteSummitData, + ]]], + tags: ["Sponsorship Types"], + parameters: [ + new OA\Parameter(name: "id", description: "Sponsorship Type ID", in: "path", required: true, schema: new OA\Schema(type: "integer")), + ], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipTypeUpdateRequest") + ), + responses: [ + new OA\Response( + response: Response::HTTP_OK, + description: "OK", + content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipType") + ), + 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($id) { return $this->processRequest(function() use($id){ @@ -168,10 +326,33 @@ public function update($id) }); } - /** - * @param $id - * @return \Illuminate\Http\JsonResponse|mixed - */ + #[OA\Delete( + path: "/api/v1/sponsorship-types/{id}", + summary: "Delete a sponsorship type", + operationId: 'deleteSponsorshipType', + x: [ + 'required-groups' => [ + IGroup::SummitAdministrators, + IGroup::SuperAdmins, + IGroup::Administrators + ] + ], + security: [['summit_sponsorship_oauth2' => [ + SummitScopes::WriteSummitData, + ]]], + tags: ["Sponsorship Types"], + parameters: [ + new OA\Parameter(name: "id", description: "Sponsorship Type ID", in: "path", required: true, 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($id) { return $this->processRequest(function() use($id){ @@ -179,4 +360,4 @@ public function delete($id) return $this->deleted(); }); } -} \ No newline at end of file +} diff --git a/app/Swagger/Models/SponsorshipTypeSchema.php b/app/Swagger/Models/SponsorshipTypeSchema.php index 2d3a75d03..eff0f95bd 100644 --- a/app/Swagger/Models/SponsorshipTypeSchema.php +++ b/app/Swagger/Models/SponsorshipTypeSchema.php @@ -4,20 +4,49 @@ use OpenApi\Attributes as OA; - #[OA\Schema( schema: 'SponsorshipType', type: 'object', properties: [ - new OA\Property(property: 'id', type: 'integer', example: 1), - new OA\Property(property: 'created', type: 'integer', example: 1), - new OA\Property(property: 'last_edited', type: 'integer', example: 1), - new OA\Property(property: 'name', type: 'string', ), - new OA\Property(property: 'label', type: 'string', ), - new OA\Property(property: 'order', type: 'integer', ), - new OA\Property(property: 'size', type: 'string', ), - ]) -] + new OA\Property( + property: 'id', + type: 'integer', + description: 'Sponsorship type identifier' + ), + new OA\Property( + property: 'created', + type: 'integer', + format: 'int64', + description: 'Creation timestamp (UNIX epoch)' + ), + new OA\Property( + property: 'last_edited', + type: 'integer', + format: 'int64', + description: 'Last modification timestamp (UNIX epoch)' + ), + new OA\Property( + property: 'name', + type: 'string', + description: 'Sponsorship type name' + ), + new OA\Property( + property: 'label', + type: 'string', + description: 'Sponsorship type display label' + ), + new OA\Property( + property: 'order', + type: 'integer', + description: 'Display order' + ), + new OA\Property( + property: 'size', + type: 'string', + description: 'Sponsorship size category (Small, Medium, Large, Big)' + ), + ] +)] class SponsorshipTypeSchema { -} \ No newline at end of file +} diff --git a/app/Swagger/Security/SponsorshipTypeAuthSchema.php b/app/Swagger/Security/SponsorshipTypeAuthSchema.php new file mode 100644 index 000000000..5fdff1479 --- /dev/null +++ b/app/Swagger/Security/SponsorshipTypeAuthSchema.php @@ -0,0 +1,25 @@ + 'Read Sponsorship Types Data', + SummitScopes::ReadAllSummitData => 'Read All Sponsorship Types Data', + SummitScopes::WriteSummitData => 'Write Sponsorship Types Data', + ], + ), + ], + ) +] +class SponsorshipTypeAuthSchema {} diff --git a/app/Swagger/Security/SponsorshipTypeOauthSchemas.php b/app/Swagger/Security/SponsorshipTypeOauthSchemas.php new file mode 100644 index 000000000..ad36b5a46 --- /dev/null +++ b/app/Swagger/Security/SponsorshipTypeOauthSchemas.php @@ -0,0 +1,6 @@ +