Change Settings attributes and routes

This commit is contained in:
Bubka 2021-10-03 11:35:09 +02:00
parent 8dc5e7d6e9
commit 361ee38cf2
6 changed files with 26 additions and 32 deletions

View File

@ -39,8 +39,8 @@ public function index()
$settingsResources = collect();
$settings->each(function ($item, $key) use ($settingsResources) {
$settingsResources->push([
'name' => $key,
'data' => $item
'key' => $key,
'value' => $item
]);
});
@ -52,21 +52,21 @@ public function index()
/**
* Display a resource
*
* @param string $name
* @param string $settingName
*
* @return \App\Http\Resources\TwoFAccountReadResource
*/
public function show($name)
public function show($settingName)
{
$setting = $this->settingService->get($name);
$setting = $this->settingService->get($settingName);
if (!$setting) {
abort(404);
}
return response()->json([
'name' => $name,
'data' => $setting
'key' => $settingName,
'value' => $setting
], 200);
}
@ -79,11 +79,11 @@ public function store(SettingStoreRequest $request)
{
$validated = $request->validated();
$this->settingService->set($validated['name'], $validated['data']);
$this->settingService->set($validated['key'], $validated['value']);
return response()->json([
'name' => $validated['name'],
'data' => $validated['data']
'key' => $validated['key'],
'value' => $validated['value']
], 201);
}
@ -92,21 +92,15 @@ public function store(SettingStoreRequest $request)
* Save options
* @return [type] [description]
*/
public function update(SettingUpdateRequest $request, $name)
public function update(SettingUpdateRequest $request, $settingName)
{
$validated = $request->validated();
$setting = $this->settingService->get($name);
if (is_null($setting)) {
abort(404);
}
$setting = $this->settingService->set($name, $validated['data']);
$this->settingService->set($settingName, $validated['value']);
return response()->json([
'name' => $name,
'data' => $validated['data']
'key' => $settingName,
'value' => $validated['value']
], 200);
// The useEncryption option impacts the [existing] content of the database.
@ -138,23 +132,23 @@ public function update(SettingUpdateRequest $request, $name)
* Save options
* @return [type] [description]
*/
public function destroy($name)
public function destroy($settingName)
{
$setting = $this->settingService->get($name);
$setting = $this->settingService->get($settingName);
if (is_null($setting)) {
abort(404);
}
$optionsConfig = config('app.options');
if(array_key_exists($name, $optionsConfig)) {
if(array_key_exists($settingName, $optionsConfig)) {
return response()->json(
['message' => 'bad request',
'reason' => [__('errors.delete_user_setting_only')]
], 400);
}
$this->settingService->delete($name);
$this->settingService->delete($settingName);
return response()->json(null, 204);
}

View File

@ -24,8 +24,8 @@ public function authorize()
public function rules()
{
return [
'name' => 'required|alpha|max:128|unique:options,key',
'data' => 'required',
'key' => 'required|alpha|max:128|unique:options,key',
'value' => 'required',
];
}
}

View File

@ -24,7 +24,7 @@ public function authorize()
public function rules()
{
return [
'data' => 'required',
'value' => 'required',
];
}
}

View File

@ -23,7 +23,7 @@ class RouteServiceProvider extends ServiceProvider
*/
public function boot()
{
//
Route::pattern('settingName', '[a-zA-Z]+');
parent::boot();
}

View File

@ -110,7 +110,7 @@ public function delete($ids) : int
* @param Group $group The target group
* @return Group The updated group
*/
public function assign(mixed $ids, Group $group = null) : Group
public function assign($ids, Group $group = null) : Group
{
if (!$group) {
$group = $this->destinationGroup();

View File

@ -38,11 +38,11 @@
// Route::post('options', 'Settings\OptionController@store');
// });
Route::get('settings/{name}', 'SettingController@show');
Route::get('settings/{settingName}', 'SettingController@show');
Route::get('settings', 'SettingController@index');
Route::post('settings', 'SettingController@store');
Route::put('settings/{name}', 'SettingController@update');
Route::delete('settings/{name}', 'SettingController@destroy');
Route::put('settings/{settingName}', 'SettingController@update');
Route::delete('settings/{settingName}', 'SettingController@destroy');
Route::delete('twofaccounts', 'TwoFAccountController@batchDestroy');
Route::patch('twofaccounts/withdraw', 'TwoFAccountController@withdraw');