Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Remove and edit producs groups #40

Merged
merged 5 commits into from
Mar 21, 2017
Merged

Conversation

martijnjanssen
Copy link
Contributor

Still wondering if all endpoints are correct, an endpoint in the form of /products/add is not commonly used, /products would be a better option to do and aligns with standard RESTful endpoint usage.

@skamoen
Copy link

skamoen commented Mar 17, 2017

The adminpanel controllers don't follow REST design 😉

public String addProductGroup(@ModelAttribute @Validated ProductGroupRequest productGroupRequest) {
productService.addProductGroup(productGroupRequest);
System.out.println("here");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, this is old.

public String addProductGroup(@ModelAttribute @Validated ProductGroupRequest productGroupRequest) {
productService.addProductGroup(productGroupRequest);
System.out.println("here");
Copy link

Choose a reason for hiding this comment

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

There!

public String addProductGroup(@ModelAttribute @Validated ProductGroupRequest productGroupRequest) {
productService.addProductGroup(productGroupRequest);
System.out.println("here");

return "redirect:/products";
Copy link

Choose a reason for hiding this comment

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

Please add RedirectAttributes to show a message on the success of the adding

public String deleteProductGroup(@PathVariable int productGroupId, RedirectAttributes redirectAttributes) {
try {
productService.deleteProductGroup(productGroupId);
} catch (RuntimeException e) {
Copy link

Choose a reason for hiding this comment

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

Let's add a ExceptionHandler method for this controller, as the logic is the same for all RuntimeExceptions

Copy link

Choose a reason for hiding this comment

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

Try to have that "redirect" to the current page, so you don't lose a filled in form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would you imagine that? This is a delete endpoint, what should happen?

throw new ProductInUseException("Products are already ordered");
@Override
public void editProductGroup(ProductGroupRequest productGroupRequest) {
if (productGroupRequest.getId() != 0) {
Copy link

Choose a reason for hiding this comment

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

Why this if?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was also in the editProduct() method, could you shed some light on this?

Copy link

Choose a reason for hiding this comment

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

Hmm, probably because the id's are int, which defaults to 0 instead of null

@Override
public void editProductGroup(ProductGroupRequest productGroupRequest) {
if (productGroupRequest.getId() != 0) {
Committee committee = committeeRepository.findOne(productGroupRequest.getCommitteeId());
Copy link

Choose a reason for hiding this comment

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

Let's take the committeeRepository out of this Service. Use the CommitteeService instead

public void editProductGroup(ProductGroupRequest productGroupRequest) {
if (productGroupRequest.getId() != 0) {
Committee committee = committeeRepository.findOne(productGroupRequest.getCommitteeId());
ProductGroup productGroup = productGroupRepository.findOne(productGroupRequest.getId());
Copy link

Choose a reason for hiding this comment

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

Same for this. Create/use a servicecall getProductGroupById() for this, with proper error handling


@Override
public void deleteProductGroup(int productGroupId) {
ProductGroup productGroup = productGroupRepository.findOne(productGroupId);
Copy link

Choose a reason for hiding this comment

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

Servicecall here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So do we want to make a new ProductGroupService and ProductGroupServiceImpl? Either that or leave it here.

Copy link

Choose a reason for hiding this comment

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

I think we can put that in one service. Once we need more functionality that requires a lot more methods, we'll separate them.

public void deleteProductGroup(int productGroupId) {
ProductGroup productGroup = productGroupRepository.findOne(productGroupId);
if (!productGroup.getProducts().isEmpty()) {
throw new ProductGroupInUseException("Product group must be empty");
Copy link

Choose a reason for hiding this comment

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

Is this really the case? What would break if you remove a group with products in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had previously implemented it in a way where products were removed from the group when the group was removed, but this may be an action where we don't want it to be very easy to perform. I'm also not quite sure which way to go, it made sense to me that since there is a limit involved, you don't want it to be this easy, just like removing a product that is already ordered.

Copy link

Choose a reason for hiding this comment

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

Alright, then perhaps add a section to the editGroup page where you can remove products currently in the group?

Copy link
Contributor Author

@martijnjanssen martijnjanssen Mar 19, 2017

Choose a reason for hiding this comment

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

We can also add the removal of tickets from a group as a hoothub issue, since this is not very high prioroty. It is also not relevant to editing the product group, it would make more sense to have it in a different page. /products/group/editproductsor something similar.

Copy link

Choose a reason for hiding this comment

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

Leave it like this for now, and create a HootHub issue to implement this nicely.

package ch.wisv.payments.exception;

public class ProductGroupInUseException extends RuntimeException {
public ProductGroupInUseException(String s) {
Copy link

Choose a reason for hiding this comment

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

This constructor is already in RuntimeException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You unfortunately have to do this to make use of the super(...) constructor though.

@martijnjanssen
Copy link
Contributor Author

martijnjanssen commented Mar 17, 2017

I'm not quite sure what your plan was with the return to the form on the delete, since there is no form at all there.

On the other hand, I also can't figure out how to handle deleting a ProductGroup when there are tickets present. The action to remove the items from the group in the edit form is also not very intuitive in my opinion. I think we have to think of a different solution for this.

Issue created at #41

@skamoen skamoen merged commit d29c11c into master Mar 21, 2017
@skamoen skamoen deleted the feature-product_group_actions branch March 21, 2017 13:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants