1
0
Fork 0

added subscription rest api controller and route

This commit is contained in:
Jonathan Treffler 2024-06-12 14:21:35 +02:00
parent 5e24706796
commit b28e0619f5
2 changed files with 44 additions and 0 deletions

View file

@ -7,5 +7,6 @@ return [
'resources' => [ 'resources' => [
], ],
'routes' => [ 'routes' => [
['name' => 'subscription#destroy', 'url' => '/subscriptions/{id}', 'verb' => 'DELETE']
] ]
]; ];

View file

@ -0,0 +1,43 @@
<?php
namespace OCA\DavPush\Controller;
use OCA\DavPush\AppInfo\Application;
use OCA\DavPush\Service\SubscriptionService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\IRequest;
class SubscriptionController extends Controller {
/** @var SubscriptionService */
private $service;
/** @var string */
private $userId;
use Errors;
public function __construct(
IRequest $request,
SubscriptionService $service,
$userId
) {
parent::__construct(Application::APP_ID, $request);
$this->service = $service;
$this->userId = $userId;
}
#[NoAdminRequired]
#[NoCSRFRequired]
public function destroy(int $id): JSONResponse {
return $this->handleNotFound(function () use ($id) {
$this->service->delete($this->userId, $id);
return [
'success' => True,
];
});
}
}