Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .github/workflows/automate_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ jobs:
build:
runs-on: ubuntu-latest

# creates a real Postgres instance inside the GitHub runner
services:
logistics-db:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
POSTGRES_DB: logistics_db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

defaults:
run:
working-directory: server
Expand All @@ -32,6 +48,13 @@ jobs:

- name: Build and Test with Maven
run: mvn -B clean verify
env:
# find on ther GitHub Service Container
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: logistics_db
DB_USER: postgres
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}

- name: Upload test reports
if: always()
Expand All @@ -47,4 +70,4 @@ jobs:
name: JUnit Tests
path: server/target/surefire-reports/*.xml
reporter: java-junit
fail-on-error: true
fail-on-error: true
43 changes: 43 additions & 0 deletions database/Init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- 1. Locations Table
CREATE TABLE IF NOT EXISTS locations (
id VARCHAR(36) PRIMARY KEY,
name VARCHAR(255),
type VARCHAR(50),
city VARCHAR(255)
);

-- 2. Products Table
CREATE TABLE IF NOT EXISTS products (
id VARCHAR(36) PRIMARY KEY,
name VARCHAR(255),
min_temperature DOUBLE PRECISION,
max_temperature DOUBLE PRECISION
);

-- 3. Storage Units Table
CREATE TABLE IF NOT EXISTS storage_units (
id VARCHAR(36) PRIMARY KEY,
location_id VARCHAR(36) REFERENCES locations(id),
min_temperature DOUBLE PRECISION,
max_temperature DOUBLE PRECISION,
capacity INTEGER
);

-- 4. Demands Table
CREATE TABLE IF NOT EXISTS demands (
id VARCHAR(36) PRIMARY KEY,
location_id VARCHAR(36) REFERENCES locations(id),
product_id VARCHAR(36) REFERENCES products(id),
date VARCHAR(50),
min_quantity INTEGER,
max_quantity INTEGER
);

-- 5. Routes Table
CREATE TABLE IF NOT EXISTS routes (
id VARCHAR(36) PRIMARY KEY,
from_location_id VARCHAR(36) REFERENCES locations(id),
to_location_id VARCHAR(36) REFERENCES locations(id),
capacity INTEGER,
min_shipment INTEGER
);
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
services:
server:
build: ./server
container_name: logistics-platform-server
ports:
- "8000:8000"
env_file:
- ./server/.env
depends_on:
db-service:
condition: service_healthy
environment:
DB_HOST: db-service
DB_PORT: 5432
DB_NAME: logistics_db
DB_USER: postgres
DB_PASSWORD: YourPassword123
SERVER_PORT: 8000

db-service:
image: postgres:15
container_name: logistics-db-container
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: YourPassword123
POSTGRES_DB: logistics_db
ports:
- "5433:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
- ./database/Init.sql:/docker-entrypoint-initdb.d/Init.sql:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d logistics_db"]
interval: 5s
timeout: 5s
retries: 10

volumes:
postgres-data:
driver: local
2 changes: 2 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ build/

### VS Code ###
.vscode/

.env
18 changes: 18 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


# Stage 1: Build

FROM maven:3.9.6-eclipse-temurin-21 AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline -B
COPY src ./src
RUN mvn clean package -DskipTests

# Stage 2: Runtime

FROM eclipse-temurin:21-jre
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8000
ENTRYPOINT ["java", "-jar", "app.jar"]
13 changes: 13 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.4</version>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/io.github.cdimascio/java-dotenv -->
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>java-dotenv</artifactId>
<version>5.2.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package csembstu.alamgir.server;

import csembstu.alamgir.server.config.EnvConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ServerApplication {

public static void main(String[] args) {

EnvConfig.loadEnv();
SpringApplication.run(ServerApplication.class, args);
}

Expand Down
25 changes: 25 additions & 0 deletions server/src/main/java/csembstu/alamgir/server/config/EnvConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package csembstu.alamgir.server.config;

import io.github.cdimascio.dotenv.Dotenv;
import io.github.cdimascio.dotenv.DotenvEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EnvConfig {
private static final Logger log = LoggerFactory.getLogger(EnvConfig.class);
public static void loadEnv() {
Dotenv dotenv = Dotenv.configure()
.ignoreIfMissing()
.load();

for (DotenvEntry entry : dotenv.entries()) {
String key = entry.getKey();
String value = entry.getValue();

if (value != null && !value.isEmpty()) {
System.setProperty(key, value);
log.info("Loaded property: {}", key);
}
}
}
}
12 changes: 7 additions & 5 deletions server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@

spring.application.name=server


server.port=8000

# Database Setup for PostgreSQL
spring.datasource.url=jdbc:postgresql://localhost:5432/logisticsdb
spring.datasource.username=postgres
spring.datasource.password=postgresql
spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASSWORD}

spring.datasource.driver-class-name=org.postgresql.Driver
# spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true


#hide the stack trace in error responses
server.error.include-stacktrace=never
server.error.include-message=always
Expand Down