feat: email field in Person entity

This commit is contained in:
filippo-ferrari 2024-05-24 19:23:05 +02:00
parent 9d127b722f
commit 2cc8862e32
3 changed files with 17 additions and 11 deletions

View file

@ -1,6 +1,7 @@
package com.application.munera.data; package com.application.munera.data;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -26,6 +27,11 @@ public class Person {
@Column(name = "LastName", nullable = false) @Column(name = "LastName", nullable = false)
private String lastName; private String lastName;
@Email
@Size(max = 100)
@Column(name = "email")
private String email;
// @JsonIgnore // @JsonIgnore
@ManyToMany(mappedBy = "creditors") @ManyToMany(mappedBy = "creditors")
private Set<Expense> creditorExpenses; private Set<Expense> creditorExpenses;

View file

@ -182,7 +182,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
: "var(--lumo-disabled-text-color)"); : "var(--lumo-disabled-text-color)");
formLayout.add(name, cost, category, description, isPeriodic, periodUnit, periodInterval, date); formLayout.add(name, cost, category, description, isPeriodic, periodUnit, periodInterval, date);
grid.addColumn(importantRenderer).setHeader("Important").setAutoWidth(true); grid.addColumn(importantRenderer).setHeader("Periodic").setAutoWidth(true);
editorDiv.add(formLayout); editorDiv.add(formLayout);
createButtonLayout(editorLayoutDiv); createButtonLayout(editorLayoutDiv);

View file

@ -1,8 +1,6 @@
package com.application.munera.views.expenses; package com.application.munera.views.expenses;
import com.application.munera.data.Person; import com.application.munera.data.Person;
import com.application.munera.services.CategoryService;
import com.application.munera.services.ExpenseService;
import com.application.munera.services.PersonService; import com.application.munera.services.PersonService;
import com.application.munera.views.MainLayout; import com.application.munera.views.MainLayout;
import com.vaadin.flow.component.UI; import com.vaadin.flow.component.UI;
@ -19,10 +17,14 @@ import com.vaadin.flow.component.notification.Notification.Position;
import com.vaadin.flow.component.notification.NotificationVariant; import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.splitlayout.SplitLayout; import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.BeanValidationBinder; import com.vaadin.flow.data.binder.BeanValidationBinder;
import com.vaadin.flow.data.binder.ValidationException; import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.*; 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 com.vaadin.flow.spring.data.VaadinSpringDataHelpers;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.orm.ObjectOptimisticLockingFailureException; import org.springframework.orm.ObjectOptimisticLockingFailureException;
@ -45,16 +47,12 @@ public class PeopleView extends Div implements BeforeEnterObserver {
private final BeanValidationBinder<Person> binder; private final BeanValidationBinder<Person> binder;
private Person person; private Person person;
private final ExpenseService expenseService;
private final CategoryService categoryService;
private final PersonService personService; private final PersonService personService;
private TextField firstName; private TextField firstName;
private TextField lastName; private TextField lastName;
private EmailField email;
public PeopleView(ExpenseService expenseService, CategoryService categoryService, PersonService personService) { public PeopleView(PersonService personService) {
this.expenseService = expenseService;
this.categoryService = categoryService;
this.personService = personService; this.personService = personService;
addClassNames("people-view"); addClassNames("people-view");
@ -69,6 +67,7 @@ public class PeopleView extends Div implements BeforeEnterObserver {
// Configure Grid // Configure Grid
grid.addColumn(Person::getFirstName).setHeader("First Name").setSortable(true); grid.addColumn(Person::getFirstName).setHeader("First Name").setSortable(true);
grid.addColumn(Person::getLastName).setHeader("Last Name").setSortable(true); grid.addColumn(Person::getLastName).setHeader("Last Name").setSortable(true);
grid.addColumn(Person::getEmail).setHeader("Email").setSortable(true);
grid.getColumns().forEach(col -> col.setAutoWidth(true)); grid.getColumns().forEach(col -> col.setAutoWidth(true));
grid.setItems(query -> personService.list( grid.setItems(query -> personService.list(
@ -150,7 +149,8 @@ public class PeopleView extends Div implements BeforeEnterObserver {
FormLayout formLayout = new FormLayout(); FormLayout formLayout = new FormLayout();
firstName = new TextField("Name"); firstName = new TextField("Name");
lastName = new TextField("Cost"); lastName = new TextField("Cost");
formLayout.add(firstName, lastName); email = new EmailField("Email");
formLayout.add(firstName, lastName, email);
editorDiv.add(formLayout); editorDiv.add(formLayout);
createButtonLayout(editorLayoutDiv); createButtonLayout(editorLayoutDiv);