2020-08-20 18:36:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
final class SharingPostController extends AbstractController
|
|
|
|
{
|
|
|
|
protected string $route = '/api/v1/sharing';
|
2020-08-24 22:19:46 +02:00
|
|
|
|
|
|
|
/** @var string[] */
|
2020-08-20 18:36:30 +02:00
|
|
|
protected array $mandatoryAttributes = [
|
|
|
|
'userId',
|
|
|
|
'userSharedId',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function handle(): void
|
|
|
|
{
|
|
|
|
parent::handle();
|
|
|
|
|
|
|
|
if ($this->response->getStatus() !== ServerStatus::OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-24 22:19:46 +02:00
|
|
|
if (!$this->isUserLoggedIn() || !$this->hasUserPermission($this->jsonBody->userId)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-20 18:36:30 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$sharing = new Sharing();
|
2020-08-24 22:19:46 +02:00
|
|
|
$sharing->setUserId($this->jsonBody->userId);
|
|
|
|
$sharing->setUserShared($this->jsonBody->userSharedId);
|
2020-08-20 18:36:30 +02:00
|
|
|
$sharing->Save();
|
|
|
|
|
|
|
|
$this->response = new ApiJsonResponse();
|
|
|
|
$this->response->setParameter('sharingId', $sharing->getSharingId());
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
|
|
|
|
$this->response->setMessage($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|