Skip to content

Commit

Permalink
i hate my life die 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Zusel committed Jun 13, 2024
1 parent 5406c14 commit 5620bdf
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 202 deletions.
5 changes: 5 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.persistence.*;

import java.util.Date;
import java.util.List;

@Entity
@Table(name = "customer")
Expand All @@ -22,8 +23,11 @@ public class Customer {
@Temporal(TemporalType.TIMESTAMP)
Date createdOn;

@OneToMany(mappedBy = "customer")
private List<Order> orders;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@PrePersist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Password> passwords;
private String equipment;
private boolean express;
Expand All @@ -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() {
Expand All @@ -63,4 +65,8 @@ public boolean isExpress() {
public void setExpress(boolean express) {
this.express = express;
}

public List<Password> getPasswords() {
return passwords;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -67,7 +67,7 @@ public PasswordBuilder withName(String name) {
}

public PasswordBuilder withValue(String value) {
password.setValue(value);
password.setPassword(value);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Order> getAllOrders(){
return orderRepository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -21,4 +23,9 @@ public OrderResource(OrderService orderService) {
public Order createOrder(@RequestBody Order order) {
return orderService.createOrder(order);
}

@GetMapping(path = "")
public List<Order> getAllOrders() {
return orderService.getAllOrders();
}
}
Original file line number Diff line number Diff line change
@@ -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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {

Expand All @@ -19,4 +21,8 @@ public OrderService(OrderProcessor orderProcessor) {
public Order createOrder(Order order) {
return orderProcessor.saveOrder(order);
}

public List<Order> getAllOrders() {
return orderProcessor.getAllOrders();
}
}
1 change: 1 addition & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<changeSet id="1715892267251-1" author="itstimetoforget">
<createSequence incrementBy="50" sequenceName="customer_seq" startValue="1"/>
</changeSet>
<changeSet id="1715892267251-2" author="itstimetoforget">
<createSequence incrementBy="50" sequenceName="employee_seq" startValue="1"/>
</changeSet>
<changeSet id="1715892267251-3" author="itstimetoforget">
<createSequence incrementBy="50" sequenceName="order_seq" startValue="1"/>
</changeSet>
<changeSet id="1715892267251-4" author="itstimetoforget">
<createSequence incrementBy="50" sequenceName="password_seq" startValue="1"/>
</changeSet>
<changeSet id="1715892267251-5" author="itstimetoforget">
<changeSet id="1718298499965-1" author="itstimetoforget">
<createTable tableName="customer">
<column name="id" type="BIGINT">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_customer"/>
</column>
<column name="first_name" type="VARCHAR(255)"/>
Expand All @@ -34,9 +22,22 @@
<column name="created_on" type="DATETIME"/>
</createTable>
</changeSet>
<changeSet id="1715892267251-6" author="itstimetoforget">
<changeSet id="1718298499965-2" author="itstimetoforget">
<createTable tableName="customer_order">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_customer_order"/>
</column>
<column name="customer_id" type="BIGINT"/>
<column name="description" type="VARCHAR(255)"/>
<column name="equipment" type="VARCHAR(255)"/>
<column name="express" type="BOOLEAN">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="1718298499965-3" author="itstimetoforget">
<createTable tableName="employee">
<column name="id" type="BIGINT">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_employee"/>
</column>
<column name="short_name" type="VARCHAR(255)"/>
Expand All @@ -49,38 +50,27 @@
</column>
</createTable>
</changeSet>
<changeSet id="1715892267251-7" author="itstimetoforget">
<createTable tableName="order">
<column name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_order"/>
</column>
<column name="customer_id" type="BIGINT"/>
<column name="description" type="VARCHAR(255)"/>
<column name="equipment" type="VARCHAR(255)"/>
<column name="express" type="BOOLEAN">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="1715892267251-8" author="itstimetoforget">
<changeSet id="1718298499965-4" author="itstimetoforget">
<createTable tableName="password">
<column name="id" type="BIGINT">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_password"/>
</column>
<column name="name" type="VARCHAR(255)"/>
<column name="value" type="VARCHAR(255)"/>
<column name="order_id" type="BIGINT"/>
<column name="password" type="VARCHAR(255)"/>
<column name="order_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="1715892267251-9" author="itstimetoforget">
<addForeignKeyConstraint baseColumnNames="customer_id" baseTableName="order"
constraintName="FK_ORDER_ON_CUSTOMER" referencedColumnNames="id"
<changeSet id="1718298499965-5" author="itstimetoforget">
<addForeignKeyConstraint baseColumnNames="customer_id" baseTableName="customer_order"
constraintName="FK_CUSTOMER_ORDER_ON_CUSTOMER" referencedColumnNames="id"
referencedTableName="customer"/>
</changeSet>
<changeSet id="1715892267251-10" author="itstimetoforget">
<changeSet id="1718298499965-6" author="itstimetoforget">
<addForeignKeyConstraint baseColumnNames="order_id" baseTableName="password"
constraintName="FK_PASSWORD_ON_ORDER" referencedColumnNames="id"
referencedTableName="order"/>
referencedTableName="customer_order"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<changeSet id="1718298560443-1" author="itstimetoforget">
<dropNotNullConstraint columnDataType="bigint" columnName="order_id" tableName="password"/>
</changeSet>

</databaseChangeLog>
6 changes: 3 additions & 3 deletions backend/src/main/resources/db/changelog/master.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<include file="db/changelog/2024/05/16-01-changelog.xml"/>
<include file="db/changelog/2024/06/13-01-changelog.xml"/>
<include file="db/changelog/2024/06/13-02-changelog.xml"/>
</databaseChangeLog>
7 changes: 7 additions & 0 deletions backend/src/main/resources/templates/order_summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html xmlns:th="http://www.thymeleaf.org">
<body>
<h3 style="text-align: center; color: green">
<span style="color: black" th:text="'Welcome to ' + ${to} + '!'"></span>
</h3>
</body>
</html>

This file was deleted.

Loading

0 comments on commit 5620bdf

Please sign in to comment.