ringfinger/backend/classes/controller/SharingPostController.php
2020-08-20 18:36:30 +02:00

36 lines
812 B
PHP

<?php
declare(strict_types=1);
final class SharingPostController extends AbstractController
{
protected string $route = '/api/v1/sharing';
protected array $mandatoryAttributes = [
'userId',
'userSharedId',
];
public function handle(): void
{
parent::handle();
if ($this->response->getStatus() !== ServerStatus::OK) {
return;
}
$json = json_decode($this->requestBody);
try {
$sharing = new Sharing();
$sharing->setUserId($json->userId);
$sharing->setUserShared($json->userSharedId);
$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());
}
}
}