Skip to content

Commit

Permalink
Merge pull request #5 from FoodCoopV3/main
Browse files Browse the repository at this point in the history
Foodcoop Backend
  • Loading branch information
orat authored May 24, 2024
2 parents 9c7a6f2 + c31c971 commit efa0677
Show file tree
Hide file tree
Showing 159 changed files with 7,713 additions and 2,198 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ syntax: glob
/*/target/*
/*/*.iml
/*.iml
/*/*/*/*/application.properties
.classpath
.project
org.*
application.properties
17 changes: 13 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
FROM adoptopenjdk/openjdk11:alpine-jre
ARG JAR_FILE=/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
FROM maven:3.6.3-jdk-11-slim AS build
WORKDIR /home/app

# Kopiere das gesamte Projektverzeichnis
COPY . .

# Baue das Projekt mit Maven Wrapper
RUN mvn clean install -DskipTests

# Verwende das offizielle OpenJDK Image, um die Jar auszuführen
FROM openjdk:11-jre-slim
COPY --from=build /home/app/plugins/target/*.jar /usr/local/lib/app.jar
ENTRYPOINT ["java","-jar","/usr/local/lib/app.jar"]
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,82 @@
Food-coop warehouse management software.


## Instructions for local setup

If you want to setup the Backend for your localhost you need to create an application.properties in plugins/src/main/resources and you need a local Keycloak & MariaDB instance.<br>
In the application.properties you have to define your MariaDB Datasource and Keycloak instance.<br>
This is needed because for production the application.properties is created & written to via GitHub Actions (see [GitHub workflows](https://github.com/FoodCoopV3/foodcoops-backend/blob/main/.github/workflows/ssh_deployment.yml))<br>
The reason for this is, that the private Data of the official Keycloak/MariaDB instances like passwords, secrets etc. is not exposed in the propertie file and is being filled in when build by GitHub Actions.<br>
An example applications.properties could look like this:
```java
spring.datasource.url=jdbc:mariadb://{ip_of_db}:3306/{dbname}
spring.datasource.username={username}
spring.datasource.password={password}
spring.datasource.driver−class−name=org.mariadb.jdbc.Driver
spring.jpa.hibernate.ddl−auto=none
spring.jpa.generate−ddl=true
spring.datasource.initialization−mode=always
spring.jpa.show−sql=true
server.port=8081

keycloak.realm={Realm Name}
keycloak.auth−server−url=http://{keycloak_ip}:{port}/
keycloak.ssl−required=none
keycloak.credentials.secret={Client Secrent}
keycloak.use−resource−role−mappings = true
keycloak.resource={Client Name}

spring.mail.host=smtp.ionos.de
spring.mail.port=587
spring.mail.username=foodcoop@orat.de
spring.mail.password={password}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
```
(@Oliver got the mail password, Keycloak + db have to be setup before)

If you want to setup Keycloak etc you can use the following docker-compose.yml

```
version: '1'
services:
frontend:
image: frontend
restart: always
volumes:
- nginx_cfg:/etc/nginx/conf.d
ports:
- 80:80
keycloak:
image: quay.io/keycloak/keycloak:19.0.1
restart: always
ports:
- 8089:8080
volumes:
- /root/foodcoop/keycloak_data/dataTest:/opt/jboss/keycloak/standalone/data/
environment:
- KEYCLOAK_ADMIN={admin username}
- KC_HTTP_ENABLED=true
- KEYCLOAK_ADMIN_PASSWORD={admin passwort}
- DB_VENDOR=mariadb
- KC_DB=mariadb
- KC_DB_USERNAME={db username}
- KC_DB_PASSWORD={db passwort}
- KC_DB_URL=jdbc:mariadb://{ip}:3306/{dbname}?allowPublicKeyRetrieval=true&useSSL=FALSE
command:
- start-dev
app:
image: foodcoops-backend
restart: always
ports:
- "8080:8080"
volumes:
nginx_cfg:
```
Change Keycloak http enabled to false asap. (after you added https support.)
MariaDB is NOT included, checkout the paper for the reason & how to set it up.

After setup, swagger is running at: http://{server ip}:8080/swagger-ui/
## Installing, starting and stopping the application

Food-coop warehouse comes prepackaged with its maven wrapper. Go to the project directory.<br>
Expand Down
42 changes: 42 additions & 0 deletions abstraction/bin/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>warehouse</artifactId>
<groupId>de.dhbw.foodcoop</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>abstraction</artifactId>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<debug>true</debug>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
49 changes: 49 additions & 0 deletions abstraction/bin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>warehouse</artifactId>
<groupId>de.dhbw.foodcoop</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>abstraction</artifactId>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<debug>true</debug>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
</dependencies>


</project>
18 changes: 18 additions & 0 deletions abstraction/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@
<artifactId>spring-context</artifactId>
<version>5.3.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
</dependency>

<!-- Jackson Annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>

<!-- Jackson Databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.dhbw.foodcoop.warehouse.adapters.representations;

public class BestandBuyRepresentation {

private String id;
private ProduktRepresentation bestand;
private double amount;
public BestandBuyRepresentation(String id, ProduktRepresentation bestand, double amount) {
super();
this.id = id;
this.bestand = bestand;
this.amount = amount;
}

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public ProduktRepresentation getBestand() {
return bestand;
}
public void setBestand(ProduktRepresentation bestand) {
this.bestand = bestand;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.dhbw.foodcoop.warehouse.adapters.representations;

import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import de.dhbw.foodcoop.warehouse.domain.entities.BrotBestand;
import de.dhbw.foodcoop.warehouse.domain.entities.FrischBestand;
import de.dhbw.foodcoop.warehouse.domain.entities.Produkt;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = FrischBestandRepresentation.class, name = "frisch"),
@JsonSubTypes.Type(value = BrotBestandRepresentation.class, name ="brot"),
@JsonSubTypes.Type(value = ProduktRepresentation.class, name="lager")
// Andere Subtypen hier
})
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class BestandRepresentation {
protected String id;
protected String name;
private boolean verfuegbarkeit;
private float preis;

public BestandRepresentation(String id, String name, boolean verfuegbarkeit, float preis) {
this.id = id;
this.name = name;
this.verfuegbarkeit = verfuegbarkeit;
this.preis = preis;
}

public BestandRepresentation() {
// TODO Auto-generated constructor stub
}
public String getId() {
return id;
}

public String getName() {
return name;
}

public boolean getVerfuegbarkeit() {
return verfuegbarkeit;
}



public float getPreis() {
return preis;
}

public void setId(String id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.dhbw.foodcoop.warehouse.adapters.representations;

public class BestellungBuyRepresentation {
private String id;
private BestellungRepresentation bestellung;
private double amount;
public BestellungBuyRepresentation(String id, BestellungRepresentation bestellung, double amount) {
super();
this.id = id;
this.bestellung = bestellung;
this.amount = amount;
}

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}



public BestellungRepresentation getBestellung() {
return bestellung;
}

public void setBestellung(BestellungRepresentation bestellung) {
this.bestellung = bestellung;
}

public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}

}
Loading

0 comments on commit efa0677

Please sign in to comment.