Endpoints for sharing implemented
This commit is contained in:
parent
0334c7022d
commit
459be4a999
38
backend/classes/controller/SharingDeleteController.php
Normal file
38
backend/classes/controller/SharingDeleteController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?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);
|
||||
$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());
|
||||
}
|
||||
}
|
||||
}
|
38
backend/classes/controller/SharingGetController.php
Normal file
38
backend/classes/controller/SharingGetController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
final class SharingGetController 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);
|
||||
|
||||
$this->response = new ApiJsonResponse();
|
||||
$this->response->setParameter('success', true);
|
||||
$this->response->setResult($sharing);
|
||||
} catch (Throwable $e) {
|
||||
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
|
||||
$this->response->setParameter('success', false);
|
||||
$this->response->setMessage($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
36
backend/classes/controller/SharingPostController.php
Normal file
36
backend/classes/controller/SharingPostController.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
final class Sharing extends MySqlTable
|
||||
final class Sharing extends MySqlTable implements JsonSerializable
|
||||
{
|
||||
public const FIELD_USER = 'User';
|
||||
public const FIELD_USER_SHARED = 'UserShared';
|
||||
@ -40,4 +40,13 @@ final class Sharing extends MySqlTable
|
||||
{
|
||||
$this->setField(self::FIELD_USER_SHARED, $userShared);
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'sharingId' => $this->getSharingId(),
|
||||
'userId' => $this->getUserId(),
|
||||
'userSharedId' => $this->getUserShared(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user