diff --git a/composer.json b/composer.json index d19a770..9b1755f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/core-api", - "version": "1.1.0-alpha", + "version": "1.1.1-alpha", "description": "Core Framework and Resources for Fleetbase API", "keywords": [ "fleetbase", diff --git a/src/Http/Controllers/Internal/v1/SettingController.php b/src/Http/Controllers/Internal/v1/SettingController.php index 90c89ab..4e358c7 100644 --- a/src/Http/Controllers/Internal/v1/SettingController.php +++ b/src/Http/Controllers/Internal/v1/SettingController.php @@ -252,4 +252,40 @@ public function saveServicesConfig(Request $request) return response()->json(['status' => 'OK']); } + + /** + * Get branding settings. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\JsonResponse + */ + public function getBrandingSettings() + { + $brandingSettings = Setting::getBranding(); + return response()->json(['brand' => $brandingSettings]); + } + + /** + * Saves branding settings. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\JsonResponse + */ + public function saveBrandingSettings(Request $request) + { + $iconUrl = $request->input('brand.icon_url'); + $logoUrl = $request->input('brand.logo_url'); + + if ($iconUrl) { + Setting::configure('branding.icon_url', $iconUrl); + } + + if ($logoUrl) { + Setting::configure('branding.logo_url', $logoUrl); + } + + $brandingSettings = Setting::getBranding(); + + return response()->json(['brand' => $brandingSettings]); + } } diff --git a/src/Models/Setting.php b/src/Models/Setting.php index dcf64f6..ac9ad43 100644 --- a/src/Models/Setting.php +++ b/src/Models/Setting.php @@ -146,4 +146,15 @@ public static function configure($key, $value = null) ] ); } + + public static function getBranding() + { + $brandingSettings = ['id' => 1, 'uuid' => 1]; + $iconUrl = static::where('key', 'branding.icon_url')->first(); + $logoUrl = static::where('key', 'branding.logo_url')->first(); + $brandingSettings['icon_url'] = $iconUrl ? $iconUrl->value : '/images/icon.png'; + $brandingSettings['logo_url'] = $logoUrl ? $logoUrl->value : '/images/fleetbase-logo-svg.svg'; + + return $brandingSettings; + } } diff --git a/src/routes.php b/src/routes.php index 73e0944..cfe5892 100644 --- a/src/routes.php +++ b/src/routes.php @@ -59,6 +59,12 @@ function ($router) { $router->get('font-awesome-icons', 'LookupController@fontAwesomeIcons'); } ); + $router->group( + ['prefix' => 'settings'], + function ($router) { + $router->get('branding', 'SettingController@getBrandingSettings'); + } + ); $router->group( ['middleware' => ['fleetbase.protected']], function ($router) { @@ -83,6 +89,8 @@ function ($router, $controller) { $router->post('queue-config', $controller('saveQueueConfig')); $router->get('services-config', $controller('getServicesConfig')); $router->post('services-config', $controller('saveServicesConfig')); + $router->post('branding', $controller('saveBrandingSettings')); + $router->put('branding', $controller('saveBrandingSettings')); } ); $router->fleetbaseRoutes('api-events');