Parse min and max from formatOptions for response model
This commit is contained in:
parent
af2e64ef7b
commit
7506142ab9
|
@ -831,13 +831,14 @@ App::get('/v1/database/collections/:collectionId/attributes/:attributeId')
|
|||
])]);
|
||||
|
||||
$type = $attribute->getAttribute('type');
|
||||
$format = json_decode($attribute->getAttribute('format'), true);
|
||||
$format = $attribute->getAttribute('format');
|
||||
$formatOptions = $attribute->getAttribute('formatOptions');
|
||||
|
||||
$model = match($type) {
|
||||
Database::VAR_BOOLEAN => Response::MODEL_ATTRIBUTE_BOOLEAN,
|
||||
Database::VAR_INTEGER => Response::MODEL_ATTRIBUTE_INTEGER,
|
||||
Database::VAR_FLOAT => Response::MODEL_ATTRIBUTE_FLOAT,
|
||||
Database::VAR_STRING => match($format['name']) {
|
||||
Database::VAR_STRING => match($format) {
|
||||
APP_DATABASE_ATTRIBUTE_URL => Response::MODEL_ATTRIBUTE_EMAIL,
|
||||
APP_DATABASE_ATTRIBUTE_IP => Response::MODEL_ATTRIBUTE_IP,
|
||||
APP_DATABASE_ATTRIBUTE_URL => Response::MODEL_ATTRIBUTE_URL,
|
||||
|
@ -845,6 +846,18 @@ App::get('/v1/database/collections/:collectionId/attributes/:attributeId')
|
|||
},
|
||||
default => Response::MODEL_ATTRIBUTE,
|
||||
};
|
||||
|
||||
// Format response if options are provided
|
||||
// And response model needs to be modified
|
||||
if (!empty($formatOptions) &&
|
||||
($type === Response::MODEL_ATTRIBUTE_INTEGER ||
|
||||
$type === Response::MODEL_ATTRIBUTE_FLOAT))
|
||||
{
|
||||
$attribute->setAttribute('min', $formatOptions['min'], $type);
|
||||
$attribute->setAttribute('max', $formatOptions['max'], $type);
|
||||
// unset($attribute['format']);
|
||||
// unset($attribute['formatOptions']);
|
||||
}
|
||||
|
||||
$response->dynamic($attribute, $model);
|
||||
});
|
||||
|
|
|
@ -12,15 +12,19 @@ class AttributeFloat extends Attribute
|
|||
parent::__construct();
|
||||
|
||||
$this
|
||||
->addRule('format', [
|
||||
'type' => self::TYPE_FLOAT,
|
||||
'description' => 'Float format.',
|
||||
->addRule('min', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Minimum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => \json_encode([
|
||||
'name' => APP_DATABASE_ATTRIBUTE_FLOAT_RANGE,
|
||||
'min' => 1.5,
|
||||
'max' => 2.5,
|
||||
]),
|
||||
'example' => 1,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
->addRule('max', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Maximum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => 10,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
|
|
|
@ -12,15 +12,19 @@ class AttributeInteger extends Attribute
|
|||
parent::__construct();
|
||||
|
||||
$this
|
||||
->addRule('format', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Integer format.',
|
||||
->addRule('min', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Minimum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => \json_encode([
|
||||
'name' => APP_DATABASE_ATTRIBUTE_INT_RANGE,
|
||||
'min' => 0,
|
||||
'max' => 10,
|
||||
]),
|
||||
'example' => 1,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
->addRule('max', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Maximum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => 10,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
|
|
Loading…
Reference in a new issue