mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix limit & offset computation
This commit is contained in:
@@ -1057,11 +1057,11 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
|
||||
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
|
||||
|
||||
$queries = Query::parseQueries($queries);
|
||||
$limitQuery = array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_LIMIT);
|
||||
$offsetQuery = array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_OFFSET);
|
||||
$limitQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_LIMIT));
|
||||
$offsetQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_OFFSET));
|
||||
|
||||
$limit = !empty($limitQuery) ? $limitQuery[0]->getValue() : 4;
|
||||
$offset = !empty($offsetQuery) ? $offsetQuery[0]->getValue() : 0;
|
||||
$limit = !empty($limitQuery) ? $limitQuery->getValue() : 4;
|
||||
$offset = !empty($offsetQuery) ? $offsetQuery->getValue() : 0;
|
||||
$page = ($offset / $limit) + 1;
|
||||
|
||||
$owner = $github->getOwnerName($providerInstallationId);
|
||||
|
||||
@@ -316,6 +316,43 @@ class VCSConsoleClientTest extends Scope
|
||||
$this->assertEquals($searchedRepositories['body']['runtimeProviderRepositories'][0]['name'], 'appwrite');
|
||||
$this->assertEquals($searchedRepositories['body']['runtimeProviderRepositories'][0]['runtime'], 'other');
|
||||
|
||||
// with limit and offset
|
||||
$repositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $installationId . '/providerRepositories', array_merge([
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'type' => 'runtime',
|
||||
'limit' => 1,
|
||||
'offset' => 0
|
||||
]);
|
||||
$this->assertSame(200, $repositories['headers']['status-code']);
|
||||
$this->assertSame(4, $repositories['body']['total']);
|
||||
$this->assertSame(1, \count($repositories['body']['runtimeProviderRepositories']));
|
||||
$this->assertSame('starter-for-svelte', $repositories['body']['runtimeProviderRepositories'][0]['name']);
|
||||
|
||||
$repositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $installationId . '/providerRepositories', array_merge([
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'type' => 'runtime',
|
||||
'limit' => 2,
|
||||
'offset' => 1
|
||||
]);
|
||||
$this->assertSame(200, $repositories['headers']['status-code']);
|
||||
$this->assertSame(4, $repositories['body']['total']);
|
||||
$this->assertSame(2, \count($repositories['body']['runtimeProviderRepositories']));
|
||||
$this->assertSame('templates-for-functions', $repositories['body']['runtimeProviderRepositories'][0]['name']);
|
||||
$this->assertSame('appwrite', $repositories['body']['runtimeProviderRepositories'][1]['name']);
|
||||
|
||||
$repositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $installationId . '/providerRepositories', array_merge([
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'type' => 'runtime',
|
||||
'limit' => 2,
|
||||
'offset' => 100
|
||||
]);
|
||||
$this->assertSame(200, $repositories['headers']['status-code']);
|
||||
$this->assertSame(4, $repositories['body']['total']);
|
||||
$this->assertSame(0, \count($repositories['body']['runtimeProviderRepositories']));
|
||||
|
||||
// TODO: If you are about to add another check, rewrite this to @provideScenarios
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user