mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Move schedule endpoints to projects group (/v1/projects/:projectId/schedules)
This commit is contained in:
committed by
premtsd-code
parent
3fde05e024
commit
63d2efdaac
@@ -32,18 +32,18 @@ class Create extends Action
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_POST)
|
||||
->setHttpPath('/v1/schedules')
|
||||
->setHttpPath('/v1/projects/:projectId/schedules')
|
||||
->desc('Create schedule')
|
||||
->groups(['api', 'schedules'])
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'schedules.write')
|
||||
->label('audits.event', 'schedule.create')
|
||||
->label('audits.resource', 'schedule/{response.$id}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'schedules',
|
||||
namespace: 'projects',
|
||||
group: 'schedules',
|
||||
name: 'create',
|
||||
name: 'createSchedule',
|
||||
description: '/docs/references/schedules/create.md',
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
auth: [AuthType::ADMIN],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_CREATED,
|
||||
@@ -51,29 +51,37 @@ class Create extends Action
|
||||
)
|
||||
],
|
||||
))
|
||||
->param('projectId', '', new UID(), 'Project unique ID.')
|
||||
->param('resourceType', '', new WhiteList([SCHEDULE_RESOURCE_TYPE_FUNCTION, SCHEDULE_RESOURCE_TYPE_EXECUTION, SCHEDULE_RESOURCE_TYPE_MESSAGE], true), 'The resource type for the schedule. Possible values: ' . implode(', ', [SCHEDULE_RESOURCE_TYPE_FUNCTION, SCHEDULE_RESOURCE_TYPE_EXECUTION, SCHEDULE_RESOURCE_TYPE_MESSAGE]) . '.')
|
||||
->param('resourceId', '', new UID(), 'The resource ID to associate with this schedule.')
|
||||
->param('schedule', '', new Cron(), 'Schedule CRON expression.')
|
||||
->param('active', false, new Boolean(), 'Whether the schedule is active.', true)
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForProject')
|
||||
->inject('dbForPlatform')
|
||||
->inject('getProjectDB')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(
|
||||
string $projectId,
|
||||
string $resourceType,
|
||||
string $resourceId,
|
||||
string $schedule,
|
||||
bool $active,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Database $dbForProject,
|
||||
Database $dbForPlatform,
|
||||
callable $getProjectDB,
|
||||
Authorization $authorization,
|
||||
): void {
|
||||
$project = $dbForPlatform->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
$dbForProject = $getProjectDB($project);
|
||||
|
||||
$collection = match ($resourceType) {
|
||||
SCHEDULE_RESOURCE_TYPE_FUNCTION => 'functions',
|
||||
SCHEDULE_RESOURCE_TYPE_EXECUTION => 'executions',
|
||||
|
||||
@@ -8,7 +8,6 @@ use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
@@ -27,16 +26,16 @@ class Get extends Action
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/schedules/:scheduleId')
|
||||
->setHttpPath('/v1/projects/:projectId/schedules/:scheduleId')
|
||||
->desc('Get schedule')
|
||||
->groups(['api', 'schedules'])
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'schedules.read')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'schedules',
|
||||
namespace: 'projects',
|
||||
group: 'schedules',
|
||||
name: 'get',
|
||||
name: 'getSchedule',
|
||||
description: '/docs/references/schedules/get.md',
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
auth: [AuthType::ADMIN],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_OK,
|
||||
@@ -44,21 +43,27 @@ class Get extends Action
|
||||
)
|
||||
]
|
||||
))
|
||||
->param('projectId', '', new UID(), 'Project unique ID.')
|
||||
->param('scheduleId', '', new UID(), 'Schedule ID.')
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForPlatform')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(
|
||||
string $projectId,
|
||||
string $scheduleId,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Database $dbForPlatform,
|
||||
Authorization $authorization,
|
||||
): void {
|
||||
$project = $dbForPlatform->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
$schedule = $authorization->skip(
|
||||
fn () => $dbForPlatform->getDocument('schedules', $scheduleId)
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@ use Utopia\Database\Exception\Query as QueryException;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\Query\Cursor;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Boolean;
|
||||
@@ -32,16 +33,16 @@ class XList extends Action
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/schedules')
|
||||
->setHttpPath('/v1/projects/:projectId/schedules')
|
||||
->desc('List schedules')
|
||||
->groups(['api', 'schedules'])
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'schedules.read')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'schedules',
|
||||
namespace: 'projects',
|
||||
group: 'schedules',
|
||||
name: 'list',
|
||||
name: 'listSchedules',
|
||||
description: '/docs/references/schedules/list.md',
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
auth: [AuthType::ADMIN],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_OK,
|
||||
@@ -49,30 +50,35 @@ class XList extends Action
|
||||
)
|
||||
]
|
||||
))
|
||||
->param('projectId', '', new UID(), 'Project unique ID.')
|
||||
->param('queries', [], new Schedules(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Schedules::ALLOWED_ATTRIBUTES), true)
|
||||
->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true)
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForPlatform')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(
|
||||
string $projectId,
|
||||
array $queries,
|
||||
bool $includeTotal,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Database $dbForPlatform,
|
||||
Authorization $authorization,
|
||||
): void {
|
||||
$project = $dbForPlatform->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$queries = Query::parseQueries($queries);
|
||||
} catch (QueryException $e) {
|
||||
throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage());
|
||||
}
|
||||
|
||||
// Always scope to the current project
|
||||
$queries[] = Query::equal('projectId', [$project->getId()]);
|
||||
|
||||
$cursor = Query::getCursorQueries($queries, false);
|
||||
|
||||
Reference in New Issue
Block a user