[TASK] Update PageAPI to Save Page Contentlet Styling
Description
1.1 Update Save endpoint /api/v1/page/{pageId}/content.
- Modify the existing endpoint responsible for saving page containers to accept
stylePropertiesmap in the request payload. - Ensure the payload structure supports mapping specific styles to specific contentlet UUIDs within a container
1.2 Implement Persistence Logic
- Update the backend service to parse and persist the
stylePropertiesJSON object. - Context Awareness: Ensure styles are saved specifically for the Contentlet instance within that specific Container and Page (MultiTree table is responsible to join them).
💡 This allows the same Contentlet used in two different containers (or Pages) be able to have different style properties.
1.3 Write Tests
- Integration Tests: Verify that when a Page/Container is saved, the style data is correctly written to the database.
- Postman Test: Verify the endpoint accepts the updated JSON structure (see context for example).
Acceptance Criteria
- [ ] The Save Endpoint accepts the
stylePropertiesobject within the container list payload. - [ ] Styles are successfully persisted to the database, linked to the specific Page-Container-Contentlet relationship.
- [ ] Contextality Check: It is verified that the same contentlet can hold distinct style configurations in different containers.
- [ ] Existing save functionality remains unaffected (Regression check).
Priority
None
Additional Context
- Example Payload Structure: The endpoint now accepts a styleProperties object keyed by the contentlet UUID:
[
{
"identifier": "//demo.dotcms.com/application/containers/default/",
"uuid": "1",
"contentletsId": [
"7c9cb3a7-bb68-4fd0-b21d-03ec4be491a7"
],
"styleProperties": { // this is the new field containing the styles per contentlet
"7c9cb3a7-bb68-4fd0-b21d-03ec4be491a7": {
"width": "100px",
"color": "#FF0000",
"margin": "10px"
}
}
}
]
- Here is an example of a cURL request pointing to
localhost:8080
curl --location 'localhost:8080/api/v1/page/bec7b960-a8bf-4f14-a22b-0d94caf217f0/content' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YWRtaW5AZG90Y21zLmNvbTphZG1pbg==' \
--header 'Cookie: JSESSIONID=7C27D704C99706F30F0C41CD118418CC; rme=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI3MTgxNjdjOC1jN2ZmLTQyYzAtOWY1MC1mMjdlMjI4NWU2ZTMiLCJ4bW9kIjoxNzY1Mzc2NTIzNzU4LCJzdWIiOiJpWnJmYkpiaW4rZmpGNVNTcXBBcm9BPT0iLCJpYXQiOjE3NjUzNzY1MjMsImlzcyI6ImRvdGNtcy1wcm9kdWN0aW9uIiwiZXhwIjoxNzY1NDYyOTIzfQ.eNNaRm6HdaquyK2M4_1UQfOPOgoKwHOukn_RgRE3YSs' \
--data '[
{
"identifier": "//demo.dotcms.com/application/containers/default/",
"uuid": "1",
"contentletsId": [
"7c9cb3a7-bb68-4fd0-b21d-03ec4be491a7"
],
"styleProperties": {
"7c9cb3a7-bb68-4fd0-b21d-03ec4be491a7": {
"width": "100px",
"color": "#FF0000",
"margin": "10px"
}
}
},
{
"identifier": "//demo.dotcms.com/application/containers/default/",
"uuid": "1",
"contentletsId": [
"f827c41a-5689-4733-b4d7-916d3a31c9c6"
]
}
]'
PRs linked to this issue
- modify PageAPI to save style properties per contentlet by @dario-daza
PRs linked to this issue
- 33695 task update pageapi to expose style properties by @dario-daza
- modify PageAPI to save style properties per contentlet by @dario-daza
QA NOTES:
Due the resource currently is not returning relevant information about the Contentlets saved, when you make a Save request using the cURL (see Additional context above), the only way to check that the service saved the styles properties is connecting to the Database and search for the field modified.
- Connect to the Database using the data that you define in your
docker-compose, remember that you have to enable the port of the DB to connect to it from your local. - Search for the
multi_treetable. - Filter the
contentletIdto which you applied the styles, e.g:
SELECT * FROM multi_tree WHERE child = '7c9cb3a7-bb68-4fd0-b21d-03ec4be491a7';
💡 Keep in mind that the field
childin themulti_treetable is for the contentletIds.
QA Failed
Tested in main 290cee7
https://github.com/user-attachments/assets/5328094d-978b-48a0-9a42-282a73ba9afe
The saving functionality works, but I found that we're not validating the contentlet identifier within the "styleProperties" object, which makes debugging and finding errors confusing, since now, regardless of whether the contentlet identifier exists or not, we always receive "entity": "ok".
I believe the correct flow would be:
If any of the contentlets within styleProperties doesn't exist, I don't save any and I return an exception.
This means that if I send three contentlets correctly and one incorrectly, none are saved.
This is to prevent errors and confusion with the endpoint.
thoughts? cc: @dario-daza @nollymar @fmontes
I agree with the poor response. However, I'm not sure if we should couple the Style Properties to the Contentlet saving process. Not all Contentlets define Style Properties, and even when they do, those properties are not strictly required for the Contentlet itself.
So if a single Contentlet in a Page has Styles (bad defined) the failure shouldn't impact all the other ones, in this case, it would be better to skip the non-matching or invalid styles with a warning message and still return a successful response with the contentlets saved and the valid styles applied. Below I attach a video showing how the warning message would look:
https://github.com/user-attachments/assets/2ddf3a59-c1a2-40ce-a782-c1f042c7ae1c
What do you think @fmontes @nollymar @KevinDavilaDotCMS
Passed QA
Tested in main 1350a2e
https://github.com/user-attachments/assets/675e512f-1196-407c-8ea1-fb8e39e3051e
I've noticed an issue with the api/v1/page/${pageIdentifier}/content endpoint. It appears that content is lost when saving style properties. Please see the video below for details.
https://github.com/user-attachments/assets/7bc51554-1465-498b-8bdf-e99da475ac2d
cc: @nollymar @KevinDavilaDotCMS @dario-daza