initial commit
This commit is contained in:
		
							
								
								
									
										32
									
								
								lib/Controller/SettingsController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								lib/Controller/SettingsController.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
<?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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user