Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FRW-6430 Data Exchange API Complex Endpoints for POST, PUT and PATCH #2479

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Install the required features:
Install the required modules using Composer:

```bash
composer require spryker/dynamic-entity-backend-api:"^1.0.0" spryker/dynamic-entity-gui:"^1.0.0" --update-with-dependencies
composer require spryker/dynamic-entity-backend-api:"^1.5.0" spryker/dynamic-entity-gui:"^1.0.0" --update-with-dependencies
```

{% info_block warningBox "Verification" %}
Expand Down Expand Up @@ -377,12 +377,12 @@ dynamic_entity.validation.persistence_failed_duplicate_entry,"Failed to persist
dynamic_entity.validation.persistence_failed_duplicate_entry,"Das Speichern der Daten ist fehlgeschlagen. Bitte überprüfen Sie die bereitgestellten Daten und versuchen Sie es erneut. Eintrag is doppelt vorhanden.",de_DE
dynamic_entity.validation.entity_does_not_exist,"The entity could not be found in the database.",en_US
dynamic_entity.validation.entity_does_not_exist,"Die Entität konnte in der Datenbank nicht gefunden werden.",de_DE
dynamic_entity.validation.invalid_field_type,"Invalid data type for field: %fieldName%",en_US
dynamic_entity.validation.invalid_field_type,"Ungültiger Datentyp: %fieldName%",de_DE
dynamic_entity.validation.invalid_field_type,"Invalid data type for field: %tableAlias%.%fieldName%",en_US
dynamic_entity.validation.invalid_field_type,"Ungültiger Datentyp: %tableAlias%.%fieldName%",de_DE
dynamic_entity.validation.invalid_field_value,"Invalid data value for field: %fieldName%, row number: %rowNumber%. Field rules: %validationRules%",en_US
dynamic_entity.validation.invalid_field_value,"Ungültiger Datenwert für das Feld: %fieldName%, Zeilennummer: %rowNumber%. Feldregeln: %validationRules%",de_DE
dynamic_entity.validation.required_field_is_missing,"The required field must not be empty. Field: '%fieldName%'",en_US
dynamic_entity.validation.required_field_is_missing,"Das erforderlich Feld darf nicht leer sein. Feld: '%fieldName%'",de_DE
dynamic_entity.validation.required_field_is_missing,"The required field must not be empty. Field: '%tableAlias%.%fieldName%'",en_US
dynamic_entity.validation.required_field_is_missing,"Das erforderlich Feld darf nicht leer sein. Feld: '%tableAlias%.%fieldName%'",de_DE
dynamic_entity.validation.entity_not_found_or_identifier_is_not_creatable,"Entity `%identifier%` not found by identifier, and new identifier can not be persisted. Please update the request.",en_US
dynamic_entity.validation.entity_not_found_or_identifier_is_not_creatable,"Entität `%identifier%` konnte anhand der ID nicht gefunden werden, und die neue ID kann nicht dauerhaft gespeichert werden. Bitte aktualisieren Sie die Anfrage.",de_DE
dynamic_entity.validation.modification_of_immutable_field_prohibited,"Modification of immutable field `%fieldName%` is prohibited",en_US
Expand All @@ -393,6 +393,8 @@ dynamic_entity.validation.provided_field_is_invalid,"The provided `%fieldName%`
dynamic_entity.validation.provided_field_is_invalid,"Der angegebene `%fieldName%` ist falsch oder ungültig.",de_DE
dynamic_entity.validation.relation_not_found,"Relation %relationName% not found. Please check the requested relation name and try again.",en_US
dynamic_entity.validation.relation_not_found,"Beziehung %relationName% nicht gefunden. Bitte überprüfen Sie den angeforderten Beziehungsnamen und versuchen Sie es erneut.",de_DE
dynamic_entity.validation.relation_is_not_editable,"The relationship `%relationName%` is not editable by configuration.",en_US
dynamic_entity.validation.relation_is_not_editable,"Die Beziehung `%relationName%` kann nicht per Konfiguration bearbeitet werden.",de_DE
dynamic_entity.validation.configuration_not_found,"Dynamic entity configuration for table alias `%aliasName%` not found.",en_US
dynamic_entity.validation.configuration_not_found,"Dynamische Entitätskonfiguration für Tabellenalias `%aliasName%` nicht gefunden.",de_DE
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,100 @@ to ensure accurate and consistent data manipulation during `PUT` operations.

{% endinfo_block %}

### Sending `POST`, `PATCH`б and `PUT` requests with relationships

To create or update an entity along with its related entities, you need to include the relationships directly in
the request payload. The payload should be structured to reflect the hierarchy and connections between the main entity
and its child entities.

{% info_block infoBox %}

Currently, our system doesn't support `many-to-many` relationships for POST, PATCH, and PUT requests.
Only `one-to-one` and `one-to-many` relationships are allowed. This means that each child entity can be associated
with only one parent entity.

{% endinfo_block %}

The payload for these requests follows a nested structure where the main entity and its related entities are included within a data array.
Each object in the data array represents an instance of the main entity, and each related entity is nested within it.

For correct processing, make sure that related entities are defined with existing relation names. Also, organize them in alignment with their hierarchical relationships in the database, corresponding to the relationships defined in tables like `spy_dynamic_entity_configuration_relation` and `spy_dynamic_entity_configuration_relation_field_mapping`:

- `spy_dynamic_entity_configuration_relation` specifies the relationships between parent and child entities. Each record links a parent entity to a child entity.
- `spy_dynamic_entity_configuration_relation_field_mapping` contains the field mappings between related entities.

The hierarchical relationships are primarily defined by the foreign key references in these tables.
For example, `spy_dynamic_entity_configuration_relation` uses foreign keys to establish connections between
parent and child configurations in `spy_dynamic_entity_configuration`.

Incorrect or non-existent relation names or a misalignment in the hierarchy leads to processing errors.
For a detailed list of potential errors, see [Error codes](#error-codes).

For POST, PATCH, and PUT requests the payload must accurately reflect the entity relationships.
Make sure that each entity in the request includes its corresponding related entities, structured as nested objects within the payload.

```bash
POST /dynamic-entity/countries HTTP/1.1
Host: glue-backend.mysprykershop.com
Content-Type: application/json
Accept: application/json
Authorization: Bearer {your_token}
Content-Length: 245

{
"data": [
{
"iso2_code": "DE",
"iso3_code": "DEU",
"name": "Germany",
"countryTaxRates": [
{
"name": "Germany Standard",
"rate": "1.00"
}
]
}
]
}
```

Response sample:

```json
{
"data": [
{
"iso2_code": "DE",
"iso3_code": "DEU",
"name": "Germany",
"postal_code_mandatory": null,
"postal_code_regex": null,
"id_country": 1,
"countryTaxRates": [
{
"name": "Germany Standard",
"rate": "1.00",
"id_country_tax_rate": 1,
"fk_country": 1
}
]
}
]
}
```

The response contains all columns from the `spy_country` table and the included `spy_tax_rate` table,
as configured in `spy_dynamic_entity_definition.definition`. Each column is identified using the `fieldVisibleName`
as the key, providing a comprehensive view of the table’s data in the API response.

{% info_block infoBox %}

For POST and PUT requests, which are used to create new entities, child entities receive their foreign key reference
to the parent entity only after the parent entity is created. The system automatically assigns the foreign key
to the child entities based on the newly created parent entity's ID.

{% endinfo_block %}

#### Error codes

Bellow, you can find a list of error codes that you can receive when sending `GET`, `POST`, `PATCH` or `PUT` requests.
Expand All @@ -483,4 +577,5 @@ Bellow, you can find a list of error codes that you can receive when sending `GE
| 1310 | Incomplete Request - missing identifier. | The request is incomplete. The identifier is missing. Check the request and try again. |
| 1311 | The provided `field` is incorrect or invalid. | The request contains a field that isn't present in the configuration. Check the field names. |
| 1312 | Dynamic entity configuration for table alias `alias` not found. | Make sure that you send the valid alias of the entity in the request. |
| 1313 | Relation `relation` not found. Please check the requested relation name and try again. | Make sure that the relation that you send in the relation chain is valid and present in the `spy_dynamic_entity_configuration_relation` table. |
| 1313 | Relation `relation` not found. Please check the requested relation name and try again. | Make sure that the relation that you send in the relation chain is valid and present in the `spy_dynamic_entity_configuration_relation` table. |
| 1314 | The relationship `relation` is not editable by configuration. | Make sure that the relation that you send in the relation chain is configurable. |
Loading