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->assertAdmin();
$data = Arr::get($request->getParsedBody(), 'data', []);
$attributes = Arr::get($request->getParsedBody(), 'data.attributes');
$client = Client::build(
Arr::get($data, 'attributes.name'),
$actor->id,
Arr::get($data, 'attributes.icon'),
Arr::get($data, 'attributes.description'),
Arr::get($data, 'attributes.actions'),
Arr::get($data, 'attributes.metrics'),
Arr::get($data, 'attributes.requirements'),
);
$client->save();
return $client;
return Client::create([
'client_id' => Arr::get($attributes, 'client_id'),
'client_secret' => Arr::get($attributes, 'client_secret'),
'user_id' => $actor->id,
]);
}
}

View file

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

View file

@ -21,11 +21,11 @@ class UpdateClientController extends AbstractListController
$id = Arr::get($request->getQueryParams(), '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'])
->each(function (string $attribute) use ($client, $data) {
if (($val = Arr::get($data, "attributes.$attribute")) !== null) {
->each(function (string $attribute) use ($client, $attributes) {
if (($val = Arr::get($attributes, $attribute)) !== null) {
$client->$attribute = $val;
}
});