From d3e0490eee3d7e8c0a7b31b73b7d9673374bae8f Mon Sep 17 00:00:00 2001 From: effe Date: Sat, 14 Sep 2024 11:20:23 -0400 Subject: [PATCH] feat: support for userId in categories --- .../com/application/munera/services/CategoryService.java | 5 +++-- .../munera/views/categories/CategoriesView.java | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/application/munera/services/CategoryService.java b/src/main/java/com/application/munera/services/CategoryService.java index 5f91c1c..5cf8c0b 100644 --- a/src/main/java/com/application/munera/services/CategoryService.java +++ b/src/main/java/com/application/munera/services/CategoryService.java @@ -26,8 +26,9 @@ public class CategoryService { return categoryRepository.findByUserId(userId); } - public void update(Category category) { - categoryRepository.save(category); + public void update(Category category, Long userId) { + category.setUserId(userId); + categoryRepository.save(category ); } public void delete(Category category) { diff --git a/src/main/java/com/application/munera/views/categories/CategoriesView.java b/src/main/java/com/application/munera/views/categories/CategoriesView.java index da97bea..35f7f51 100644 --- a/src/main/java/com/application/munera/views/categories/CategoriesView.java +++ b/src/main/java/com/application/munera/views/categories/CategoriesView.java @@ -53,10 +53,12 @@ public class CategoriesView extends Div implements BeforeEnterObserver { private final CategoryService categoryService; private final UserService userService; private TextField name; + private TextArea description; public CategoriesView(CategoryService categoryService, UserService userService) { this.categoryService = categoryService; this.userService = userService; + final var userId = this.userService.getLoggedInUser().getId(); addClassNames("expenses-view"); // Create UI @@ -70,7 +72,7 @@ public class CategoriesView extends Div implements BeforeEnterObserver { grid.addColumn(Category::getDescription).setHeader("Description").setSortable(true); grid.getColumns().forEach(col -> col.setAutoWidth(true)); - grid.setItems(this.categoryService.findAllByUserId(this.userService.getLoggedInUser().getId())); + grid.setItems(this.categoryService.findAllByUserId(userId)); grid.addThemeVariants(GridVariant.LUMO_NO_BORDER); // when a row is selected or deselected, populate form @@ -103,7 +105,7 @@ public class CategoriesView extends Div implements BeforeEnterObserver { this.category = new Category(); } binder.writeBean(this.category); - categoryService.update(this.category); + categoryService.update(this.category, userId); clearForm(); refreshGrid(); Notification.show("Data updated"); @@ -155,7 +157,6 @@ public class CategoriesView extends Div implements BeforeEnterObserver { } private void createEditorLayout(SplitLayout splitLayout) { - TextArea description; Div editorLayoutDiv = new Div(); editorLayoutDiv.setClassName("editor-layout");