adds total count for subscribers in topics model
This commit is contained in:
parent
456654c165
commit
34b3ed68ee
5 changed files with 48 additions and 6 deletions
|
@ -1629,7 +1629,7 @@ $commonCollections = [
|
||||||
'size' => 0,
|
'size' => 0,
|
||||||
'signed' => true,
|
'signed' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'default' => null,
|
'default' => 0,
|
||||||
'array' => false,
|
'array' => false,
|
||||||
'filters' => [],
|
'filters' => [],
|
||||||
],
|
],
|
||||||
|
@ -1719,6 +1719,17 @@ $commonCollections = [
|
||||||
'array' => false,
|
'array' => false,
|
||||||
'filters' => [],
|
'filters' => [],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'$id' => ID::custom('total'),
|
||||||
|
'type' => Database::VAR_INTEGER,
|
||||||
|
'format' => '',
|
||||||
|
'size' => 0,
|
||||||
|
'signed' => true,
|
||||||
|
'required' => false,
|
||||||
|
'default' => 0,
|
||||||
|
'array' => false,
|
||||||
|
'filters' => [],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'$id' => ID::custom('targets'),
|
'$id' => ID::custom('targets'),
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
|
|
@ -1491,7 +1491,7 @@ App::post('/v1/messaging/topics/:topicId/subscribers')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$subscriber = $dbForProject->createDocument('subscribers', $subscriber);
|
$subscriber = $dbForProject->createDocument('subscribers', $subscriber);
|
||||||
$dbForProject->deleteCachedDocument('topics', $topicId);
|
Authorization::skip(fn () => $dbForProject->increaseDocumentAttribute('topics', $topicId, 'total', 1));
|
||||||
} catch (DuplicateException) {
|
} catch (DuplicateException) {
|
||||||
throw new Exception(Exception::SUBSCRIBER_ALREADY_EXISTS);
|
throw new Exception(Exception::SUBSCRIBER_ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
|
@ -1610,8 +1610,9 @@ App::delete('/v1/messaging/topics/:topicId/subscriber/:subscriberId')
|
||||||
if ($subscriber->isEmpty() || $subscriber->getAttribute('topicId') !== $topicId) {
|
if ($subscriber->isEmpty() || $subscriber->getAttribute('topicId') !== $topicId) {
|
||||||
throw new Exception(Exception::SUBSCRIBER_NOT_FOUND);
|
throw new Exception(Exception::SUBSCRIBER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscriber = $dbForProject->deleteDocument('subscribers', $subscriberId);
|
$subscriber = $dbForProject->deleteDocument('subscribers', $subscriberId);
|
||||||
$dbForProject->deleteCachedDocument('topics', $topicId);
|
Authorization::skip(fn () => $dbForProject->decreaseDocumentAttribute('topics', $topicId, 'total', 1));
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->setStatusCode(Response::STATUS_CODE_NOCONTENT)
|
->setStatusCode(Response::STATUS_CODE_NOCONTENT)
|
||||||
|
|
2
composer.lock
generated
2
composer.lock
generated
|
@ -5822,5 +5822,5 @@
|
||||||
"platform-overrides": {
|
"platform-overrides": {
|
||||||
"php": "8.0"
|
"php": "8.0"
|
||||||
},
|
},
|
||||||
"plugin-api-version": "2.3.0"
|
"plugin-api-version": "2.6.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,12 @@ class Topic extends Model
|
||||||
'default' => '',
|
'default' => '',
|
||||||
'example' => 'events',
|
'example' => 'events',
|
||||||
])
|
])
|
||||||
|
->addRule('total', [
|
||||||
|
'type' => self::TYPE_INTEGER,
|
||||||
|
'description' => 'Total count of subscribers subscribed to topic.',
|
||||||
|
'default' => 0,
|
||||||
|
'example' => 100,
|
||||||
|
])
|
||||||
->addRule('description', [
|
->addRule('description', [
|
||||||
'type' => self::TYPE_STRING,
|
'type' => self::TYPE_STRING,
|
||||||
'description' => 'Description of the topic.',
|
'description' => 'Description of the topic.',
|
||||||
|
|
|
@ -288,6 +288,7 @@ trait MessagingBase
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertEquals('android-app', $response['body']['name']);
|
$this->assertEquals('android-app', $response['body']['name']);
|
||||||
$this->assertEquals('updated-description', $response['body']['description']);
|
$this->assertEquals('updated-description', $response['body']['description']);
|
||||||
|
$this->assertEquals(0, $response['body']['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -311,12 +312,23 @@ trait MessagingBase
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'subscriberId' => 'unique()',
|
'subscriberId' => ID::unique(),
|
||||||
'targetId' => $target['body']['$id'],
|
'targetId' => $target['body']['$id'],
|
||||||
]);
|
]);
|
||||||
$this->assertEquals(201, $response['headers']['status-code']);
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
|
||||||
|
$topic = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $topic['$id'], [
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||||
|
]);
|
||||||
|
$this->assertEquals(200, $topic['headers']['status-code']);
|
||||||
|
$this->assertEquals('android-app', $topic['body']['name']);
|
||||||
|
$this->assertEquals('updated-description', $topic['body']['description']);
|
||||||
|
$this->assertEquals(1, $topic['body']['total']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'topicId' => $topic['$id'],
|
'topicId' => $topic['body']['$id'],
|
||||||
'targetId' => $target['body']['$id'],
|
'targetId' => $target['body']['$id'],
|
||||||
'subscriberId' => $response['body']['$id']
|
'subscriberId' => $response['body']['$id']
|
||||||
];
|
];
|
||||||
|
@ -361,7 +373,19 @@ trait MessagingBase
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()));
|
], $this->getHeaders()));
|
||||||
|
|
||||||
$this->assertEquals(204, $response['headers']['status-code']);
|
$this->assertEquals(204, $response['headers']['status-code']);
|
||||||
|
|
||||||
|
$topic = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $data['topicId'], [
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $topic['headers']['status-code']);
|
||||||
|
$this->assertEquals('android-app', $topic['body']['name']);
|
||||||
|
$this->assertEquals('updated-description', $topic['body']['description']);
|
||||||
|
$this->assertEquals(0, $topic['body']['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue