In the legacy UI we have a concept edit page, which allows to add/remove/edit concept names and then save all changes. On the server side we need to iterate though all concept names and compare them with those stored in database to determine, which ones were modified/added/removed by the user and persist changes.
In the new UI, which uses REST, we cannot simply update a concept resource by sending a concept with names. We must do separate REST calls to update each name if modified by the user.
The question is how to best handle updating names via REST. I see 3 options:
We add a feature to the REST api, which allows to update a collection of names passed with a concept.
-OR-
We change the edit concepts page so that each edited name is confirmed by the user and is sent right away to the server in a separate ajax call.
-OR-
Javascript tracks which names have been added/removed/edited and sends multiple REST requests to the server when the user saves the concept.
I like 3) but with a single REST after each inserted/updated/deleted name (a mix of 2 and 3).
I don’t like 1) because it doesn’t fit well in the current REST API architecture. Think about all the UIs yet to be developed, it will lead to an explosion of REST API methods. IMHO the REST API must be equivalent (o very similar) to the Service Layer, and NOT a facade for the UI. But still, I think a facade is needed (don’t know if in JS or in a Controller).
I choose 1) because I think editing names should be thought of as a single transaction (may be not a big deal in this case but I like to imagine one would want to specify full & short names at one go)
By the way using a single request fits well with current REST API because concept names are sub resources of Concepts which means you can POST an array of names in a payload using a concept endpoint as shown below.
POST /ws/rest/v1/concept/{conceptUuid}
{
"names":[ {
"name": "some name",
"uuid": "uuid of the name"
}, {
// Some other name
}
]
}
I haven’t tested this but I think it should work because I have been doing a similar thing with person and person attributes.