fix: controller class

This commit is contained in:
FoskyM 2023-10-01 20:30:49 +08:00
parent 3b5354c4af
commit bd1c7f36bb
No known key found for this signature in database
GPG key ID: 42C0ED6994AD7E9C
6 changed files with 21 additions and 26 deletions

View file

@ -2,7 +2,7 @@
namespace FoskyM\OAuthCenter\Api\Controller; namespace FoskyM\OAuthCenter\Api\Controller;
use Flarum\Api\Controller\AbstractListController; use Flarum\Api\Controller\AbstractCreateController;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document;
use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Models\Client;
use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer; use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer;
class CreateClientController extends AbstractListController class CreateClientController extends AbstractCreateController
{ {
public $serializer = ClientSerializer::class; public $serializer = ClientSerializer::class;
protected function data(ServerRequestInterface $request, Document $document) protected function data(ServerRequestInterface $request, Document $document)

View file

@ -2,7 +2,7 @@
namespace FoskyM\OAuthCenter\Api\Controller; namespace FoskyM\OAuthCenter\Api\Controller;
use Flarum\Api\Controller\AbstractListController; use Flarum\Api\Controller\AbstractCreateController;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document;
use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Models\Scope;
use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer;
class CreateScopeController extends AbstractListController class CreateScopeController extends AbstractCreateController
{ {
public $serializer = ScopeSerializer::class; public $serializer = ScopeSerializer::class;
protected function data(ServerRequestInterface $request, Document $document) protected function data(ServerRequestInterface $request, Document $document)

View file

@ -2,7 +2,7 @@
namespace FoskyM\OAuthCenter\Api\Controller; namespace FoskyM\OAuthCenter\Api\Controller;
use Flarum\Api\Controller\AbstractListController; use Flarum\Api\Controller\AbstractDeleteController;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -10,10 +10,10 @@ use Tobscure\JsonApi\Document;
use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Models\Client;
use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer; use FoskyM\OAuthCenter\Api\Serializer\ClientSerializer;
class DeleteClientController extends AbstractListController class DeleteClientController extends AbstractDeleteController
{ {
public $serializer = ClientSerializer::class; public $serializer = ClientSerializer::class;
protected function data(ServerRequestInterface $request, Document $document) protected function delete(ServerRequestInterface $request)
{ {
$id = Arr::get($request->getQueryParams(), 'id'); $id = Arr::get($request->getQueryParams(), 'id');
RequestUtil::getActor($request) RequestUtil::getActor($request)
@ -22,7 +22,5 @@ class DeleteClientController extends AbstractListController
$client = Client::find($id); $client = Client::find($id);
$client->delete(); $client->delete();
return $client;
} }
} }

View file

@ -2,7 +2,7 @@
namespace FoskyM\OAuthCenter\Api\Controller; namespace FoskyM\OAuthCenter\Api\Controller;
use Flarum\Api\Controller\AbstractListController; use Flarum\Api\Controller\AbstractDeleteController;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -10,19 +10,16 @@ use Tobscure\JsonApi\Document;
use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Models\Scope;
use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer;
class DeleteScopeController extends AbstractListController class DeleteScopeController extends AbstractDeleteController
{ {
public $serializer = ScopeSerializer::class; protected function delete(ServerRequestInterface $request)
protected function data(ServerRequestInterface $request, Document $document)
{ {
$id = Arr::get($request->getQueryParams(), 'id'); $id = Arr::get($request->getQueryParams(), 'id');
RequestUtil::getActor($request) RequestUtil::getActor($request)
->assertAdmin(); ->assertAdmin();
$client = Scope::find($id); $scope = Scope::find($id);
$client->delete(); $scope->delete();
return $client;
} }
} }

View file

@ -2,7 +2,7 @@
namespace FoskyM\OAuthCenter\Api\Controller; namespace FoskyM\OAuthCenter\Api\Controller;
use Flarum\Api\Controller\AbstractListController; use Flarum\Api\Controller\AbstractShowController;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document;
use FoskyM\OAuthCenter\Models\Client; use FoskyM\OAuthCenter\Models\Client;
use FoskyM\OAuthCenter\Api\Serializer\ClientPublicSerializer; use FoskyM\OAuthCenter\Api\Serializer\ClientPublicSerializer;
class ShowClientController extends AbstractListController class ShowClientController extends AbstractShowController
{ {
public $serializer = ClientPublicSerializer::class; public $serializer = ClientPublicSerializer::class;
protected function data(ServerRequestInterface $request, Document $document) protected function data(ServerRequestInterface $request, Document $document)

View file

@ -2,7 +2,7 @@
namespace FoskyM\OAuthCenter\Api\Controller; namespace FoskyM\OAuthCenter\Api\Controller;
use Flarum\Api\Controller\AbstractListController; use Flarum\Api\Controller\AbstractShowController;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -10,7 +10,7 @@ use Tobscure\JsonApi\Document;
use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Models\Scope;
use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer;
class UpdateScopeController extends AbstractListController class UpdateScopeController extends AbstractShowController
{ {
public $serializer = ScopeSerializer::class; public $serializer = ScopeSerializer::class;
protected function data(ServerRequestInterface $request, Document $document) protected function data(ServerRequestInterface $request, Document $document)
@ -19,19 +19,19 @@ class UpdateScopeController extends AbstractListController
$actor->assertAdmin(); $actor->assertAdmin();
$id = Arr::get($request->getQueryParams(), 'id'); $id = Arr::get($request->getQueryParams(), 'id');
$client = Scope::find($id); $scope = Scope::find($id);
$attributes = Arr::get($request->getParsedBody(), 'data.attributes', []); $attributes = Arr::get($request->getParsedBody(), 'data.attributes', []);
collect(['scope', 'resource_path', 'method', 'is_default', 'scope_name', 'scope_icon', 'scope_desc']) 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) { if (($val = Arr::get($attributes, $attribute)) !== null) {
$client->$attribute = $val; $scope->$attribute = $val;
} }
}); });
$client->save(); $scope->save();
return $client; return $scope;
} }
} }