2020-07-13 08:27:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-04-12 19:26:57 +02:00
|
|
|
|
2018-07-03 21:53:46 +02:00
|
|
|
namespace OCA\Notes\Controller;
|
2019-05-25 08:15:05 +02:00
|
|
|
|
2020-04-12 19:26:57 +02:00
|
|
|
use OCA\Notes\Service\SettingsService;
|
2018-07-03 21:53:46 +02:00
|
|
|
|
2020-04-12 19:26:57 +02:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2018-07-03 21:53:46 +02:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
|
2019-05-25 08:15:05 +02:00
|
|
|
class SettingsController extends Controller {
|
2018-07-03 21:53:46 +02:00
|
|
|
private $service;
|
2018-09-16 17:21:43 +02:00
|
|
|
private $userSession;
|
2018-07-03 21:53:46 +02:00
|
|
|
|
|
|
|
public function __construct(
|
2020-04-12 19:26:57 +02:00
|
|
|
string $appName,
|
2018-07-03 21:53:46 +02:00
|
|
|
IRequest $request,
|
2018-09-16 17:21:43 +02:00
|
|
|
SettingsService $service,
|
|
|
|
IUserSession $userSession
|
2018-07-03 21:53:46 +02:00
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->service = $service;
|
2018-09-16 17:21:43 +02:00
|
|
|
$this->userSession = $userSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getUID() {
|
|
|
|
return $this->userSession->getUser()->getUID();
|
2018-07-03 21:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @throws \OCP\PreConditionNotMetException
|
|
|
|
*/
|
|
|
|
public function set() {
|
2018-09-16 17:21:43 +02:00
|
|
|
$this->service->set(
|
|
|
|
$this->getUID(),
|
|
|
|
$this->request->getParams()
|
|
|
|
);
|
2018-07-03 21:53:46 +02:00
|
|
|
return $this->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function get() {
|
2018-09-16 17:21:43 +02:00
|
|
|
return new JSONResponse($this->service->getAll($this->getUID()));
|
2018-07-03 21:53:46 +02:00
|
|
|
}
|
|
|
|
}
|