79 lines
1.6 KiB
PHP
79 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace OCA\MoneyPlanner\Controller;
|
|
|
|
use Exception;
|
|
|
|
use OCP\IRequest;
|
|
use OCP\AppFramework\Http;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCA\MoneyPlanner\Service\AccountService;
|
|
|
|
class AccountController extends Controller {
|
|
|
|
private $service;
|
|
private $userId;
|
|
|
|
use Errors;
|
|
|
|
public function __construct(string $AppName, IRequest $request, AccountService $service, $UserId){
|
|
parent::__construct($AppName, $request);
|
|
$this->service = $service;
|
|
$this->userId = $UserId;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*/
|
|
public function index() {
|
|
return new DataResponse($this->service->findAll($this->userId));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param int $id
|
|
*/
|
|
public function show(int $id) {
|
|
return $this->handleNotFound(function () use ($id) {
|
|
return $this->service->find($id, $this->userId);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param string $name
|
|
*/
|
|
public function create(string $name) {
|
|
return $this->service->create($name, $this->userId);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param int $id
|
|
* @param string $name
|
|
*/
|
|
public function update(int $id, string $name) {
|
|
return $this->handleNotFound(function () use ($id, $name) {
|
|
return $this->service->update($id, $name, $this->userId);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param int $id
|
|
*/
|
|
public function destroy(int $id) {
|
|
return $this->handleNotFound(function () use ($id) {
|
|
return $this->service->delete($id, $this->userId);
|
|
});
|
|
}
|
|
}
|
|
|
|
?>
|