diff --git a/Controller/ApiAddressAttributeController.php b/Controller/ApiAddressAttributeController.php index 6bebdea..2f014c0 100644 --- a/Controller/ApiAddressAttributeController.php +++ b/Controller/ApiAddressAttributeController.php @@ -61,7 +61,23 @@ final class ApiAddressAttributeController extends Controller return; } - $type = AddressAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('type'))->execute(); + $type = AddressAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('type'))->execute(); + + if (!$type->repeatable) { + $attr = AddressAttributeMapper::count() + ->with('type') + ->where('type/id', (int) $request->getData('type')) + ->where('ref', (int) $request->getData('ref')) + ->execute(); + + if ($attr > 0) { + $response->header->status = RequestStatusCode::R_409; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + } + $attribute = $this->createAttributeFromRequest($request, $type); $this->createModel($request->header->account, $attribute, AddressAttributeMapper::class, 'attribute', $request->getOrigin()); $this->createStandardCreateResponse($request, $response, $attribute); diff --git a/Controller/ApiAttributeController.php b/Controller/ApiAttributeController.php index f4ddaf2..9112aa4 100644 --- a/Controller/ApiAttributeController.php +++ b/Controller/ApiAttributeController.php @@ -61,7 +61,23 @@ final class ApiAttributeController extends Controller return; } - $type = UnitAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('type'))->execute(); + $type = UnitAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('type'))->execute(); + + if (!$type->repeatable) { + $attr = UnitAttributeMapper::count() + ->with('type') + ->where('type/id', (int) $request->getData('type')) + ->where('ref', (int) $request->getData('ref')) + ->execute(); + + if ($attr > 0) { + $response->header->status = RequestStatusCode::R_409; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + } + $attribute = $this->createAttributeFromRequest($request, $type); $this->createModel($request->header->account, $attribute, UnitAttributeMapper::class, 'attribute', $request->getOrigin()); $this->createStandardCreateResponse($request, $response, $attribute); diff --git a/Models/Attribute/AddressAttributeTypeMapper.php b/Models/Attribute/AddressAttributeTypeMapper.php index 8e1a3b4..d4443ff 100644 --- a/Models/Attribute/AddressAttributeTypeMapper.php +++ b/Models/Attribute/AddressAttributeTypeMapper.php @@ -42,6 +42,7 @@ final class AddressAttributeTypeMapper extends DataMapperFactory 'address_attr_type_datatype' => ['name' => 'address_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'], 'address_attr_type_fields' => ['name' => 'address_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], 'address_attr_type_custom' => ['name' => 'address_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], + 'address_attr_type_repeatable' => ['name' => 'address_attr_type_repeatable', 'type' => 'bool', 'internal' => 'repeatable'], 'address_attr_type_pattern' => ['name' => 'address_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], 'address_attr_type_required' => ['name' => 'address_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], ]; diff --git a/Models/Attribute/AddressAttributeValueMapper.php b/Models/Attribute/AddressAttributeValueMapper.php index 83b4a7f..ec33353 100644 --- a/Models/Attribute/AddressAttributeValueMapper.php +++ b/Models/Attribute/AddressAttributeValueMapper.php @@ -59,6 +59,7 @@ final class AddressAttributeValueMapper extends DataMapperFactory 'mapper' => AddressAttributeValueL11nMapper::class, 'table' => 'address_attr_value_l11n', 'self' => 'address_attr_value_l11n_value', + 'column' => 'content', 'external' => null, ], ]; diff --git a/Models/Attribute/UnitAttributeTypeMapper.php b/Models/Attribute/UnitAttributeTypeMapper.php index 2941e5e..a9eed0d 100644 --- a/Models/Attribute/UnitAttributeTypeMapper.php +++ b/Models/Attribute/UnitAttributeTypeMapper.php @@ -42,6 +42,7 @@ final class UnitAttributeTypeMapper extends DataMapperFactory 'unit_attr_type_datatype' => ['name' => 'unit_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'], 'unit_attr_type_fields' => ['name' => 'unit_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], 'unit_attr_type_custom' => ['name' => 'unit_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], + 'unit_attr_type_repeatable' => ['name' => 'unit_attr_type_repeatable', 'type' => 'bool', 'internal' => 'repeatable'], 'unit_attr_type_pattern' => ['name' => 'unit_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], 'unit_attr_type_required' => ['name' => 'unit_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], ]; diff --git a/Models/Attribute/UnitAttributeValueMapper.php b/Models/Attribute/UnitAttributeValueMapper.php index a6e9dcd..58af03b 100644 --- a/Models/Attribute/UnitAttributeValueMapper.php +++ b/Models/Attribute/UnitAttributeValueMapper.php @@ -59,6 +59,7 @@ final class UnitAttributeValueMapper extends DataMapperFactory 'mapper' => UnitAttributeValueL11nMapper::class, 'table' => 'unit_attr_value_l11n', 'self' => 'unit_attr_value_l11n_value', + 'column' => 'content', 'external' => null, ], ];