From 8369ed64397a59468bb7f4683f1a946729d2c2e5 Mon Sep 17 00:00:00 2001 From: Filippo Ferrari Date: Sat, 15 Jun 2024 22:21:53 +0200 Subject: [PATCH] feat: events --- frontend/index.html | 23 +++++++++++++++++++ .../com/application/munera/data/Event.java | 9 ++++++++ .../com/application/munera/data/Person.java | 3 +++ .../munera/views/expenses/EventsView.java | 13 +++++++++-- .../munera/views/expenses/ExpensesView.java | 8 +++---- src/main/resources/application.properties | 2 +- 6 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 frontend/index.html diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..d36e593 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + +
+ + diff --git a/src/main/java/com/application/munera/data/Event.java b/src/main/java/com/application/munera/data/Event.java index d0ea1b7..ccbe590 100644 --- a/src/main/java/com/application/munera/data/Event.java +++ b/src/main/java/com/application/munera/data/Event.java @@ -5,6 +5,8 @@ import jakarta.validation.constraints.Size; import lombok.Getter; import lombok.Setter; +import java.util.Set; + @Entity @Getter @Setter @@ -22,4 +24,11 @@ public class Event { @Size(max = 100) @Column(name = "Description") private String description; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable( + name = "Event_participants", + joinColumns = @JoinColumn(name = "event_id"), + inverseJoinColumns = @JoinColumn(name = "participant_id")) + private Set participants; } diff --git a/src/main/java/com/application/munera/data/Person.java b/src/main/java/com/application/munera/data/Person.java index 2ffae57..8cbb7e3 100644 --- a/src/main/java/com/application/munera/data/Person.java +++ b/src/main/java/com/application/munera/data/Person.java @@ -44,4 +44,7 @@ public class Person { @ManyToMany(mappedBy = "debtors") private Set debtorExpenses; + + @ManyToMany(mappedBy = "participants") + private Set events; } diff --git a/src/main/java/com/application/munera/views/expenses/EventsView.java b/src/main/java/com/application/munera/views/expenses/EventsView.java index cf69ace..ceba5d5 100644 --- a/src/main/java/com/application/munera/views/expenses/EventsView.java +++ b/src/main/java/com/application/munera/views/expenses/EventsView.java @@ -1,11 +1,14 @@ package com.application.munera.views.expenses; import com.application.munera.data.Event; +import com.application.munera.data.Person; import com.application.munera.services.EventService; +import com.application.munera.services.PersonService; import com.application.munera.views.MainLayout; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.ButtonVariant; +import com.vaadin.flow.component.combobox.MultiSelectComboBox; import com.vaadin.flow.component.dependency.Uses; import com.vaadin.flow.component.formlayout.FormLayout; import com.vaadin.flow.component.grid.Grid; @@ -48,11 +51,14 @@ public class EventsView extends Div implements BeforeEnterObserver { private Event event; private final EventService eventService; + private final PersonService personService; private TextField name; private TextArea description; + private MultiSelectComboBox participants; - public EventsView(EventService eventService) { + public EventsView(EventService eventService, PersonService personService) { this.eventService = eventService; + this.personService = personService; addClassNames("events-view"); // Create UI @@ -162,7 +168,10 @@ public class EventsView extends Div implements BeforeEnterObserver { FormLayout formLayout = new FormLayout(); name = new TextField("Name"); description = new TextArea("Description"); - formLayout.add(name, description); + participants = new MultiSelectComboBox<>("Participants"); + participants.setItems(personService.findAll()); + participants.setItemLabelGenerator(Person::getFirstName); + formLayout.add(name, description, participants); editorDiv.add(formLayout); createButtonLayout(editorLayoutDiv); diff --git a/src/main/java/com/application/munera/views/expenses/ExpensesView.java b/src/main/java/com/application/munera/views/expenses/ExpensesView.java index 1b23f51..95dcae1 100644 --- a/src/main/java/com/application/munera/views/expenses/ExpensesView.java +++ b/src/main/java/com/application/munera/views/expenses/ExpensesView.java @@ -91,7 +91,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { grid.addColumn(Expense::getPeriodInterval).setHeader("Period Interval").setSortable(true); grid.addColumn(Expense::getPeriodUnit).setHeader("Period Unit").setSortable(true); grid.addColumn(Expense::getDate).setHeader("Date").setSortable(true).setSortProperty("date"); - grid.addColumn(expenseEvent -> expenseEvent.getEvent().getName()).setHeader("Event").setSortable(true); + // grid.addColumn(expenseEvent -> expenseEvent.getEvent().getName()).setHeader("Event").setSortable(true); grid.getColumns().forEach(col -> col.setAutoWidth(true)); grid.setItems(query -> expenseService.list( @@ -216,12 +216,12 @@ public class ExpensesView extends Div implements BeforeEnterObserver { creditors = new MultiSelectComboBox<>("Creditors"); creditors.setItems(personService.findAll()); creditors.setItemLabelGenerator(Person::getFirstName); - debtors = new MultiSelectComboBox<>("Debtors"); - debtors.setItems(personService.findAll()); - debtors.setItemLabelGenerator(Person::getFirstName); event = new ComboBox<>("Event"); event.setItems(eventService.findAll()); event.setItemLabelGenerator(Event::getName); + debtors = new MultiSelectComboBox<>("Debtors"); + debtors.setItems(personService.findAll()); + debtors.setItemLabelGenerator(Person::getFirstName); date = new DatePicker("Date"); LitRenderer isPeriodicRenderer = LitRenderer.of( "") diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7c15721..06fd252 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,7 +3,7 @@ logging.level.org.atmosphere = warn spring.mustache.check-template-location = false # Launch the default browser when starting the application in development mode -vaadin.launch-browser=true +#vaadin.launch-browser=true # PostgreSQL configuration. spring.datasource.url = jdbc:postgresql://localhost:5432/munera_vaadin spring.datasource.username = postgres