63 lines
No EOL
2 KiB
PHP
63 lines
No EOL
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use Domains\Settings\Models\Setting;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class SettingsController extends BaseController
|
|
{
|
|
/**
|
|
* Display current settings
|
|
*/
|
|
public function index(): JsonResponse
|
|
{
|
|
try {
|
|
$settings = [
|
|
'article_processing_enabled' => Setting::isArticleProcessingEnabled(),
|
|
'publishing_approvals_enabled' => Setting::isPublishingApprovalsEnabled(),
|
|
];
|
|
|
|
return $this->sendResponse($settings, 'Settings retrieved successfully.');
|
|
} catch (\Exception $e) {
|
|
return $this->sendError('Failed to retrieve settings: ' . $e->getMessage(), [], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update settings
|
|
*/
|
|
public function update(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$validated = $request->validate([
|
|
'article_processing_enabled' => 'boolean',
|
|
'enable_publishing_approvals' => 'boolean',
|
|
]);
|
|
|
|
if (isset($validated['article_processing_enabled'])) {
|
|
Setting::setArticleProcessingEnabled($validated['article_processing_enabled']);
|
|
}
|
|
|
|
if (isset($validated['enable_publishing_approvals'])) {
|
|
Setting::setPublishingApprovalsEnabled($validated['enable_publishing_approvals']);
|
|
}
|
|
|
|
$updatedSettings = [
|
|
'article_processing_enabled' => Setting::isArticleProcessingEnabled(),
|
|
'publishing_approvals_enabled' => Setting::isPublishingApprovalsEnabled(),
|
|
];
|
|
|
|
return $this->sendResponse(
|
|
$updatedSettings,
|
|
'Settings updated successfully.'
|
|
);
|
|
} catch (ValidationException $e) {
|
|
return $this->sendValidationError($e->errors());
|
|
} catch (\Exception $e) {
|
|
return $this->sendError('Failed to update settings: ' . $e->getMessage(), [], 500);
|
|
}
|
|
}
|
|
} |