ringfinger/backend/classes/controller/SharingDeleteController.php

43 lines
939 B
PHP
Raw Permalink Normal View History

2020-08-20 18:36:30 +02:00
<?php
declare(strict_types=1);
final class SharingDeleteController extends AbstractController
{
protected string $route = '/api/v1/sharing/{sharingId}';
private int $sharingId;
public function __construct(string $url)
{
parent::__construct($url);
$this->sharingId = (int)$this->getUrlParamInt('sharingId');
}
public function handle(): void
{
parent::handle();
if ($this->response->getStatus() !== ServerStatus::OK) {
return;
}
try {
$sharing = new Sharing($this->sharingId);
if (!$this->isUserLoggedIn() || !$this->hasUserPermission($sharing->getUserId())) {
return;
}
2020-08-20 18:36:30 +02:00
$sharing->Delete();
$this->response = new ApiJsonResponse();
$this->response->setParameter('success', true);
} catch (Throwable $e) {
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
$this->response->setParameter('success', false);
$this->response->setMessage($e->getMessage());
}
}
}