Initial commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\MoneyPlanner\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\ApiController;
|
||||
|
||||
use OCA\MoneyPlanner\Service\AccountService;
|
||||
|
||||
class AccountApiController extends ApiController {
|
||||
|
||||
private $service;
|
||||
private $userId;
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct($AppName, IRequest $request,
|
||||
AccountService $service, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->service = $service;
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index() {
|
||||
return new DataResponse($this->service->findAll($this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show($id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->find($id, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function create($name) {
|
||||
return $this->service->create($name, $this->userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
*/
|
||||
public function update($id, $name) {
|
||||
return $this->handleNotFound(function () use ($id, $name) {
|
||||
return $this->service->update($id, $name, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\MoneyPlanner\Controller;
|
||||
|
||||
use Closure;
|
||||
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
|
||||
use OCA\MoneyPlanner\Service\NotFoundException;
|
||||
|
||||
|
||||
trait Errors {
|
||||
|
||||
protected function handleNotFound (Closure $callback) {
|
||||
try {
|
||||
return new DataResponse($callback());
|
||||
} catch(NotFoundException $e) {
|
||||
$message = ['message' => $e->getMessage()];
|
||||
return new DataResponse($message, Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace OCA\MoneyPlanner\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
class PageController extends Controller {
|
||||
private $userId;
|
||||
|
||||
public function __construct($AppName, IRequest $request, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* CAUTION: the @Stuff turns off security checks; for this page no admin is
|
||||
* required and no CSRF check. If you don't know what CSRF is, read
|
||||
* it up in the docs or you might create a security hole. This is
|
||||
* basically the only required method to add this exemption, don't
|
||||
* add it to any other method if you don't exactly know what it does
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
return new TemplateResponse('moneyplanner', 'index'); // templates/index.php
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\MoneyPlanner\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\ApiController;
|
||||
|
||||
use OCA\MoneyPlanner\Service\TransactionService;
|
||||
|
||||
class TransactionApiController extends ApiController {
|
||||
|
||||
private $service;
|
||||
private $userId;
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct($AppName, IRequest $request,
|
||||
TransactionService $service, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->service = $service;
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index() {
|
||||
return new DataResponse($this->service->findAll($this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show($id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->find($id, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function create(
|
||||
$accountFrom,
|
||||
$accountTo,
|
||||
$group,
|
||||
$category,
|
||||
$balance,
|
||||
$date,
|
||||
$freqNum,
|
||||
$freqType
|
||||
) {
|
||||
return $this->service->create(
|
||||
$accountFrom, $accountTo, $group, $category,
|
||||
$balance, $date, $freqNum, $freqType,
|
||||
$this->userId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function update(
|
||||
$id,
|
||||
$accountFrom,
|
||||
$accountTo,
|
||||
$group,
|
||||
$category,
|
||||
$balance,
|
||||
$date,
|
||||
$freqNum,
|
||||
$freqType
|
||||
) {
|
||||
return $this->handleNotFound(function () use (
|
||||
$id, $accountFrom, $accountTo, $group, $category,
|
||||
$balance, $date, $freqNum, $freqType
|
||||
) {
|
||||
return $this->service->update(
|
||||
$id, $accountFrom, $accountTo, $group, $category,
|
||||
$balance, $date, $freqNum, $freqType,
|
||||
$this->userId
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,103 @@
|
||||
<?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\TransactionService;
|
||||
|
||||
class TransactionController extends Controller {
|
||||
|
||||
private $service;
|
||||
private $userId;
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct(string $AppName, IRequest $request, TransactionService $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
|
||||
*/
|
||||
public function create(
|
||||
$accountFrom,
|
||||
$accountTo,
|
||||
$group,
|
||||
$category,
|
||||
$balance,
|
||||
$date,
|
||||
$freqNum,
|
||||
$freqType
|
||||
) {
|
||||
return $this->service->create(
|
||||
$accountFrom, $accountTo, $group, $category,
|
||||
$balance, $date, $freqNum, $freqType,
|
||||
$this->userId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function update(
|
||||
int $id,
|
||||
$accountFrom,
|
||||
$accountTo,
|
||||
$group,
|
||||
$category,
|
||||
$balance,
|
||||
$date,
|
||||
$freqNum,
|
||||
$freqType
|
||||
) {
|
||||
return $this->handleNotFound(function () use (
|
||||
$id, $accountFrom, $accountTo, $group, $category,
|
||||
$balance, $date, $freqNum, $freqType
|
||||
) {
|
||||
return $this->service->update(
|
||||
$id, $accountFrom, $accountTo, $group, $category,
|
||||
$balance, $date, $freqNum, $freqType,
|
||||
$this->userId
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy(int $id) {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user