feat: support for userId in categories
This commit is contained in:
parent
8d0823a206
commit
d3e0490eee
2 changed files with 7 additions and 5 deletions
|
@ -26,7 +26,8 @@ public class CategoryService {
|
|||
return categoryRepository.findByUserId(userId);
|
||||
}
|
||||
|
||||
public void update(Category category) {
|
||||
public void update(Category category, Long userId) {
|
||||
category.setUserId(userId);
|
||||
categoryRepository.save(category );
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue