diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php index de8047119..383b71598 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php @@ -18,6 +18,9 @@ use models\oauth2\IResourceServerContext; use models\summit\ISummitRepository; use ModelSerializers\SerializerRegistry; +use OpenApi\Attributes as OA; +use Symfony\Component\HttpFoundation\Response; + /** * Class OAuth2SponsorshipTypeApiController * @package App\Http\Controllers @@ -101,9 +104,108 @@ protected function getSummitRepository(): ISummitRepository } use GetAndValidateJsonPayload; - /** - * @return \Illuminate\Http\JsonResponse|mixed - */ + + #[OA\Get( + path: "/api/v1/sponsorship-types", + summary: "Get all sponsorship types", + security: [["bearer_token" => []]], + tags: ["SponsorshipTypes"], + 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( + 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/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_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", + security: [["bearer_token" => []]], + tags: ["SponsorshipTypes"], + requestBody: new OA\RequestBody( + required: true, + content: new OA\JsonContent( + required: ["name", "label", "size"], + properties: [ + new OA\Property(property: "name", type: "string", description: "Sponsorship type name"), + new OA\Property(property: "label", type: "string", description: "Display label"), + new OA\Property(property: "size", type: "string", description: "Size category", enum: ["Small", "Medium", "Large", "Big"]), + ] + ) + ), + 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 +226,27 @@ 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", + security: [["bearer_token" => []]], + tags: ["SponsorshipTypes"], + 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 +263,39 @@ public function get($id) }); } - /** - * @param $id - * @return \Illuminate\Http\JsonResponse|mixed - */ + #[OA\Put( + path: "/api/v1/sponsorship-types/{id}", + summary: "Update a sponsorship type", + security: [["bearer_token" => []]], + tags: ["SponsorshipTypes"], + 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( + properties: [ + new OA\Property(property: "name", type: "string", description: "Sponsorship type name"), + new OA\Property(property: "label", type: "string", description: "Display label"), + new OA\Property(property: "size", type: "string", description: "Size category", enum: ["Small", "Medium", "Large", "Big"]), + new OA\Property(property: "order", type: "integer", description: "Display order (minimum: 1)", minimum: 1), + ] + ) + ), + 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 +316,23 @@ public function update($id) }); } - /** - * @param $id - * @return \Illuminate\Http\JsonResponse|mixed - */ + #[OA\Delete( + path: "/api/v1/sponsorship-types/{id}", + summary: "Delete a sponsorship type", + security: [["bearer_token" => []]], + tags: ["SponsorshipTypes"], + 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){ diff --git a/app/Swagger/SponsorshipTypeSchemas.php b/app/Swagger/SponsorshipTypeSchemas.php new file mode 100644 index 000000000..f3b43dd26 --- /dev/null +++ b/app/Swagger/SponsorshipTypeSchemas.php @@ -0,0 +1,19 @@ +