1
0
Fork 0
mirror of synced 2024-10-03 19:53:33 +13:00

refactor according to review feedback

This commit is contained in:
prateek banga 2023-08-08 02:56:20 +05:30
parent 0630f56dd5
commit 52e800cc59

View file

@ -1676,30 +1676,28 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes')
throw new Exception(Exception::COLLECTION_NOT_FOUND); throw new Exception(Exception::COLLECTION_NOT_FOUND);
} }
$queriesFromRequest = Query::parseQueries($queries); $queries = Query::parseQueries($queries);
// Add type property in query if select query exists and type property doesn't exist as type is required for response model // Add type property in query if select query exists and type property doesn't exist as type is required for response model
$hasDetailsinQuery = [ $hasSelect = false;
'selectQuery' => false, $hasTypeAttribute = false;
'typeAttributeInSelectQuery' => false, foreach ($queries as $query) {
];
foreach ($queriesFromRequest as $query) {
if ($query->getMethod() === Query::TYPE_SELECT) { if ($query->getMethod() === Query::TYPE_SELECT) {
$hasDetailsinQuery['selectQuery'] = true; $hasSelect = true;
} }
if (\array_search('type', $query->getValues())) { if (\array_search('type', $query->getValues())) {
$hasDetailsinQuery['typeAttributeInSelectQuery'] = true; $hasTypeAttribute = true;
} }
} }
$transformedQueries = $queriesFromRequest;
if ($hasDetailsinQuery['selectQuery'] && !$hasDetailsinQuery['typeAttributeInSelectQuery']) {
\array_push($transformedQueries, Query::select(['type']));
}
\array_push($transformedQueries, Query::equal('collectionId', [$collectionId]), Query::equal('databaseId', [$databaseId])); if ($hasSelect && !$hasTypeAttribute) {
\array_push($queries, Query::select(['type']));
}
\array_push($queries, Query::equal('collectionId', [$collectionId]), Query::equal('databaseId', [$databaseId]));
// Get cursor document if there was a cursor query // Get cursor document if there was a cursor query
$cursor = Query::getByType($transformedQueries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]); $cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]);
$cursor = reset($cursor); $cursor = reset($cursor);
if ($cursor) { if ($cursor) {
@ -1716,8 +1714,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes')
$cursor->setValue($cursorDocument[0]); $cursor->setValue($cursorDocument[0]);
} }
$attributes = $dbForProject->find('attributes', $transformedQueries); $attributes = $dbForProject->find('attributes', $queries);
$filterQueries = Query::groupByType($transformedQueries)['filters']; $filterQueries = Query::groupByType($queries)['filters'];
$total = $dbForProject->count('attributes', $filterQueries, APP_LIMIT_COUNT); $total = $dbForProject->count('attributes', $filterQueries, APP_LIMIT_COUNT);
//Add relationship data from options to attributes as it loses options during response setup //Add relationship data from options to attributes as it loses options during response setup
@ -1740,7 +1738,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes')
]), Response::MODEL_ATTRIBUTE_LIST); ]), Response::MODEL_ATTRIBUTE_LIST);
// If type Attribute didn't exist in select query we need to remove type attribute from attribute list // If type Attribute didn't exist in select query we need to remove type attribute from attribute list
if ($hasDetailsinQuery['selectQuery'] && !$hasDetailsinQuery['typeAttributeInSelectQuery']) { if ($hasSelect && !$hasTypeAttribute) {
foreach ($output['attributes'] as &$attribute) { foreach ($output['attributes'] as &$attribute) {
unset($attribute['type']); unset($attribute['type']);
} }