Skip to content

OBPIH-6119 Add endpoint to create/edit product supplier preference#4526

Merged
awalkowiak merged 2 commits intofeature/product-supplier-list-redesignfrom
OBPIH-6119
Mar 4, 2024
Merged

OBPIH-6119 Add endpoint to create/edit product supplier preference#4526
awalkowiak merged 2 commits intofeature/product-supplier-list-redesignfrom
OBPIH-6119

Conversation

@kchelstowski
Copy link
Collaborator

No description provided.

@kchelstowski kchelstowski self-assigned this Mar 1, 2024
List<ProductSupplierPreference> productSupplierPreferences =
productSupplierPreferenceService.saveOrUpdateBatch(command.productSupplierPreferences)

response.status = HttpStatus.OK.value()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then what status would you send if we create and update at once?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't a change request, just a loud thinking that I don't like creating and updating in the same endpoint.

Comment on lines +19 to +20
ProductSupplierPreference persistedProductSupplierPreference =
productSupplierPreferenceService.save(productSupplierPreference)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you said ...we have validation for uniqueness... then I got it 😄

Copy link
Collaborator

@awalkowiak awalkowiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging as is for now, but the conventions around this will be discussed on the tech huddle

@awalkowiak awalkowiak merged commit 70221dc into feature/product-supplier-list-redesign Mar 4, 2024
@awalkowiak awalkowiak deleted the OBPIH-6119 branch March 4, 2024 12:48
awalkowiak pushed a commit that referenced this pull request Mar 12, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants