From 28cfe2afed4e551671c5c51c3a1abcb75bd634f4 Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Sat, 18 May 2024 17:15:31 +0200 Subject: [PATCH] inital commit --- pom.xml | 8 ++- .../com/application/munera/data/Category.java | 4 ++ .../com/application/munera/data/Expense.java | 44 ++++++++++++ .../application/munera/data/PeriodUnit.java | 4 ++ .../application/munera/data/SamplePerson.java | 69 ------------------- .../munera/data/SamplePersonRepository.java | 4 +- .../munera/services/SamplePersonService.java | 10 +-- .../munera/views/expenses/ExpensesView.java | 18 ++--- src/main/resources/application.properties | 6 +- 9 files changed, 78 insertions(+), 89 deletions(-) create mode 100644 src/main/java/com/application/munera/data/Category.java create mode 100644 src/main/java/com/application/munera/data/Expense.java create mode 100644 src/main/java/com/application/munera/data/PeriodUnit.java delete mode 100644 src/main/java/com/application/munera/data/SamplePerson.java diff --git a/pom.xml b/pom.xml index b0c9858..7ebaa04 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,13 @@ org.springframework.boot spring-boot-starter-data-jpa - + + + org.projectlombok + lombok + 1.18.32 + provided + org.springframework.boot spring-boot-starter-validation diff --git a/src/main/java/com/application/munera/data/Category.java b/src/main/java/com/application/munera/data/Category.java new file mode 100644 index 0000000..0bef2b0 --- /dev/null +++ b/src/main/java/com/application/munera/data/Category.java @@ -0,0 +1,4 @@ +package com.application.munera.data; + +public class Category { +} diff --git a/src/main/java/com/application/munera/data/Expense.java b/src/main/java/com/application/munera/data/Expense.java new file mode 100644 index 0000000..ffd19bf --- /dev/null +++ b/src/main/java/com/application/munera/data/Expense.java @@ -0,0 +1,44 @@ +package com.application.munera.data; + +import jakarta.persistence.*; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; + +import java.math.BigDecimal; +import java.time.LocalDate; + +@Entity +@Getter +@Setter +public class Expense { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "Id", unique = true, nullable = false) + private Long id; + + @Size(max = 100) + @Column(name = "Name", nullable = false) + private String name; + + @ManyToOne + @JoinColumn(name = "CategoryId", nullable = false) + private Category category; + + @Column(name = "Cost", nullable = false) + private BigDecimal cost; + + @Column(name = "Description") + private String description; + + @Column(name = "PeriodicExpense", nullable = false) + private Boolean isPeriodic; + + @Column(name = "PeriodUnit") + private PeriodUnit periodUnit; + + @Column(name = "PeriodInterval") + private Integer periodInterval; + } diff --git a/src/main/java/com/application/munera/data/PeriodUnit.java b/src/main/java/com/application/munera/data/PeriodUnit.java new file mode 100644 index 0000000..2c82d6c --- /dev/null +++ b/src/main/java/com/application/munera/data/PeriodUnit.java @@ -0,0 +1,4 @@ +package com.application.munera.data; + +public class PeriodUnit { +} diff --git a/src/main/java/com/application/munera/data/SamplePerson.java b/src/main/java/com/application/munera/data/SamplePerson.java deleted file mode 100644 index 6e57a5c..0000000 --- a/src/main/java/com/application/munera/data/SamplePerson.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.application.munera.data; - -import jakarta.persistence.Entity; -import jakarta.validation.constraints.Email; -import java.time.LocalDate; - -@Entity -public class SamplePerson extends AbstractEntity { - - private String firstName; - private String lastName; - @Email - private String email; - private String phone; - private LocalDate dateOfBirth; - private String occupation; - private String role; - private boolean important; - - public String getFirstName() { - return firstName; - } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - public String getLastName() { - return lastName; - } - public void setLastName(String lastName) { - this.lastName = lastName; - } - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - public String getPhone() { - return phone; - } - public void setPhone(String phone) { - this.phone = phone; - } - public LocalDate getDateOfBirth() { - return dateOfBirth; - } - public void setDateOfBirth(LocalDate dateOfBirth) { - this.dateOfBirth = dateOfBirth; - } - public String getOccupation() { - return occupation; - } - public void setOccupation(String occupation) { - this.occupation = occupation; - } - public String getRole() { - return role; - } - public void setRole(String role) { - this.role = role; - } - public boolean isImportant() { - return important; - } - public void setImportant(boolean important) { - this.important = important; - } - -} diff --git a/src/main/java/com/application/munera/data/SamplePersonRepository.java b/src/main/java/com/application/munera/data/SamplePersonRepository.java index 978789d..be33666 100644 --- a/src/main/java/com/application/munera/data/SamplePersonRepository.java +++ b/src/main/java/com/application/munera/data/SamplePersonRepository.java @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; public interface SamplePersonRepository extends - JpaRepository, - JpaSpecificationExecutor { + JpaRepository, + JpaSpecificationExecutor { } diff --git a/src/main/java/com/application/munera/services/SamplePersonService.java b/src/main/java/com/application/munera/services/SamplePersonService.java index 42912ae..7fb62c3 100644 --- a/src/main/java/com/application/munera/services/SamplePersonService.java +++ b/src/main/java/com/application/munera/services/SamplePersonService.java @@ -1,6 +1,6 @@ package com.application.munera.services; -import com.application.munera.data.SamplePerson; +import com.application.munera.data.Expense; import com.application.munera.data.SamplePersonRepository; import java.util.Optional; import org.springframework.data.domain.Page; @@ -17,11 +17,11 @@ public class SamplePersonService { this.repository = repository; } - public Optional get(Long id) { + public Optional get(Long id) { return repository.findById(id); } - public SamplePerson update(SamplePerson entity) { + public Expense update(Expense entity) { return repository.save(entity); } @@ -29,11 +29,11 @@ public class SamplePersonService { repository.deleteById(id); } - public Page list(Pageable pageable) { + public Page list(Pageable pageable) { return repository.findAll(pageable); } - public Page list(Pageable pageable, Specification filter) { + public Page list(Pageable pageable, Specification filter) { return repository.findAll(filter, pageable); } 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 80c0060..9498567 100644 --- a/src/main/java/com/application/munera/views/expenses/ExpensesView.java +++ b/src/main/java/com/application/munera/views/expenses/ExpensesView.java @@ -1,6 +1,6 @@ package com.application.munera.views.expenses; -import com.application.munera.data.SamplePerson; +import com.application.munera.data.Expense; import com.application.munera.services.SamplePersonService; import com.application.munera.views.MainLayout; import com.vaadin.flow.component.UI; @@ -42,7 +42,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { private final String SAMPLEPERSON_ID = "samplePersonID"; private final String SAMPLEPERSON_EDIT_ROUTE_TEMPLATE = "/%s/edit"; - private final Grid grid = new Grid<>(SamplePerson.class, false); + private final Grid grid = new Grid<>(Expense.class, false); private TextField firstName; private TextField lastName; @@ -56,9 +56,9 @@ public class ExpensesView extends Div implements BeforeEnterObserver { private final Button cancel = new Button("Cancel"); private final Button save = new Button("Save"); - private final BeanValidationBinder binder; + private final BeanValidationBinder binder; - private SamplePerson samplePerson; + private Expense samplePerson; private final SamplePersonService samplePersonService; @@ -82,7 +82,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { grid.addColumn("dateOfBirth").setAutoWidth(true); grid.addColumn("occupation").setAutoWidth(true); grid.addColumn("role").setAutoWidth(true); - LitRenderer importantRenderer = LitRenderer.of( + LitRenderer importantRenderer = LitRenderer.of( "") .withProperty("icon", important -> important.isImportant() ? "check" : "minus").withProperty("color", important -> important.isImportant() @@ -107,7 +107,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { }); // Configure Form - binder = new BeanValidationBinder<>(SamplePerson.class); + binder = new BeanValidationBinder<>(Expense.class); // Bind fields. This is where you'd define e.g. validation rules @@ -121,7 +121,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { save.addClickListener(e -> { try { if (this.samplePerson == null) { - this.samplePerson = new SamplePerson(); + this.samplePerson = new Expense(); } binder.writeBean(this.samplePerson); samplePersonService.update(this.samplePerson); @@ -144,7 +144,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { public void beforeEnter(BeforeEnterEvent event) { Optional samplePersonId = event.getRouteParameters().get(SAMPLEPERSON_ID).map(Long::parseLong); if (samplePersonId.isPresent()) { - Optional samplePersonFromBackend = samplePersonService.get(samplePersonId.get()); + Optional samplePersonFromBackend = samplePersonService.get(samplePersonId.get()); if (samplePersonFromBackend.isPresent()) { populateForm(samplePersonFromBackend.get()); } else { @@ -209,7 +209,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { populateForm(null); } - private void populateForm(SamplePerson value) { + private void populateForm(Expense value) { this.samplePerson = value; binder.readBean(this.samplePerson); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b3fe897..5ffaaea 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,9 +5,9 @@ spring.mustache.check-template-location = false # Launch the default browser when starting the application in development mode vaadin.launch-browser=true # PostgreSQL configuration. -spring.datasource.url = jdbc:postgresql://localhost:5432/vaadinstart -spring.datasource.username = vaadinstart -spring.datasource.password = vaadinstart +spring.datasource.url = jdbc:postgresql://localhost:5432/munera +spring.datasource.username = postgres +spring.datasource.password = spring.jpa.hibernate.ddl-auto = update # To improve the performance during development. # For more information https://vaadin.com/docs/latest/integrations/spring/configuration#special-configuration-parameters