112 lines
2.2 KiB
PHP
112 lines
2.2 KiB
PHP
<?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);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
?>
|