From 3c415435162cb68fd7dd7c81c8fc8ec3a308fdf6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A1n=20Mach=C3=A1=C4=8Dek?= <xmachac5@fi.muni.cz>
Date: Sun, 26 Mar 2023 13:29:49 +0200
Subject: [PATCH] feat: add server settings

---
 report/openapi.yaml                           |   2 +-
 report/pom.xml                                | 102 +++++++++++++++++-
 .../fi/pa165/report/ReportApplication.java    |  15 ---
 .../pa165/report/server/ReportController.java |   9 ++
 .../{ => server}/ReportApplicationTests.java  |   2 +-
 5 files changed, 110 insertions(+), 20 deletions(-)
 delete mode 100644 report/src/main/java/cz/muni/fi/pa165/report/ReportApplication.java
 create mode 100644 report/src/main/java/cz/muni/fi/pa165/report/server/ReportController.java
 rename report/src/test/java/cz/muni/fi/pa165/report/{ => server}/ReportApplicationTests.java (82%)

diff --git a/report/openapi.yaml b/report/openapi.yaml
index 7ea3bc2..e60241a 100644
--- a/report/openapi.yaml
+++ b/report/openapi.yaml
@@ -23,7 +23,7 @@ servers:
       server:
         default: localhost
       port:
-        default: "8085"
+        default: "8080"
 tags:
   - name: Report
     description: Microservice for report pdf report.
diff --git a/report/pom.xml b/report/pom.xml
index 4a717ac..50da74e 100644
--- a/report/pom.xml
+++ b/report/pom.xml
@@ -9,22 +9,75 @@
     </parent>
 
     <artifactId>report</artifactId>
-
+    <packaging>jar</packaging>
     <name>report</name>
     <description>Reporting service for Airport Manager</description>
 
     <dependencies>
 
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mapstruct</groupId>
+            <artifactId>mapstruct</artifactId>
         </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-webflux</artifactId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>jakarta.annotation</groupId>
+            <artifactId>jakarta.annotation-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>jakarta.validation</groupId>
+            <artifactId>jakarta.validation-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.swagger.core.v3</groupId>
+            <artifactId>swagger-models-jakarta</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.swagger.core.v3</groupId>
+            <artifactId>swagger-annotations-jakarta</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.openapitools</groupId>
+            <artifactId>jackson-databind-nullable</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.validation</groupId>
+            <artifactId>validation-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
+        </dependency>
+
+        <!-- for pagination from JPA without actually using JPA -->
+        <dependency>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-commons</artifactId>
+        </dependency>
+
+        <!-- for testing -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
@@ -33,11 +86,54 @@
     </dependencies>
 
     <build>
+
+        <defaultGoal>spring-boot:run</defaultGoal>
+        <!-- name of executable JAR file -->
+        <finalName>report_generated</finalName>
+
         <plugins>
+            <plugin>
+                <groupId>org.openapitools</groupId>
+                <artifactId>openapi-generator-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                        <configuration>
+                            <!-- take openapi.yaml from the corresponding microservice -->
+                            <inputSpec>${project.basedir}/openapi.yaml</inputSpec>
+                            <generatorName>spring</generatorName>
+                            <apiPackage>cz.muni.fi.pa165.report.server.api</apiPackage>
+                            <modelPackage>cz.muni.fi.pa165.report.server.model</modelPackage>
+                            <!-- https://openapi-generator.tech/docs/generators/spring -->
+                            <configOptions>
+                                <basePackage>cz.muni.fi.pa165.report.server</basePackage>
+                                <configPackage>cz.muni.fi.pa165.report.server.config</configPackage>
+                                <useSpringBoot3>true</useSpringBoot3>
+                                <useTags>true</useTags>
+                                <delegatePattern>true</delegatePattern>
+                            </configOptions>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <!-- create executable jar -->
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <executable>true</executable>
+                </configuration>
+            </plugin>
+
+            <!-- run integration tests in "mvn verify" phase -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
             </plugin>
         </plugins>
     </build>
 </project>
+
diff --git a/report/src/main/java/cz/muni/fi/pa165/report/ReportApplication.java b/report/src/main/java/cz/muni/fi/pa165/report/ReportApplication.java
deleted file mode 100644
index 1dd030d..0000000
--- a/report/src/main/java/cz/muni/fi/pa165/report/ReportApplication.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package cz.muni.fi.pa165.report;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class ReportApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(ReportApplication.class, args);
-    }
-
-}
-
-
diff --git a/report/src/main/java/cz/muni/fi/pa165/report/server/ReportController.java b/report/src/main/java/cz/muni/fi/pa165/report/server/ReportController.java
new file mode 100644
index 0000000..9cbd3ab
--- /dev/null
+++ b/report/src/main/java/cz/muni/fi/pa165/report/server/ReportController.java
@@ -0,0 +1,9 @@
+package cz.muni.fi.pa165.report.server;
+
+public class ReportController {
+
+    public static void main(String[] args) {
+        System.out.println("Hello there!");
+    }
+}
+
diff --git a/report/src/test/java/cz/muni/fi/pa165/report/ReportApplicationTests.java b/report/src/test/java/cz/muni/fi/pa165/report/server/ReportApplicationTests.java
similarity index 82%
rename from report/src/test/java/cz/muni/fi/pa165/report/ReportApplicationTests.java
rename to report/src/test/java/cz/muni/fi/pa165/report/server/ReportApplicationTests.java
index c3aeea2..8708f43 100644
--- a/report/src/test/java/cz/muni/fi/pa165/report/ReportApplicationTests.java
+++ b/report/src/test/java/cz/muni/fi/pa165/report/server/ReportApplicationTests.java
@@ -1,4 +1,4 @@
-package cz.muni.fi.pa165.report;
+package cz.muni.fi.pa165.report.server;
 
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
-- 
GitLab