diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 2dd5c3f0e7..0490712e11 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -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); }); diff --git a/src/Appwrite/Utopia/Response/Model/AttributeFloat.php b/src/Appwrite/Utopia/Response/Model/AttributeFloat.php index 669aa4dd7e..a0f68ec6af 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeFloat.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeFloat.php @@ -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, ]) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeInteger.php b/src/Appwrite/Utopia/Response/Model/AttributeInteger.php index d1ff6346f3..f11344d79e 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeInteger.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeInteger.php @@ -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, ])