diff --git a/Api/AuthenticationApiInterface.php b/Api/AuthenticationApiInterface.php index f8211ae1..57505790 100755 --- a/Api/AuthenticationApiInterface.php +++ b/Api/AuthenticationApiInterface.php @@ -70,7 +70,7 @@ public function authenticationDelete( /** * Operation authenticationGet. * - * Check token + * Check JWT token validity * * @param int &$responseCode The HTTP Response Code * @param array $responseHeaders Additional HTTP headers to return with the response () @@ -98,7 +98,7 @@ public function authenticationOauthPost( /** * Operation authenticationPost. * - * Login + * Login - create a new JWT token * * @param LoginRequest $login_request (required) * @param int &$responseCode The HTTP Response Code diff --git a/Api/StudioApiInterface.php b/Api/StudioApiInterface.php index 8ed85e2c..288fa6b4 100755 --- a/Api/StudioApiInterface.php +++ b/Api/StudioApiInterface.php @@ -50,9 +50,43 @@ interface StudioApiInterface public function setBearerAuth(?string $value): void; /** - * Operation studioIdPut. + * Operation studioIdDelete. * - * Update a Studio + * Delete a studio (only available to studio admins) + * + * @param string $id (required) + * @param string $accept_language (optional, default to 'en') + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () + */ + public function studioIdDelete( + string $id, + string $accept_language, + int &$responseCode, + array &$responseHeaders + ): void; + + /** + * Operation studioIdGet. + * + * Get studio details (private studios are only available to members) + * + * @param string $id (required) + * @param string $accept_language (optional, default to 'en') + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () + */ + public function studioIdGet( + string $id, + string $accept_language, + int &$responseCode, + array &$responseHeaders + ): array|object|null; + + /** + * Operation studioIdPost. + * + * Update a Studio (only available to studio admins) * * @param string $id (required) * @param string $accept_language (optional, default to 'en') @@ -64,7 +98,7 @@ public function setBearerAuth(?string $value): void; * @param int &$responseCode The HTTP Response Code * @param array $responseHeaders Additional HTTP headers to return with the response () */ - public function studioIdPut( + public function studioIdPost( string $id, string $accept_language, ?string $name, diff --git a/Controller/AuthenticationController.php b/Controller/AuthenticationController.php index c929f461..407a319f 100755 --- a/Controller/AuthenticationController.php +++ b/Controller/AuthenticationController.php @@ -123,7 +123,7 @@ public function authenticationDeleteAction(Request $request) /** * Operation authenticationGet. * - * Check token + * Check JWT token validity * * @param Request $request the Symfony request to handle * @@ -265,7 +265,7 @@ public function authenticationOauthPostAction(Request $request) /** * Operation authenticationPost. * - * Login + * Login - create a new JWT token * * @param Request $request the Symfony request to handle * diff --git a/Controller/StudioController.php b/Controller/StudioController.php index 894f1a5f..cace06a6 100755 --- a/Controller/StudioController.php +++ b/Controller/StudioController.php @@ -48,15 +48,183 @@ class StudioController extends Controller { /** - * Operation studioIdPut. + * Operation studioIdDelete. * - * Update a Studio + * Delete a studio (only available to studio admins) * * @param Request $request the Symfony request to handle * * @return Response the Symfony response */ - public function studioIdPutAction(Request $request, $id) + public function studioIdDeleteAction(Request $request, $id) + { + // Handle authentication + // Authentication 'BearerAuth' required + // HTTP bearer authentication required + $securityBearerAuth = $request->headers->get('authorization'); + + // Read out all input parameter values into variables + $accept_language = $request->headers->get('Accept-Language', 'en'); + + // Use the default value if no value was provided + + // Deserialize the input values that needs it + try { + $id = $this->deserialize($id, 'string', 'string'); + $accept_language = $this->deserialize($accept_language, 'string', 'string'); + } catch (SerializerRuntimeException $exception) { + return $this->createBadRequestResponse($exception->getMessage()); + } + + // Validate the input values + $asserts = []; + $asserts[] = new Assert\NotNull(); + $asserts[] = new Assert\Type('string'); + $asserts[] = new Assert\Regex('/^[a-zA-Z0-9\\-]+$/'); + $response = $this->validate($id, $asserts); + if ($response instanceof Response) { + return $response; + } + $asserts = []; + $asserts[] = new Assert\Type('string'); + $response = $this->validate($accept_language, $asserts); + if ($response instanceof Response) { + return $response; + } + + try { + $handler = $this->getApiHandler(); + + // Set authentication method 'BearerAuth' + $handler->setBearerAuth($securityBearerAuth); + + // Make the call to the business logic + $responseCode = 204; + $responseHeaders = []; + + $handler->studioIdDelete($id, $accept_language, $responseCode, $responseHeaders); + + $message = match ($responseCode) { + 204 => 'OK', + 400 => 'Bad request (Invalid, or missing parameters)', + 401 => 'Invalid JWT token | JWT token not found | JWT token expired', + 403 => 'Insufficient privileges, action not allowed.', + 404 => 'Not found', + 406 => 'Not acceptable - client must accept application/json as content type', + default => '', + }; + + return new Response( + '', + $responseCode, + array_merge( + $responseHeaders, + [ + 'X-OpenAPI-Message' => $message, + ] + ) + ); + } catch (\Throwable $fallthrough) { + return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); + } + } + + /** + * Operation studioIdGet. + * + * Get studio details (private studios are only available to members) + * + * @param Request $request the Symfony request to handle + * + * @return Response the Symfony response + */ + public function studioIdGetAction(Request $request, $id) + { + // Figure out what data format to return to the client + $produces = ['application/json']; + // Figure out what the client accepts + $clientAccepts = $request->headers->has('Accept') ? $request->headers->get('Accept') : '*/*'; + $responseFormat = $this->getOutputFormat($clientAccepts, $produces); + if (null === $responseFormat) { + return new Response('', 406); + } + + // Handle authentication + + // Read out all input parameter values into variables + $accept_language = $request->headers->get('Accept-Language', 'en'); + + // Use the default value if no value was provided + + // Deserialize the input values that needs it + try { + $id = $this->deserialize($id, 'string', 'string'); + $accept_language = $this->deserialize($accept_language, 'string', 'string'); + } catch (SerializerRuntimeException $exception) { + return $this->createBadRequestResponse($exception->getMessage()); + } + + // Validate the input values + $asserts = []; + $asserts[] = new Assert\NotNull(); + $asserts[] = new Assert\Type('string'); + $asserts[] = new Assert\Regex('/^[a-zA-Z0-9\\-]+$/'); + $response = $this->validate($id, $asserts); + if ($response instanceof Response) { + return $response; + } + $asserts = []; + $asserts[] = new Assert\Type('string'); + $response = $this->validate($accept_language, $asserts); + if ($response instanceof Response) { + return $response; + } + + try { + $handler = $this->getApiHandler(); + + // Make the call to the business logic + $responseCode = 200; + $responseHeaders = []; + + $result = $handler->studioIdGet($id, $accept_language, $responseCode, $responseHeaders); + + $message = match ($responseCode) { + 200 => 'OK', + 400 => 'Bad request (Invalid, or missing parameters)', + 401 => 'Invalid JWT token | JWT token not found | JWT token expired', + 403 => 'Insufficient privileges, action not allowed.', + 404 => 'Not found', + 406 => 'Not acceptable - client must accept application/json as content type', + default => '', + }; + + return new Response( + null !== $result ? $this->serialize($result, $responseFormat) : '', + $responseCode, + array_merge( + $responseHeaders, + [ + 'Content-Type' => $responseFormat, + 'X-OpenAPI-Message' => $message, + ] + ) + ); + } catch (\Throwable $fallthrough) { + return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); + } + } + + /** + * Operation studioIdPost. + * + * Update a Studio (only available to studio admins) + * + * @param Request $request the Symfony request to handle + * + * @return Response the Symfony response + */ + public function studioIdPostAction(Request $request, $id) { // Figure out what data format to return to the client $produces = ['application/json']; @@ -150,7 +318,7 @@ public function studioIdPutAction(Request $request, $id) $responseCode = 200; $responseHeaders = []; - $result = $handler->studioIdPut($id, $accept_language, $name, $description, $is_public, $enable_comments, $image_file, $responseCode, $responseHeaders); + $result = $handler->studioIdPost($id, $accept_language, $name, $description, $is_public, $enable_comments, $image_file, $responseCode, $responseHeaders); $message = match ($responseCode) { 200 => 'Studio successfully updated.', diff --git a/README.md b/README.md index a4291f96..cddb242e 100755 --- a/README.md +++ b/README.md @@ -112,9 +112,9 @@ All URIs are relative to *https://share.catrob.at/api* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *AuthenticationApiInterface* | [**authenticationDelete**](docs/Api/AuthenticationApiInterface.md#authenticationdelete) | **DELETE** /authentication | Expires refresh token -*AuthenticationApiInterface* | [**authenticationGet**](docs/Api/AuthenticationApiInterface.md#authenticationget) | **GET** /authentication | Check token +*AuthenticationApiInterface* | [**authenticationGet**](docs/Api/AuthenticationApiInterface.md#authenticationget) | **GET** /authentication | Check JWT token validity *AuthenticationApiInterface* | [**authenticationOauthPost**](docs/Api/AuthenticationApiInterface.md#authenticationoauthpost) | **POST** /authentication/oauth | OAuth Login -*AuthenticationApiInterface* | [**authenticationPost**](docs/Api/AuthenticationApiInterface.md#authenticationpost) | **POST** /authentication | Login +*AuthenticationApiInterface* | [**authenticationPost**](docs/Api/AuthenticationApiInterface.md#authenticationpost) | **POST** /authentication | Login - create a new JWT token *AuthenticationApiInterface* | [**authenticationRefreshPost**](docs/Api/AuthenticationApiInterface.md#authenticationrefreshpost) | **POST** /authentication/refresh | Refresh token *AuthenticationApiInterface* | [**authenticationUpgradePost**](docs/Api/AuthenticationApiInterface.md#authenticationupgradepost) | **POST** /authentication/upgrade | Upgrade a deprecated token to JWT *MediaLibraryApiInterface* | [**mediaFileIdGet**](docs/Api/MediaLibraryApiInterface.md#mediafileidget) | **GET** /media/file/{id} | Get the information of a specific media file @@ -141,7 +141,9 @@ Class | Method | HTTP request | Description *ProjectsApiInterface* | [**projectsUserGet**](docs/Api/ProjectsApiInterface.md#projectsuserget) | **GET** /projects/user | Get the projects of the logged in user *ProjectsApiInterface* | [**projectsUserIdGet**](docs/Api/ProjectsApiInterface.md#projectsuseridget) | **GET** /projects/user/{id} | Get the public projects of a given user *SearchApiInterface* | [**searchGet**](docs/Api/SearchApiInterface.md#searchget) | **GET** /search | Search for projects, users,.. -*StudioApiInterface* | [**studioIdPut**](docs/Api/StudioApiInterface.md#studioidput) | **PUT** /studio/{id} | Update a Studio +*StudioApiInterface* | [**studioIdDelete**](docs/Api/StudioApiInterface.md#studioiddelete) | **DELETE** /studio/{id} | Delete a studio (only available to studio admins) +*StudioApiInterface* | [**studioIdGet**](docs/Api/StudioApiInterface.md#studioidget) | **GET** /studio/{id} | Get studio details (private studios are only available to members) +*StudioApiInterface* | [**studioIdPost**](docs/Api/StudioApiInterface.md#studioidpost) | **POST** /studio/{id} | Update a Studio (only available to studio admins) *StudioApiInterface* | [**studioPost**](docs/Api/StudioApiInterface.md#studiopost) | **POST** /studio | Create a new Studio *UserApiInterface* | [**userDelete**](docs/Api/UserApiInterface.md#userdelete) | **DELETE** /user | Delete user account *UserApiInterface* | [**userGet**](docs/Api/UserApiInterface.md#userget) | **GET** /user | Get your private user data diff --git a/Resources/config/routing.yaml b/Resources/config/routing.yaml index 9030469c..e1c0cc44 100755 --- a/Resources/config/routing.yaml +++ b/Resources/config/routing.yaml @@ -208,11 +208,27 @@ open_api_server_search_searchget: _controller: open_api_server.controller.search::searchGetAction # studio -open_api_server_studio_studioidput: +open_api_server_studio_studioiddelete: path: /studio/{id} - methods: [PUT] + methods: [DELETE] + defaults: + _controller: open_api_server.controller.studio::studioIdDeleteAction + requirements: + id: '^[a-zA-Z0-9\\-]+$' + +open_api_server_studio_studioidget: + path: /studio/{id} + methods: [GET] + defaults: + _controller: open_api_server.controller.studio::studioIdGetAction + requirements: + id: '^[a-zA-Z0-9\\-]+$' + +open_api_server_studio_studioidpost: + path: /studio/{id} + methods: [POST] defaults: - _controller: open_api_server.controller.studio::studioIdPutAction + _controller: open_api_server.controller.studio::studioIdPostAction requirements: id: '^[a-zA-Z0-9\\-]+$' diff --git a/Tests/Api/AuthenticationApiInterfaceTest.php b/Tests/Api/AuthenticationApiInterfaceTest.php index 37544be7..ccee8b7c 100755 --- a/Tests/Api/AuthenticationApiInterfaceTest.php +++ b/Tests/Api/AuthenticationApiInterfaceTest.php @@ -98,7 +98,7 @@ public function testAuthenticationDelete(): void /** * Test case for authenticationGet. * - * Check token. + * Check JWT token validity. */ public function testAuthenticationGet(): void { @@ -128,7 +128,7 @@ public function testAuthenticationOauthPost(): void /** * Test case for authenticationPost. * - * Login. + * Login - create a new JWT token. */ public function testAuthenticationPost(): void { diff --git a/Tests/Api/StudioApiInterfaceTest.php b/Tests/Api/StudioApiInterfaceTest.php index 1d05a878..491a8c0b 100755 --- a/Tests/Api/StudioApiInterfaceTest.php +++ b/Tests/Api/StudioApiInterfaceTest.php @@ -81,11 +81,11 @@ public static function tearDownAfterClass(): void } /** - * Test case for studioIdPut. + * Test case for studioIdDelete. * - * Update a Studio. + * Delete a studio (only available to studio admins). */ - public function testStudioIdPut(): void + public function testStudioIdDelete(): void { $client = self::$client; @@ -94,8 +94,44 @@ public function testStudioIdPut(): void $data = $this->genTestData('^[a-zA-Z0-9\-]+$'); $path = str_replace($pattern, $data, $path); - $crawler = $client->request('PUT', $path); - $this->markTestSkipped('Test for studioIdPut not implemented'); + $crawler = $client->request('DELETE', $path); + $this->markTestSkipped('Test for studioIdDelete not implemented'); + } + + /** + * Test case for studioIdGet. + * + * Get studio details (private studios are only available to members). + */ + public function testStudioIdGet(): void + { + $client = self::$client; + + $path = '/studio/{id}'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for studioIdGet not implemented'); + } + + /** + * Test case for studioIdPost. + * + * Update a Studio (only available to studio admins). + */ + public function testStudioIdPost(): void + { + $client = self::$client; + + $path = '/studio/{id}'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('POST', $path); + $this->markTestSkipped('Test for studioIdPost not implemented'); } /** diff --git a/docs/Api/AuthenticationApiInterface.md b/docs/Api/AuthenticationApiInterface.md index 3fe15d69..2851cade 100755 --- a/docs/Api/AuthenticationApiInterface.md +++ b/docs/Api/AuthenticationApiInterface.md @@ -5,9 +5,9 @@ All URIs are relative to *https://share.catrob.at/api* Method | HTTP request | Description ------------- | ------------- | ------------- [**authenticationDelete**](AuthenticationApiInterface.md#authenticationDelete) | **DELETE** /authentication | Expires refresh token -[**authenticationGet**](AuthenticationApiInterface.md#authenticationGet) | **GET** /authentication | Check token +[**authenticationGet**](AuthenticationApiInterface.md#authenticationGet) | **GET** /authentication | Check JWT token validity [**authenticationOauthPost**](AuthenticationApiInterface.md#authenticationOauthPost) | **POST** /authentication/oauth | OAuth Login -[**authenticationPost**](AuthenticationApiInterface.md#authenticationPost) | **POST** /authentication | Login +[**authenticationPost**](AuthenticationApiInterface.md#authenticationPost) | **POST** /authentication | Login - create a new JWT token [**authenticationRefreshPost**](AuthenticationApiInterface.md#authenticationRefreshPost) | **POST** /authentication/refresh | Refresh token [**authenticationUpgradePost**](AuthenticationApiInterface.md#authenticationUpgradePost) | **POST** /authentication/upgrade | Upgrade a deprecated token to JWT @@ -80,9 +80,9 @@ void (empty response body) ## **authenticationGet** > authenticationGet() -Check token +Check JWT token validity -Checks if a token is valid or expired +Checks if a token is valid or expired. ### Example Implementation ```php @@ -185,7 +185,7 @@ No authorization required ## **authenticationPost** > OpenAPI\Server\Model\JWTResponse authenticationPost($login_request) -Login +Login - create a new JWT token Returns an JWT token which provides authorization for a limited time diff --git a/docs/Api/StudioApiInterface.md b/docs/Api/StudioApiInterface.md index fd2d0246..d7af0dd4 100755 --- a/docs/Api/StudioApiInterface.md +++ b/docs/Api/StudioApiInterface.md @@ -4,7 +4,9 @@ All URIs are relative to *https://share.catrob.at/api* Method | HTTP request | Description ------------- | ------------- | ------------- -[**studioIdPut**](StudioApiInterface.md#studioIdPut) | **PUT** /studio/{id} | Update a Studio +[**studioIdDelete**](StudioApiInterface.md#studioIdDelete) | **DELETE** /studio/{id} | Delete a studio (only available to studio admins) +[**studioIdGet**](StudioApiInterface.md#studioIdGet) | **GET** /studio/{id} | Get studio details (private studios are only available to members) +[**studioIdPost**](StudioApiInterface.md#studioIdPost) | **POST** /studio/{id} | Update a Studio (only available to studio admins) [**studioPost**](StudioApiInterface.md#studioPost) | **POST** /studio | Create a new Studio @@ -19,10 +21,10 @@ services: # ... ``` -## **studioIdPut** -> OpenAPI\Server\Model\StudioResponse studioIdPut($id, $accept_language, $name, $description, $is_public, $enable_comments, $image_file) +## **studioIdDelete** +> studioIdDelete($id, $accept_language) -Update a Studio +Delete a studio (only available to studio admins) ### Example Implementation ```php @@ -39,9 +41,115 @@ class StudioApi implements StudioApiInterface // ... /** - * Implementation of StudioApiInterface#studioIdPut + * Implementation of StudioApiInterface#studioIdDelete */ - public function studioIdPut(string $id, string $accept_language, ?string $name, ?string $description, ?bool $is_public, ?bool $enable_comments, ?UploadedFile $image_file, int &$responseCode, array &$responseHeaders): array|object|null + public function studioIdDelete(string $id, string $accept_language, int &$responseCode, array &$responseHeaders): void + { + // Implement the operation ... + } + + // ... +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **id** | **string**| | + **accept_language** | **string**| | [optional] [default to 'en'] + +### Return type + +void (empty response body) + +### Authorization + +[BearerAuth](../../README.md#BearerAuth) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +## **studioIdGet** +> OpenAPI\Server\Model\StudioResponse studioIdGet($id, $accept_language) + +Get studio details (private studios are only available to members) + +### Example Implementation +```php + OpenAPI\Server\Model\StudioResponse studioIdPost($id, $accept_language, $name, $description, $is_public, $enable_comments, $image_file) + +Update a Studio (only available to studio admins) + +### Example Implementation +```php +