inital commit
This commit is contained in:
parent
4b503323df
commit
28cfe2afed
9 changed files with 78 additions and 89 deletions
8
pom.xml
8
pom.xml
|
@ -68,7 +68,13 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.32</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
|
4
src/main/java/com/application/munera/data/Category.java
Normal file
4
src/main/java/com/application/munera/data/Category.java
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
package com.application.munera.data;
|
||||||
|
|
||||||
|
public class Category {
|
||||||
|
}
|
44
src/main/java/com/application/munera/data/Expense.java
Normal file
44
src/main/java/com/application/munera/data/Expense.java
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.application.munera.data;
|
||||||
|
|
||||||
|
public class PeriodUnit {
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
public interface SamplePersonRepository
|
public interface SamplePersonRepository
|
||||||
extends
|
extends
|
||||||
JpaRepository<SamplePerson, Long>,
|
JpaRepository<Expense, Long>,
|
||||||
JpaSpecificationExecutor<SamplePerson> {
|
JpaSpecificationExecutor<Expense> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.application.munera.services;
|
package com.application.munera.services;
|
||||||
|
|
||||||
import com.application.munera.data.SamplePerson;
|
import com.application.munera.data.Expense;
|
||||||
import com.application.munera.data.SamplePersonRepository;
|
import com.application.munera.data.SamplePersonRepository;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
@ -17,11 +17,11 @@ public class SamplePersonService {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<SamplePerson> get(Long id) {
|
public Optional<Expense> get(Long id) {
|
||||||
return repository.findById(id);
|
return repository.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SamplePerson update(SamplePerson entity) {
|
public Expense update(Expense entity) {
|
||||||
return repository.save(entity);
|
return repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@ public class SamplePersonService {
|
||||||
repository.deleteById(id);
|
repository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<SamplePerson> list(Pageable pageable) {
|
public Page<Expense> list(Pageable pageable) {
|
||||||
return repository.findAll(pageable);
|
return repository.findAll(pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<SamplePerson> list(Pageable pageable, Specification<SamplePerson> filter) {
|
public Page<Expense> list(Pageable pageable, Specification<Expense> filter) {
|
||||||
return repository.findAll(filter, pageable);
|
return repository.findAll(filter, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.application.munera.views.expenses;
|
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.services.SamplePersonService;
|
||||||
import com.application.munera.views.MainLayout;
|
import com.application.munera.views.MainLayout;
|
||||||
import com.vaadin.flow.component.UI;
|
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_ID = "samplePersonID";
|
||||||
private final String SAMPLEPERSON_EDIT_ROUTE_TEMPLATE = "/%s/edit";
|
private final String SAMPLEPERSON_EDIT_ROUTE_TEMPLATE = "/%s/edit";
|
||||||
|
|
||||||
private final Grid<SamplePerson> grid = new Grid<>(SamplePerson.class, false);
|
private final Grid<Expense> grid = new Grid<>(Expense.class, false);
|
||||||
|
|
||||||
private TextField firstName;
|
private TextField firstName;
|
||||||
private TextField lastName;
|
private TextField lastName;
|
||||||
|
@ -56,9 +56,9 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
||||||
private final Button cancel = new Button("Cancel");
|
private final Button cancel = new Button("Cancel");
|
||||||
private final Button save = new Button("Save");
|
private final Button save = new Button("Save");
|
||||||
|
|
||||||
private final BeanValidationBinder<SamplePerson> binder;
|
private final BeanValidationBinder<Expense> binder;
|
||||||
|
|
||||||
private SamplePerson samplePerson;
|
private Expense samplePerson;
|
||||||
|
|
||||||
private final SamplePersonService samplePersonService;
|
private final SamplePersonService samplePersonService;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
||||||
grid.addColumn("dateOfBirth").setAutoWidth(true);
|
grid.addColumn("dateOfBirth").setAutoWidth(true);
|
||||||
grid.addColumn("occupation").setAutoWidth(true);
|
grid.addColumn("occupation").setAutoWidth(true);
|
||||||
grid.addColumn("role").setAutoWidth(true);
|
grid.addColumn("role").setAutoWidth(true);
|
||||||
LitRenderer<SamplePerson> importantRenderer = LitRenderer.<SamplePerson>of(
|
LitRenderer<Expense> importantRenderer = LitRenderer.<Expense>of(
|
||||||
"<vaadin-icon icon='vaadin:${item.icon}' style='width: var(--lumo-icon-size-s); height: var(--lumo-icon-size-s); color: ${item.color};'></vaadin-icon>")
|
"<vaadin-icon icon='vaadin:${item.icon}' style='width: var(--lumo-icon-size-s); height: var(--lumo-icon-size-s); color: ${item.color};'></vaadin-icon>")
|
||||||
.withProperty("icon", important -> important.isImportant() ? "check" : "minus").withProperty("color",
|
.withProperty("icon", important -> important.isImportant() ? "check" : "minus").withProperty("color",
|
||||||
important -> important.isImportant()
|
important -> important.isImportant()
|
||||||
|
@ -107,7 +107,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Configure Form
|
// Configure Form
|
||||||
binder = new BeanValidationBinder<>(SamplePerson.class);
|
binder = new BeanValidationBinder<>(Expense.class);
|
||||||
|
|
||||||
// Bind fields. This is where you'd define e.g. validation rules
|
// 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 -> {
|
save.addClickListener(e -> {
|
||||||
try {
|
try {
|
||||||
if (this.samplePerson == null) {
|
if (this.samplePerson == null) {
|
||||||
this.samplePerson = new SamplePerson();
|
this.samplePerson = new Expense();
|
||||||
}
|
}
|
||||||
binder.writeBean(this.samplePerson);
|
binder.writeBean(this.samplePerson);
|
||||||
samplePersonService.update(this.samplePerson);
|
samplePersonService.update(this.samplePerson);
|
||||||
|
@ -144,7 +144,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
||||||
public void beforeEnter(BeforeEnterEvent event) {
|
public void beforeEnter(BeforeEnterEvent event) {
|
||||||
Optional<Long> samplePersonId = event.getRouteParameters().get(SAMPLEPERSON_ID).map(Long::parseLong);
|
Optional<Long> samplePersonId = event.getRouteParameters().get(SAMPLEPERSON_ID).map(Long::parseLong);
|
||||||
if (samplePersonId.isPresent()) {
|
if (samplePersonId.isPresent()) {
|
||||||
Optional<SamplePerson> samplePersonFromBackend = samplePersonService.get(samplePersonId.get());
|
Optional<Expense> samplePersonFromBackend = samplePersonService.get(samplePersonId.get());
|
||||||
if (samplePersonFromBackend.isPresent()) {
|
if (samplePersonFromBackend.isPresent()) {
|
||||||
populateForm(samplePersonFromBackend.get());
|
populateForm(samplePersonFromBackend.get());
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,7 +209,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
||||||
populateForm(null);
|
populateForm(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateForm(SamplePerson value) {
|
private void populateForm(Expense value) {
|
||||||
this.samplePerson = value;
|
this.samplePerson = value;
|
||||||
binder.readBean(this.samplePerson);
|
binder.readBean(this.samplePerson);
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ spring.mustache.check-template-location = false
|
||||||
# Launch the default browser when starting the application in development mode
|
# Launch the default browser when starting the application in development mode
|
||||||
vaadin.launch-browser=true
|
vaadin.launch-browser=true
|
||||||
# PostgreSQL configuration.
|
# PostgreSQL configuration.
|
||||||
spring.datasource.url = jdbc:postgresql://localhost:5432/vaadinstart
|
spring.datasource.url = jdbc:postgresql://localhost:5432/munera
|
||||||
spring.datasource.username = vaadinstart
|
spring.datasource.username = postgres
|
||||||
spring.datasource.password = vaadinstart
|
spring.datasource.password =
|
||||||
spring.jpa.hibernate.ddl-auto = update
|
spring.jpa.hibernate.ddl-auto = update
|
||||||
# To improve the performance during development.
|
# To improve the performance during development.
|
||||||
# For more information https://vaadin.com/docs/latest/integrations/spring/configuration#special-configuration-parameters
|
# For more information https://vaadin.com/docs/latest/integrations/spring/configuration#special-configuration-parameters
|
||||||
|
|
Loading…
Reference in a new issue