icatproject / topcat

GUI to work with multiple ICAT and IDS servers.
Other
1 stars 9 forks source link

Add `remove` Form Parameter to /cartItems #483

Closed MRichards99 closed 2 years ago

MRichards99 commented 2 years ago

As per https://github.com/ral-facilities/datagateway/issues/1210#issuecomment-1092983096, this PR adds a form parameter called remove on the POST request to /cartItems. This parameter acts as a convenient way to remove items from the cart using POST, rather than DELETE. As such, when remove is set to true, it calls deleteCartItems() instead of executing the logic from addCartItems().

The logic I've added means that remove is false by default; it's not explicitly set to false but the call to deleteCartItems() only occurs when it is true so if remove isn't specified in the request, items will be added to the cart (i.e. the existing behaviour).

I edited the tests as needed and checked they pass. I created a new VM (using the Vagrantfile on this repo) to ensure I had the correct testing environment.

There are no specific tests for addCartItems() so I haven't added any new ones testing this new behaviour. I did manually test on my own machine adding and removing items from the cart, although that was only a couple at a time (rather than the potentially hundreds that one might experience on a production machine).

louise-davies commented 2 years ago

@MRichards99 I had to use @DefaultValue as otherwise not specifying the remove param caused errors and thus it wasn't a backwards compatible change. I have deployed a snapshot of this branch on scigateway-preprod and it seems to work fine

MRichards99 commented 2 years ago

@louise-davies just seen the changes you've made, I didn't pick that up while I was testing it, glad you've sorted it