OBPIH-6119 Add endpoint to create/edit product supplier preference#4526
OBPIH-6119 Add endpoint to create/edit product supplier preference#4526awalkowiak merged 2 commits intofeature/product-supplier-list-redesignfrom
Conversation
…ith backend (ability to bind the command automatically)
…ct supplier preference
| List<ProductSupplierPreference> productSupplierPreferences = | ||
| productSupplierPreferenceService.saveOrUpdateBatch(command.productSupplierPreferences) | ||
|
|
||
| response.status = HttpStatus.OK.value() |
There was a problem hiding this comment.
I have one problem with the status code here, but I know that we created some endpoints that support creating and updating.
But when the function does a create stuff it should be 201 status, when it's updating then it should be 200.
There was a problem hiding this comment.
Then what status would you send if we create and update at once?
There was a problem hiding this comment.
It wasn't a change request, just a loud thinking that I don't like creating and updating in the same endpoint.
| ProductSupplierPreference persistedProductSupplierPreference = | ||
| productSupplierPreferenceService.save(productSupplierPreference) |
There was a problem hiding this comment.
Basically, if the function works on the passed instance (on the exact reference) you don't have to allocate a new place in memory, because the original instance should be updated.
There was a problem hiding this comment.
you are right, but I did it for a better readability. If you strongly feel like this might cause any problems, let me know so I will change that
| ProductSupplierPreference save(ProductSupplierPreference productSupplierPreference) { | ||
| // Add the product supplier preference instance to the productSupplier's preferences collection (OneToMany bidirectional) | ||
| productSupplierPreference?.productSupplier?.addToProductSupplierPreferences(productSupplierPreference) | ||
| return productSupplierPreference.save(flush: true, failOnError: true) |
There was a problem hiding this comment.
Is this flush required? I know that you are using this function below, but I am curious whether it will be working without the flush.
There was a problem hiding this comment.
flush is required here. Since we have validation for uniqueness of destinationParty per productSupplier, if we create preferences in batch and let's say you send three preferences with the same destinationParty, all of them would be saved correctly, because we didn't synchronize the persistence context.
The flush is required here to synchronize the DB constraints - in this case - uniqueness of the destinationParty per productSupplier.
There was a problem hiding this comment.
When you said ...we have validation for uniqueness... then I got it 😄
awalkowiak
left a comment
There was a problem hiding this comment.
Merging as is for now, but the conventions around this will be discussed on the tech huddle
…4526) * OBPIH-6119 Adjust names of properties on the frontend side to align with backend (ability to bind the command automatically) * OBPIH-6119 Add endpoint to create/edit (both single, and batch) product supplier preference
No description provided.