33 lines
911 B
PHP
33 lines
911 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\PrideFlags\Controller;
|
|
|
|
use OCA\PrideFlags\Settings\AppSettings;
|
|
use OCP\IRequest;
|
|
use OCP\IConfig;
|
|
use OCP\Framework\Http;
|
|
use OCP\Framework\Http\JSONResponse;
|
|
|
|
class SettingsController {
|
|
public function __construct($appName, IRequest $request, AppSettings $settings) {}
|
|
|
|
public function get(): JSONResponse {
|
|
return $this->makeJSONResponse(fn () => $this->settings->getAll());
|
|
}
|
|
|
|
public function set(string $folderVariant, string $buttonVariant): JSONResponse {
|
|
$this->settings->set($folderVariant, $buttonVariant);
|
|
return $this->makeJSONResponse(fn () => $this->settings->getAll());
|
|
}
|
|
|
|
protected function makeJSONResponse(Closure $closure): JSONResponse {
|
|
try {
|
|
return new JSONResponse($closure(), HTTP::STATUS_OK);
|
|
} catch (Exception $e) {
|
|
return new JSONResponse(['message' => $e->getMessage()], HTTP::INTERNAL_SERVER_ERROR);
|
|
}
|
|
}
|
|
}
|