Added membership and membership list models
This commit is contained in:
parent
75026ffa8c
commit
6e472d4ef3
|
@ -362,21 +362,12 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
->setParam('resource', 'teams/'.$teamId)
|
||||
;
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED) // TODO change response of this endpoint
|
||||
->json(\array_merge($membership->getArrayCopy([
|
||||
'$id',
|
||||
'userId',
|
||||
'teamId',
|
||||
'roles',
|
||||
'invited',
|
||||
'joined',
|
||||
'confirm',
|
||||
]), [
|
||||
'email' => $email,
|
||||
'name' => $name,
|
||||
]))
|
||||
;
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED); // TODO change response of this endpoint
|
||||
|
||||
$response->dynamic(new Document(\array_merge($membership->getArrayCopy(), [
|
||||
'email' => $email,
|
||||
'name' => $name,
|
||||
])), Response::MODEL_MEMBERSHIP);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -422,19 +413,10 @@ $utopia->get('/v1/teams/:teamId/memberships')
|
|||
|
||||
$temp = $projectDB->getDocument($membership->getAttribute('userId', null))->getArrayCopy(['email', 'name']);
|
||||
|
||||
$users[] = \array_merge($temp, $membership->getArrayCopy([
|
||||
'$id',
|
||||
'userId',
|
||||
'teamId',
|
||||
'roles',
|
||||
'invited',
|
||||
'joined',
|
||||
'confirm',
|
||||
]));
|
||||
$users[] = new Document(\array_merge($temp, $membership->getArrayCopy()));
|
||||
}
|
||||
|
||||
$response->json(['sum' => $projectDB->getSum(), 'memberships' => $users]);
|
||||
|
||||
$response->dynamic(new Document(['sum' => $projectDB->getSum(), 'memberships' => $users]), Response::MODEL_MEMBERSHIP_LIST);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -554,19 +536,12 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
|||
$response
|
||||
->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
|
||||
->json(\array_merge($membership->getArrayCopy([
|
||||
'$id',
|
||||
'userId',
|
||||
'teamId',
|
||||
'roles',
|
||||
'invited',
|
||||
'joined',
|
||||
'confirm',
|
||||
]), [
|
||||
'email' => $user->getAttribute('email'),
|
||||
'name' => $user->getAttribute('name'),
|
||||
]))
|
||||
;
|
||||
|
||||
$response->dynamic(new Document(\array_merge($membership->getArrayCopy(), [
|
||||
'email' => $user->getAttribute('email'),
|
||||
'name' => $user->getAttribute('name'),
|
||||
])), Response::MODEL_MEMBERSHIP);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -619,4 +594,4 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
|||
|
||||
$response->noContent();
|
||||
}
|
||||
);
|
||||
);
|
|
@ -12,12 +12,14 @@ use Appwrite\Utopia\Response\Model\Session;
|
|||
use Appwrite\Utopia\Response\Model\Team;
|
||||
use Appwrite\Utopia\Response\Model\TeamList;
|
||||
use Appwrite\Utopia\Response\Model\Locale;
|
||||
use Appwrite\Utopia\Response\Model\Membership;
|
||||
use Appwrite\Utopia\Response\Model\MembershipList;
|
||||
use Utopia\Response as UtopiaResponse;
|
||||
|
||||
class Response extends UtopiaResponse
|
||||
{
|
||||
// General
|
||||
const MODEL_LOG = 'log';
|
||||
const MODEL_LOG = 'log'; // - Missing
|
||||
const MODEL_ERROR = 'error';
|
||||
const MODEL_ERROR_DEV = 'errorDev';
|
||||
const MODEL_BASE_LIST = 'baseList';
|
||||
|
@ -25,28 +27,28 @@ class Response extends UtopiaResponse
|
|||
// Users
|
||||
const MODEL_USER = 'user';
|
||||
const MODEL_SESSION = 'session';
|
||||
const MODEL_TOKEN = 'token';
|
||||
const MODEL_TOKEN = 'token'; // - Missing
|
||||
|
||||
// Database
|
||||
const MODEL_COLLECTION = 'collection';
|
||||
const MODEL_COLLECTION = 'collection'; // - Missing
|
||||
|
||||
// Locale
|
||||
const MODEL_LOCALE = 'locale';
|
||||
const MODEL_COUNTRY = 'country';
|
||||
const MODEL_CONTINENT = 'continent';
|
||||
const MODEL_CURRENCY = 'currency';
|
||||
const MODEL_LANGUAGE = 'langauge';
|
||||
const MODEL_PHONE = 'phone';
|
||||
const MODEL_COUNTRY = 'country'; // - Missing
|
||||
const MODEL_CONTINENT = 'continent'; // - Missing
|
||||
const MODEL_CURRENCY = 'currency'; // - Missing
|
||||
const MODEL_LANGUAGE = 'langauge'; // - Missing
|
||||
const MODEL_PHONE = 'phone'; // - Missing
|
||||
|
||||
// Storage
|
||||
const MODEL_FILE = 'file';
|
||||
const MODEL_BUCKET = 'bucket';
|
||||
const MODEL_FILE = 'file'; // - Missing
|
||||
const MODEL_BUCKET = 'bucket'; // - Missing
|
||||
|
||||
// Teams
|
||||
const MODEL_TEAM = 'team';
|
||||
const MODEL_TEAM_LIST = 'teamList';
|
||||
const MODEL_MEMBERSHIP = 'membership';
|
||||
const MODEL_MEMBERSHIP_LIST = 'membershipList';
|
||||
const MODEL_MEMBERSHIP = 'membership'; // - Missing
|
||||
const MODEL_MEMBERSHIP_LIST = 'membershipList'; // - Missing
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -58,6 +60,8 @@ class Response extends UtopiaResponse
|
|||
->setModel(new Locale())
|
||||
->setModel(new Team())
|
||||
->setModel(new TeamList())
|
||||
->setModel(new Membership())
|
||||
->setModel(new MembershipList())
|
||||
;
|
||||
}
|
||||
|
||||
|
|
84
src/Appwrite/Utopia/Response/Model/Membership.php
Normal file
84
src/Appwrite/Utopia/Response/Model/Membership.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Membership extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => 'string',
|
||||
'description' => 'Membership ID.',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => 'string',
|
||||
'description' => 'User ID.',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => 'string',
|
||||
'description' => 'Team ID.',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => 'string',
|
||||
'description' => 'User name.',
|
||||
'default' => '',
|
||||
'example' => 'VIP',
|
||||
])
|
||||
->addRule('email', [
|
||||
'type' => 'string',
|
||||
'description' => 'User email address.',
|
||||
'default' => '',
|
||||
'example' => 'john@appwrite.io',
|
||||
])
|
||||
->addRule('invited', [
|
||||
'type' => 'integer',
|
||||
'description' => 'Date, the user has been invited to join the team in Unix timestamp.',
|
||||
'example' => 1592981250,
|
||||
])
|
||||
->addRule('joined', [
|
||||
'type' => 'integer',
|
||||
'description' => 'Date, the user has accepted the invitation to join the team in Unix timestamp.',
|
||||
'example' => 1592981250,
|
||||
])
|
||||
->addRule('confirm', [
|
||||
'type' => 'boolean',
|
||||
'description' => 'User confirmation status, true if the user has joined the team or false otherwise.',
|
||||
'example' => false,
|
||||
])
|
||||
->addRule('roles', [
|
||||
'type' => 'string',
|
||||
'description' => 'User list of roles',
|
||||
'default' => [],
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Membership';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_MEMBERSHIP;
|
||||
}
|
||||
}
|
41
src/Appwrite/Utopia/Response/Model/MembershipList.php
Normal file
41
src/Appwrite/Utopia/Response/Model/MembershipList.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class MembershipList extends BaseList
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('memberships', [
|
||||
'type' => Response::MODEL_MEMBERSHIP,
|
||||
'description' => 'List of memberships.',
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'Membership List';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType():string
|
||||
{
|
||||
return Response::MODEL_MEMBERSHIP_LIST;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue