nextcloud-notes/lib/Controller/SettingsController.php

52 lines
972 B
PHP
Raw Normal View History

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;
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,
SettingsService $service,
IUserSession $userSession
2018-07-03 21:53:46 +02:00
) {
parent::__construct($appName, $request);
$this->service = $service;
$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() {
$this->service->set(
$this->getUID(),
$this->request->getParams()
);
2018-07-03 21:53:46 +02:00
return $this->get();
}
/**
* @NoAdminRequired
*/
public function get() {
return new JSONResponse($this->service->getAll($this->getUID()));
2018-07-03 21:53:46 +02:00
}
}