From 9aab35ff05e1dd919b643eb88fef67efa562878f Mon Sep 17 00:00:00 2001 From: Arya Dwi Putra Date: Mon, 1 Dec 2025 07:38:04 +0700 Subject: [PATCH] Add configurable system settings service --- .env.example | 8 +++++ app/Services/System/SystemSettingService.php | 35 ++++++++++++++++++++ config/system.php | 22 ++++++++++++ tests/Unit/SystemSettingServiceTest.php | 34 +++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 app/Services/System/SystemSettingService.php create mode 100644 config/system.php create mode 100644 tests/Unit/SystemSettingServiceTest.php diff --git a/.env.example b/.env.example index 68acfcf..39cefaa 100644 --- a/.env.example +++ b/.env.example @@ -59,6 +59,14 @@ MAIL_PASSWORD=null MAIL_FROM_ADDRESS="hello@example.com" MAIL_FROM_NAME="${APP_NAME}" +ASSET_CODE_PREFIX=AST +ASSET_QR_ENABLED=true +ASSET_WARRANTY_REMINDER_DAYS=30 +SYSTEM_DATE_FORMAT=d/m/Y +SYSTEM_TIME_FORMAT=H:i +SYSTEM_DEFAULT_CURRENCY=IDR +SYSTEM_AUDIT_LOG=true + AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 diff --git a/app/Services/System/SystemSettingService.php b/app/Services/System/SystemSettingService.php new file mode 100644 index 0000000..121717d --- /dev/null +++ b/app/Services/System/SystemSettingService.php @@ -0,0 +1,35 @@ +all(), $key, $default); + } + + /** + * Set konfigurasi secara runtime tanpa menyentuh database. + */ + public function set(string $key, mixed $value): void + { + $settings = $this->all(); + Arr::set($settings, $key, $value); + + config(['system' => $settings]); + } +} diff --git a/config/system.php b/config/system.php new file mode 100644 index 0000000..6c8c544 --- /dev/null +++ b/config/system.php @@ -0,0 +1,22 @@ + [ + 'name' => env('APP_NAME', 'Asset Management System'), + 'timezone' => env('APP_TIMEZONE', 'Asia/Jakarta'), + 'locale' => env('APP_LOCALE', 'id'), + ], + 'asset' => [ + 'code_prefix' => env('ASSET_CODE_PREFIX', 'AST'), + 'qr_enabled' => env('ASSET_QR_ENABLED', true), + 'warranty_reminder_days' => env('ASSET_WARRANTY_REMINDER_DAYS', 30), + ], + 'ui' => [ + 'date_format' => env('SYSTEM_DATE_FORMAT', 'd/m/Y'), + 'time_format' => env('SYSTEM_TIME_FORMAT', 'H:i'), + 'currency' => env('SYSTEM_DEFAULT_CURRENCY', 'IDR'), + ], + 'security' => [ + 'audit_log' => env('SYSTEM_AUDIT_LOG', true), + ], +]; diff --git a/tests/Unit/SystemSettingServiceTest.php b/tests/Unit/SystemSettingServiceTest.php new file mode 100644 index 0000000..2baf04f --- /dev/null +++ b/tests/Unit/SystemSettingServiceTest.php @@ -0,0 +1,34 @@ + 'ASTX', + 'system.application.name' => 'Custom AMS', + ]); + + $service = app(SystemSettingService::class); + + $this->assertSame('ASTX', $service->get('asset.code_prefix')); + $this->assertSame('Custom AMS', $service->get('application.name')); + $this->assertTrue($service->get('asset.qr_enabled')); + } + + public function test_it_can_override_runtime_settings(): void + { + $service = app(SystemSettingService::class); + + $service->set('ui.date_format', 'Y-m-d'); + + $this->assertSame('Y-m-d', $service->get('ui.date_format')); + $this->assertSame('Y-m-d', config('system.ui.date_format')); + } +}