From 5620bdf29e8531bfe16be06b1376e978c3e5853d Mon Sep 17 00:00:00 2001 From: itstimetoforget Date: Thu, 13 Jun 2024 20:38:45 +0200 Subject: [PATCH] i hate my life die 2 --- backend/build.gradle | 5 + .../backend/rest/entity/Customer.java | 6 +- .../backend/rest/entity/Employee.java | 2 +- .../backend/rest/entity/Order.java | 26 ++-- .../backend/rest/entity/Password.java | 14 +- .../rest/processor/OrderProcessor.java | 8 ++ .../backend/rest/resource/OrderResource.java | 7 + .../backend/rest/resource/PDFResource.java | 17 +++ .../backend/rest/service/OrderService.java | 6 + .../src/main/resources/application.properties | 1 + .../13-01-changelog.xml} | 66 ++++----- .../db/changelog/2024/06/13-02-changelog.xml | 12 ++ .../main/resources/db/changelog/master.xml | 6 +- .../resources/templates/order_summary.html | 7 + .../backend/BackendApplicationTests.java | 13 -- .../de/itstimetoforget/backend/pdfTest.java | 37 +++++ frontend/src/components/cmp_AddCustomer.vue | 6 +- frontend/src/components/cmp_AddOrder.vue | 135 ++---------------- .../components/cmp_GetOrderInformations.vue | 134 +++++++++++++++++ 19 files changed, 306 insertions(+), 202 deletions(-) create mode 100644 backend/src/main/java/de/itstimetoforget/backend/rest/resource/PDFResource.java rename backend/src/main/resources/db/changelog/2024/{05/16-01-changelog.xml => 06/13-01-changelog.xml} (64%) create mode 100644 backend/src/main/resources/db/changelog/2024/06/13-02-changelog.xml create mode 100644 backend/src/main/resources/templates/order_summary.html delete mode 100644 backend/src/test/java/de/itstimetoforget/backend/BackendApplicationTests.java create mode 100644 backend/src/test/java/de/itstimetoforget/backend/pdfTest.java create mode 100644 frontend/src/components/cmp_GetOrderInformations.vue diff --git a/backend/build.gradle b/backend/build.gradle index 8161a5e..435ff52 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -42,10 +42,15 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.liquibase:liquibase-core' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' implementation 'org.hibernate.orm:hibernate-core:6.5.0.Final' + implementation 'com.github.gavlyukovskiy:datasource-proxy-spring-boot-starter:1.9.1' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.thymeleaf:thymeleaf:3.1.2.RELEASE' + implementation 'org.xhtmlrenderer:flying-saucer-pdf:9.5.1' } tasks.named('test') { diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Customer.java b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Customer.java index 923bf20..6a9926d 100644 --- a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Customer.java +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Customer.java @@ -4,6 +4,7 @@ import jakarta.persistence.*; import java.util.Date; +import java.util.List; @Entity @Table(name = "customer") @@ -22,8 +23,11 @@ public class Customer { @Temporal(TemporalType.TIMESTAMP) Date createdOn; + @OneToMany(mappedBy = "customer") + private List orders; + @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @PrePersist diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Employee.java b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Employee.java index de0161d..8971f6c 100644 --- a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Employee.java +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Employee.java @@ -10,7 +10,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class Employee { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String shortName; private String firstName; diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Order.java b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Order.java index e229050..44603da 100644 --- a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Order.java +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Order.java @@ -1,24 +1,26 @@ package de.itstimetoforget.backend.rest.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.persistence.*; import java.util.List; @Entity -@JsonIgnoreProperties(ignoreUnknown = true) -@Table(name = "order") +@Table(name = "customer_order") public class Order { + @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne @JoinColumn(name = "customer_id") - private Customer customerId; + private Customer customer; private String description; - @OneToMany(mappedBy = "order") + @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) + @JsonProperty(required = true) private List passwords; private String equipment; private boolean express; @@ -31,12 +33,12 @@ public Long getId() { return id; } - public Customer getCustomerId() { - return customerId; + public Customer getCustomer() { + return customer; } - public void setCustomerId(Customer customerId) { - this.customerId = customerId; + public void setCustomer(Customer customer) { + this.customer = customer; } public String getDescription() { @@ -63,4 +65,8 @@ public boolean isExpress() { public void setExpress(boolean express) { this.express = express; } + + public List getPasswords() { + return passwords; + } } diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Password.java b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Password.java index 010a985..0b9b1b5 100644 --- a/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Password.java +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/entity/Password.java @@ -7,14 +7,14 @@ public class Password { String name; - String value; + String password; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "order_id") Order order; @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; public String getName() { @@ -25,12 +25,12 @@ public void setName(String name) { this.name = name; } - public String getValue() { - return value; + public String getPassword() { + return password; } - public void setValue(String value) { - this.value = value; + public void setPassword(String password) { + this.password = password; } public Order getOrder() { @@ -67,7 +67,7 @@ public PasswordBuilder withName(String name) { } public PasswordBuilder withValue(String value) { - password.setValue(value); + password.setPassword(value); return this; } diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/processor/OrderProcessor.java b/backend/src/main/java/de/itstimetoforget/backend/rest/processor/OrderProcessor.java index 8e657ba..afbe4a8 100644 --- a/backend/src/main/java/de/itstimetoforget/backend/rest/processor/OrderProcessor.java +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/processor/OrderProcessor.java @@ -5,6 +5,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; + @Component public class OrderProcessor { private final OrderRepository orderRepository; @@ -14,6 +16,12 @@ public OrderProcessor(OrderRepository orderRepository) { } public Order saveOrder(Order order) { + orderRepository.save(order); + order.getPasswords().forEach(password -> password.setOrder(order)); return orderRepository.save(order); } + + public List getAllOrders(){ + return orderRepository.findAll(); + } } diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/resource/OrderResource.java b/backend/src/main/java/de/itstimetoforget/backend/rest/resource/OrderResource.java index 90fe5e8..4a1aac2 100644 --- a/backend/src/main/java/de/itstimetoforget/backend/rest/resource/OrderResource.java +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/resource/OrderResource.java @@ -5,6 +5,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @CrossOrigin(origins = {"*"}, maxAge = 4800) @RequestMapping(path = "/order") @@ -21,4 +23,9 @@ public OrderResource(OrderService orderService) { public Order createOrder(@RequestBody Order order) { return orderService.createOrder(order); } + + @GetMapping(path = "") + public List getAllOrders() { + return orderService.getAllOrders(); + } } diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/resource/PDFResource.java b/backend/src/main/java/de/itstimetoforget/backend/rest/resource/PDFResource.java new file mode 100644 index 0000000..3149e21 --- /dev/null +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/resource/PDFResource.java @@ -0,0 +1,17 @@ +package de.itstimetoforget.backend.rest.resource; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class PDFResource { + + + @RequestMapping("orderSummary") + public String orderSummary(Model model) { + model.addAttribute("to", "asdasd"); + return "order_summary"; + } + +} diff --git a/backend/src/main/java/de/itstimetoforget/backend/rest/service/OrderService.java b/backend/src/main/java/de/itstimetoforget/backend/rest/service/OrderService.java index 65fea6f..60cd152 100644 --- a/backend/src/main/java/de/itstimetoforget/backend/rest/service/OrderService.java +++ b/backend/src/main/java/de/itstimetoforget/backend/rest/service/OrderService.java @@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service public class OrderService { @@ -19,4 +21,8 @@ public OrderService(OrderProcessor orderProcessor) { public Order createOrder(Order order) { return orderProcessor.saveOrder(order); } + + public List getAllOrders() { + return orderProcessor.getAllOrders(); + } } diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 71934ba..8bd9fe1 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -6,3 +6,4 @@ spring.datasource.username=${MARIADB_USERNAME} spring.datasource.password=${MARIADB_PASSWORD} server.port=${SERVER_PORT} server.address=0.0.0.0 +#logging.level.net.ttddyy.dsproxy.listener=debug \ No newline at end of file diff --git a/backend/src/main/resources/db/changelog/2024/05/16-01-changelog.xml b/backend/src/main/resources/db/changelog/2024/06/13-01-changelog.xml similarity index 64% rename from backend/src/main/resources/db/changelog/2024/05/16-01-changelog.xml rename to backend/src/main/resources/db/changelog/2024/06/13-01-changelog.xml index 3645e53..a5abbee 100644 --- a/backend/src/main/resources/db/changelog/2024/05/16-01-changelog.xml +++ b/backend/src/main/resources/db/changelog/2024/06/13-01-changelog.xml @@ -5,21 +5,9 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd" objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS"> - - - - - - - - - - - - - + - + @@ -34,9 +22,22 @@ - + + + + + + + + + + + + + + - + @@ -49,38 +50,27 @@ - - - - - - - - - - - - - - + - + - - + + + + - - + - + + referencedTableName="customer_order"/> \ No newline at end of file diff --git a/backend/src/main/resources/db/changelog/2024/06/13-02-changelog.xml b/backend/src/main/resources/db/changelog/2024/06/13-02-changelog.xml new file mode 100644 index 0000000..3cbfca8 --- /dev/null +++ b/backend/src/main/resources/db/changelog/2024/06/13-02-changelog.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/backend/src/main/resources/db/changelog/master.xml b/backend/src/main/resources/db/changelog/master.xml index 3569617..c5fe287 100644 --- a/backend/src/main/resources/db/changelog/master.xml +++ b/backend/src/main/resources/db/changelog/master.xml @@ -1,9 +1,9 @@ - - + + \ No newline at end of file diff --git a/backend/src/main/resources/templates/order_summary.html b/backend/src/main/resources/templates/order_summary.html new file mode 100644 index 0000000..50012e1 --- /dev/null +++ b/backend/src/main/resources/templates/order_summary.html @@ -0,0 +1,7 @@ + + +

+ +

+ + \ No newline at end of file diff --git a/backend/src/test/java/de/itstimetoforget/backend/BackendApplicationTests.java b/backend/src/test/java/de/itstimetoforget/backend/BackendApplicationTests.java deleted file mode 100644 index 4d0f953..0000000 --- a/backend/src/test/java/de/itstimetoforget/backend/BackendApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.itstimetoforget.backend; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class BackendApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/backend/src/test/java/de/itstimetoforget/backend/pdfTest.java b/backend/src/test/java/de/itstimetoforget/backend/pdfTest.java new file mode 100644 index 0000000..9822073 --- /dev/null +++ b/backend/src/test/java/de/itstimetoforget/backend/pdfTest.java @@ -0,0 +1,37 @@ +package de.itstimetoforget.backend; + +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.Context; +import org.thymeleaf.templatemode.TemplateMode; +import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; +import org.xhtmlrenderer.pdf.ITextRenderer; + +import java.io.*; + +public class pdfTest { + + public static void main(String[] args) throws IOException { + ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); + templateResolver.setPrefix("templates/"); + templateResolver.setSuffix(".html"); + templateResolver.setTemplateMode("HTML5"); + + TemplateEngine templateEngine = new TemplateEngine(); + templateEngine.setTemplateResolver(templateResolver); + + Context context = new Context(); + context.setVariable("to", "Hello World"); + + String html =templateEngine.process("thymeleaf_template", context); + + String outputFolder = "thymeleaf.pdf"; + OutputStream outputStream = new FileOutputStream(outputFolder); + + ITextRenderer renderer = new ITextRenderer(); + renderer.setDocumentFromString(html); + renderer.layout(); + renderer.createPDF(outputStream); + + outputStream.close(); + } +} diff --git a/frontend/src/components/cmp_AddCustomer.vue b/frontend/src/components/cmp_AddCustomer.vue index d323524..bd8410a 100644 --- a/frontend/src/components/cmp_AddCustomer.vue +++ b/frontend/src/components/cmp_AddCustomer.vue @@ -124,8 +124,10 @@ export default { "streetNumber": this.streetNumber } RESTUtils.sendPostRequest("/customer", customer) - .then( - this.$root.$refs.vtoast.show({message: 'Customer erstellt'}) + .then( newCustomer => { + this.$root.$refs.vtoast.show({message: 'Customer erstellt'}) + this.$emit("customerCreated", newCustomer.data) + } ) .catch(error => { console.log(error) diff --git a/frontend/src/components/cmp_AddOrder.vue b/frontend/src/components/cmp_AddOrder.vue index 84edde7..e5e8eb1 100644 --- a/frontend/src/components/cmp_AddOrder.vue +++ b/frontend/src/components/cmp_AddOrder.vue @@ -3,9 +3,9 @@ - - + {{ "id:" + customer.id + " | " + "vorname: " + customer.firstName + " | " + "nachname: " + customer.lastName + " | " + "postleitzahl: " + customer.postcode + " | " + "stadt: " + customer.city + " | " + "handynummer: " + customer.mobileNumber + " | " + "festnetznummer: " + customer.landlineNumber + " | " + "email: " + customer.email + " | " + "straße: " + customer.street + " | " + "hausnummer: " + customer.streetNumber }} @@ -14,98 +14,10 @@ - - - - - - - Gewählter Kunde: -
- {{ "vorname: " + choosedCustomer.firstName }} -
- {{ "nachname: " + choosedCustomer.lastName }} -
- {{ "postleitzahl: " + choosedCustomer.postcode }} -
- {{ "stadt: " + choosedCustomer.city }} -
- {{ "handynummer: " + choosedCustomer.mobileNumber }} -
- {{ "festnetznummer: " + choosedCustomer.landlineNumber }} -
- {{ "email: " + choosedCustomer.email }} -
- {{ "straße: " + choosedCustomer.street }} -
- {{ "hausnummer: " + choosedCustomer.streetNumber }} -
- - neuen Kunden wählen - -
-
- - - - - -
- - - - - - Passwörter: - - - - - - - - - - - - - - - - - - - Passwort Hinzufügen - - - - - - - - - - - - - - - - Auftrag erstellen - - +
+