From bd1c7f36bb1c5262581887d80552e22ddfeb3761 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 20:30:49 +0800 Subject: [PATCH] fix: controller class --- src/Api/Controller/CreateClientController.php | 4 ++-- src/Api/Controller/CreateScopeController.php | 4 ++-- src/Api/Controller/DeleteClientController.php | 8 +++----- src/Api/Controller/DeleteScopeController.php | 13 +++++-------- src/Api/Controller/ShowClientController.php | 4 ++-- src/Api/Controller/UpdateScopeController.php | 14 +++++++------- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/Api/Controller/CreateClientController.php b/src/Api/Controller/CreateClientController.php index f1b7b2c..866b73b 100644 --- a/src/Api/Controller/CreateClientController.php +++ b/src/Api/Controller/CreateClientController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractCreateController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer; -class CreateClientController extends AbstractListController +class CreateClientController extends AbstractCreateController { public $serializer = ClientSerializer::class; protected function data(ServerRequestInterface $request, Document $document) diff --git a/src/Api/Controller/CreateScopeController.php b/src/Api/Controller/CreateScopeController.php index df0ef23..014d45d 100644 --- a/src/Api/Controller/CreateScopeController.php +++ b/src/Api/Controller/CreateScopeController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractCreateController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; -class CreateScopeController extends AbstractListController +class CreateScopeController extends AbstractCreateController { public $serializer = ScopeSerializer::class; protected function data(ServerRequestInterface $request, Document $document) diff --git a/src/Api/Controller/DeleteClientController.php b/src/Api/Controller/DeleteClientController.php index 17907d0..e585dfa 100644 --- a/src/Api/Controller/DeleteClientController.php +++ b/src/Api/Controller/DeleteClientController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractDeleteController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,10 +10,10 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer; -class DeleteClientController extends AbstractListController +class DeleteClientController extends AbstractDeleteController { public $serializer = ClientSerializer::class; - protected function data(ServerRequestInterface $request, Document $document) + protected function delete(ServerRequestInterface $request) { $id = Arr::get($request->getQueryParams(), 'id'); RequestUtil::getActor($request) @@ -22,7 +22,5 @@ class DeleteClientController extends AbstractListController $client = Client::find($id); $client->delete(); - - return $client; } } diff --git a/src/Api/Controller/DeleteScopeController.php b/src/Api/Controller/DeleteScopeController.php index ec2e22e..52729d8 100644 --- a/src/Api/Controller/DeleteScopeController.php +++ b/src/Api/Controller/DeleteScopeController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractDeleteController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,19 +10,16 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; -class DeleteScopeController extends AbstractListController +class DeleteScopeController extends AbstractDeleteController { - public $serializer = ScopeSerializer::class; - protected function data(ServerRequestInterface $request, Document $document) + protected function delete(ServerRequestInterface $request) { $id = Arr::get($request->getQueryParams(), 'id'); RequestUtil::getActor($request) ->assertAdmin(); - $client = Scope::find($id); + $scope = Scope::find($id); - $client->delete(); - - return $client; + $scope->delete(); } } diff --git a/src/Api/Controller/ShowClientController.php b/src/Api/Controller/ShowClientController.php index 5a64375..784736f 100644 --- a/src/Api/Controller/ShowClientController.php +++ b/src/Api/Controller/ShowClientController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractShowController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Api\Serializer\ClientPublicSerializer; -class ShowClientController extends AbstractListController +class ShowClientController extends AbstractShowController { public $serializer = ClientPublicSerializer::class; protected function data(ServerRequestInterface $request, Document $document) diff --git a/src/Api/Controller/UpdateScopeController.php b/src/Api/Controller/UpdateScopeController.php index d226d38..5f9aeb7 100644 --- a/src/Api/Controller/UpdateScopeController.php +++ b/src/Api/Controller/UpdateScopeController.php @@ -2,7 +2,7 @@ namespace FoskyM\OAuthCenter\Api\Controller; -use Flarum\Api\Controller\AbstractListController; +use Flarum\Api\Controller\AbstractShowController; use Flarum\Http\RequestUtil; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface; @@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; -class UpdateScopeController extends AbstractListController +class UpdateScopeController extends AbstractShowController { public $serializer = ScopeSerializer::class; protected function data(ServerRequestInterface $request, Document $document) @@ -19,19 +19,19 @@ class UpdateScopeController extends AbstractListController $actor->assertAdmin(); $id = Arr::get($request->getQueryParams(), 'id'); - $client = Scope::find($id); + $scope = Scope::find($id); $attributes = Arr::get($request->getParsedBody(), 'data.attributes', []); collect(['scope', 'resource_path', 'method', 'is_default', 'scope_name', 'scope_icon', 'scope_desc']) - ->each(function (string $attribute) use ($client, $attributes) { + ->each(function (string $attribute) use ($scope, $attributes) { if (($val = Arr::get($attributes, $attribute)) !== null) { - $client->$attribute = $val; + $scope->$attribute = $val; } }); - $client->save(); + $scope->save(); - return $client; + return $scope; } }