spring-projects / spring-projects/spring-data-rest
Add POST /{repository}/{id}/{property} for adding new Objects to a Collection [DATAREST-349]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Benjamin M opened DATAREST-349 and commented
It would be cool, if there was POST /\{repository\}/\{id\}/\{property\}
For example I have an Entity Invoice which hast a List<Payment> payments:
@Entity
public class Invoice {
@ElementCollection
@CollectionTable(
name="Invoice_Payment",
joinColumns=@JoinColumn(name="Invoice_id")
)
List<InvoicePayment> payments;
}
At the moment I have to PATCH/PUT /invoices/\{id\} to add a Payment item, but it would be much easier, if I just could do:
POST /invoices/{id}/payments
{
"amount":100.00,
"currencyUnit":"EUR"
}
I can't really think of an inverse action, in order to delete (or update) a specific item from the List since there's no primary key. But for this scenario there are Map s.
—
Btw: What's the proper way to use PATCH/PUT /\{repository\}/\{id\}/\{property\} ? I was able to clear my List of payments using \{\} as request body, but I wasn't able to replace all items with it. Here's what I tried:
{"payments":[{
"currencyUnit": "EUR",
"amount": 7000
}]}
[{
"currencyUnit": "EUR",
"amount": 7000
}]
{[{
"currencyUnit": "EUR",
"amount": 7000
}]}
—
EDIT: I just recognized, that there are a lot of other calls missing :) Here we go:
PUT /{repository}/{id}/{property}/{propertyId}
So I can add/replace an element to/of a Map
PATCH /{repository}/{id}/{property}/{propertyId}
To replace the content of a Map entry,
doesn't put it into the list, if it's not already present
POST /{repository}/{id}/{property}/{propertyId}
The other way round of PATCH: Add the new element if it's not already present,
but do not replace an existing one
POST /{repository}/{id}/{property}
To add an element to a List
GET /{repository}/{id}/{property}
At the moment, this only works for entities, but not for @Embeddables,
Should work for both
Affects: 2.1.1 (Dijkstra SR1)
1 votes, 2 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.