generated from fintechbd/package-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into LP-103-Login-Test-Case
# Conflicts: # tests/TestCase.php
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace Fintech\Auth\Http\Controllers; | ||
|
||
use Fintech\Auth\Http\Requests\StoreSettingRequest; | ||
use Fintech\Auth\Http\Resources\SettingResource; | ||
use Fintech\Core\Facades\Core; | ||
use Fintech\Core\Supports\Utility; | ||
use Fintech\Core\Traits\ApiResponseTrait; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Routing\Controller; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
/** | ||
* Class SettingController | ||
* @package Fintech\Auth\Http\Controllers | ||
* | ||
* @lrd:start | ||
* This class handle system setting related to individual user | ||
* @lrd:end | ||
* | ||
*/ | ||
class SettingController extends Controller | ||
{ | ||
use ApiResponseTrait; | ||
|
||
/** | ||
* @lrd:start | ||
* Return a listing of the configurations in key and value format. | ||
* *`configuration`* value depends on number of package configured to system | ||
* @lrd:end | ||
* | ||
* @return SettingResource|JsonResponse | ||
*/ | ||
public function index(): SettingResource|JsonResponse | ||
{ | ||
try { | ||
|
||
$configurations = (Auth::check()) | ||
? Core::setting()->list(['user_id' => auth()->id()]) | ||
: collect([]); | ||
|
||
$settings = []; | ||
|
||
$configurations->each(function ($setting) use (&$settings) { | ||
$settings[$setting->package][$setting->key] = Utility::typeCast($setting->value, $setting->type); | ||
}); | ||
|
||
return new SettingResource($settings); | ||
|
||
} catch (\Exception $exception) { | ||
|
||
return $this->failed($exception->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* @LRDparam package string|required|in:dashboard,other | ||
* @lrd:start | ||
* Update a specified user settings using configuration | ||
* @lrd:end | ||
* | ||
* @param StoreSettingRequest $request | ||
* @return JsonResponse | ||
*/ | ||
public function store(StoreSettingRequest $request): JsonResponse | ||
{ | ||
try { | ||
|
||
$configuration = $request->input('package', 'dashboard'); | ||
|
||
$inputs = $request->except('package'); | ||
|
||
foreach ($inputs as $key => $value) { | ||
Core::setting()->setValue($configuration, $key, $value, null, auth()->id()); | ||
} | ||
|
||
return $this->updated(__('core::messages.setting.saved', ['package' => config("fintech.core.packages.{$configuration}", 'System')])); | ||
|
||
} catch (\Exception $exception) { | ||
|
||
return $this->failed($exception->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* @lrd:start | ||
* Soft delete a specified setting resource using id. | ||
* @lrd:end | ||
* | ||
* @param string $configuration | ||
* @return JsonResponse | ||
*/ | ||
public function destroy(string $configuration) | ||
{ | ||
try { | ||
|
||
$settings = Core::setting()->list(['package' => $configuration]); | ||
|
||
foreach ($settings as $setting) { | ||
Core::setting()->destroy($setting->id); | ||
} | ||
|
||
return $this->deleted(__('core::messages.setting.deleted', ['model' => 'Setting'])); | ||
|
||
} catch (\Exception $exception) { | ||
|
||
return $this->failed($exception->getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Fintech\Auth\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class StoreSettingRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'package' => ['required', 'string'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Fintech\Auth\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class SettingResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource collection into an array. | ||
* | ||
* @param Request $request | ||
* @return array | ||
*/ | ||
public function toArray(Request $request) | ||
{ | ||
return $this->resource; | ||
} | ||
|
||
/** | ||
* Get additional data that should be returned with the resource array. | ||
* | ||
* @param Request $request | ||
* @return array<string, mixed> | ||
*/ | ||
public function with(Request $request): array | ||
{ | ||
return [ | ||
'options' => [ | ||
'package' => ['dashboard' => 'Dashboard', 'other' => 'Other'] | ||
], | ||
'query' => $request->all(), | ||
]; | ||
} | ||
} |