mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Enhance API response handling by adding 'includeTotal' parameter to account endpoints, allowing control over total count calculation for sessions, logs, and identities. Updated tests to verify functionality.
This commit is contained in:
@@ -2814,12 +2814,13 @@ App::get('/v1/account/logs')
|
||||
contentType: ContentType::JSON,
|
||||
))
|
||||
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
|
||||
->param('includeTotal', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true)
|
||||
->inject('response')
|
||||
->inject('user')
|
||||
->inject('locale')
|
||||
->inject('geodb')
|
||||
->inject('dbForProject')
|
||||
->action(function (array $queries, Response $response, Document $user, Locale $locale, Reader $geodb, Database $dbForProject) {
|
||||
->action(function (array $queries, bool $includeTotal, Response $response, Document $user, Locale $locale, Reader $geodb, Database $dbForProject) {
|
||||
|
||||
try {
|
||||
$queries = Query::parseQueries($queries);
|
||||
@@ -2864,7 +2865,7 @@ App::get('/v1/account/logs')
|
||||
}
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'total' => $audit->countLogsByUser($user->getSequence(), $queries),
|
||||
'total' => $includeTotal ? $audit->countLogsByUser($user->getSequence(), $queries) : 0,
|
||||
'logs' => $output,
|
||||
]), Response::MODEL_LOG_LIST);
|
||||
});
|
||||
@@ -5211,10 +5212,11 @@ App::get('/v1/account/identities')
|
||||
contentType: ContentType::JSON
|
||||
))
|
||||
->param('queries', [], new Identities(), '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(', ', Identities::ALLOWED_ATTRIBUTES), true)
|
||||
->param('includeTotal', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true)
|
||||
->inject('response')
|
||||
->inject('user')
|
||||
->inject('dbForProject')
|
||||
->action(function (array $queries, Response $response, Document $user, Database $dbForProject) {
|
||||
->action(function (array $queries, bool $includeTotal, Response $response, Document $user, Database $dbForProject) {
|
||||
|
||||
try {
|
||||
$queries = Query::parseQueries($queries);
|
||||
@@ -5259,7 +5261,7 @@ App::get('/v1/account/identities')
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'identities' => $results,
|
||||
'total' => $total,
|
||||
'total' => $includeTotal ? $total : 0,
|
||||
]), Response::MODEL_IDENTITY_LIST);
|
||||
});
|
||||
|
||||
|
||||
@@ -389,6 +389,26 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertIsNumeric($responseLimitOffset['body']['total']);
|
||||
|
||||
$this->assertEquals($response['body']['logs'][1], $responseLimitOffset['body']['logs'][0]);
|
||||
|
||||
/**
|
||||
* Test for includeTotal=false
|
||||
*/
|
||||
$logsWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
||||
]), [
|
||||
'includeTotal' => false
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $logsWithIncludeTotalFalse['headers']['status-code']);
|
||||
$this->assertIsArray($logsWithIncludeTotalFalse['body']);
|
||||
$this->assertIsArray($logsWithIncludeTotalFalse['body']['logs']);
|
||||
$this->assertIsInt($logsWithIncludeTotalFalse['body']['total']);
|
||||
$this->assertEquals(0, $logsWithIncludeTotalFalse['body']['total']);
|
||||
$this->assertGreaterThan(0, count($logsWithIncludeTotalFalse['body']['logs']));
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user