feat(admin): clients controller

This commit is contained in:
FoskyM 2023-10-01 17:00:51 +08:00
parent cf2abfccf7
commit 1985bd68ca
No known key found for this signature in database
GPG key ID: 42C0ED6994AD7E9C
3 changed files with 10 additions and 20 deletions

View file

@ -18,22 +18,12 @@ class CreateClientController extends AbstractListController
$actor = RequestUtil::getActor($request); $actor = RequestUtil::getActor($request);
$actor->assertAdmin(); $actor->assertAdmin();
$data = Arr::get($request->getParsedBody(), 'data', []); $attributes = Arr::get($request->getParsedBody(), 'data.attributes');
$client = Client::build( return Client::create([
Arr::get($data, 'attributes.name'), 'client_id' => Arr::get($attributes, 'client_id'),
$actor->id, 'client_secret' => Arr::get($attributes, 'client_secret'),
Arr::get($data, 'attributes.icon'), 'user_id' => $actor->id,
Arr::get($data, 'attributes.description'), ]);
Arr::get($data, 'attributes.actions'),
Arr::get($data, 'attributes.metrics'),
Arr::get($data, 'attributes.requirements'),
);
$client->save();
return $client;
} }
} }

View file

@ -18,6 +18,6 @@ class ListClientController extends AbstractListController
$actor = RequestUtil::getActor($request); $actor = RequestUtil::getActor($request);
$actor->assertAdmin(); $actor->assertAdmin();
return Client::get(); return Client::all();
} }
} }

View file

@ -21,11 +21,11 @@ class UpdateClientController extends AbstractListController
$id = Arr::get($request->getQueryParams(), 'id'); $id = Arr::get($request->getQueryParams(), 'id');
$client = Client::find($id); $client = Client::find($id);
$data = Arr::get($request->getParsedBody(), 'data', []); $attributes = Arr::get($request->getParsedBody(), 'data.attributes', []);
collect(['client_id', 'client_secret', 'redirect_uri', 'grant_types', 'scope', 'client_name', 'client_desc', 'client_icon', 'client_home']) collect(['client_id', 'client_secret', 'redirect_uri', 'grant_types', 'scope', 'client_name', 'client_desc', 'client_icon', 'client_home'])
->each(function (string $attribute) use ($client, $data) { ->each(function (string $attribute) use ($client, $attributes) {
if (($val = Arr::get($data, "attributes.$attribute")) !== null) { if (($val = Arr::get($attributes, $attribute)) !== null) {
$client->$attribute = $val; $client->$attribute = $val;
} }
}); });