fix: deleting category when not possible

This commit is contained in:
filippo-ferrari 2024-09-15 15:08:50 +02:00
parent e916e6edff
commit 31d2f27728

View file

@ -25,9 +25,8 @@ import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.data.VaadinSpringDataHelpers;
import jakarta.annotation.security.PermitAll;
import org.springframework.data.domain.PageRequest;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
import java.util.Optional;
@ -133,6 +132,11 @@ public class CategoriesView extends Div implements BeforeEnterObserver {
"Error updating the data. Somebody else has updated the record while you were making changes.");
n.setPosition(Notification.Position.MIDDLE);
n.addThemeVariants(NotificationVariant.LUMO_ERROR);
} catch (DataIntegrityViolationException ex) {
Notification n = Notification.show(
"Cannot delete this category as it is associated with existing expenses.");
n.setPosition(Notification.Position.MIDDLE);
n.addThemeVariants(NotificationVariant.LUMO_ERROR);
}
});
}