Kaynağa Gözat

:tada: Connect my backend to postgreSQL database

DricomDragon 7 ay önce
ebeveyn
işleme
06eb9e7874

+ 2 - 1
squad-composer/.theia/settings.json

@@ -1,3 +1,4 @@
 {
-    "java.compile.nullAnalysis.mode": "automatic"
+    "java.compile.nullAnalysis.mode": "automatic",
+    "java.configuration.updateBuildConfiguration": "interactive"
 }

+ 8 - 0
squad-composer/pom.xml

@@ -34,6 +34,14 @@
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-web</artifactId>
 		</dependency>
+        <dependency>
+			<groupId>org.springframework</groupId>
+            <artifactId>spring-jdbc</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.zaxxer</groupId>
+            <artifactId>HikariCP</artifactId>
+        </dependency>
 		<dependency>
 			<groupId>org.flywaydb</groupId>
 			<artifactId>flyway-core</artifactId>

+ 31 - 0
squad-composer/src/main/java/eu/jovian_hersemeule/dev/squad/squad_composer/controllers/MechController.java

@@ -0,0 +1,31 @@
+package eu.jovian_hersemeule.dev.squad.squad_composer.controllers;
+
+import org.springframework.web.bind.annotation.RestController;
+
+import eu.jovian_hersemeule.dev.squad.squad_composer.data.MechRowMapper;
+import eu.jovian_hersemeule.dev.squad.squad_composer.data.model.Mech;
+
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+@RestController
+@RequestMapping("/mech")
+public class MechController {
+
+    private final JdbcTemplate jdbcTemplate;
+
+    MechController(final DataSource ds) {
+        jdbcTemplate = new JdbcTemplate(ds);
+    }
+
+    @GetMapping("/")
+    public List<Mech> list() {
+        return jdbcTemplate.query("SELECT * FROM MECH", new MechRowMapper());
+    }
+    
+}

+ 5 - 0
squad-composer/src/main/java/eu/jovian_hersemeule/dev/squad/squad_composer/data/DataService.java

@@ -0,0 +1,5 @@
+package eu.jovian_hersemeule.dev.squad.squad_composer.data;
+
+public class DataService {
+    
+}

+ 22 - 0
squad-composer/src/main/java/eu/jovian_hersemeule/dev/squad/squad_composer/data/MechRowMapper.java

@@ -0,0 +1,22 @@
+package eu.jovian_hersemeule.dev.squad.squad_composer.data;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.lang.NonNull;
+import org.springframework.lang.Nullable;
+
+import eu.jovian_hersemeule.dev.squad.squad_composer.data.model.Mech;
+
+public class MechRowMapper implements RowMapper<Mech> {
+
+    @Override
+    @Nullable
+    public Mech mapRow(final @NonNull ResultSet rs, int rowNum) throws SQLException {
+        final Mech obj = new Mech();
+        obj.setName(rs.getString("name"));
+        return obj;
+    }
+
+}

+ 13 - 0
squad-composer/src/main/java/eu/jovian_hersemeule/dev/squad/squad_composer/data/model/Mech.java

@@ -0,0 +1,13 @@
+package eu.jovian_hersemeule.dev.squad.squad_composer.data.model;
+
+public class Mech {
+    String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

+ 5 - 0
squad-composer/src/main/resources/application.properties

@@ -1 +1,6 @@
 spring.application.name=squad-composer
+server.port=5042
+spring.datasource.url=jdbc:postgresql://localhost:5432/squad-db
+spring.datasource.username=squad-user
+spring.datasource.password=sosecret
+spring.flyway.baseline-on-migrate=true

Dosya farkı çok büyük olduğundan ihmal edildi
+ 2 - 0
squad-composer/tools/api/SquadComposer-soapui-project.xml


+ 9 - 7
squad-composer/tools/container/docker-compose.yml

@@ -1,12 +1,12 @@
-version: '3.8'
+version: '3.3'
 services:
   db:
     image: postgres
-    restart: always
+    restart: "no"
     environment:
-      POSTGRES_USER: myuser
-      POSTGRES_PASSWORD: mypassword
-      POSTGRES_DB: mydb
+      POSTGRES_USER: squad-user
+      POSTGRES_PASSWORD: sosecret
+      POSTGRES_DB: squad-db
     ports:
       - "5432:5432"
     volumes:
@@ -14,9 +14,9 @@ services:
 
   pgadmin:
     image: dpage/pgadmin4
-    restart: always
+    restart: "no"
     environment:
-      PGADMIN_DEFAULT_EMAIL: admin@admin.com
+      PGADMIN_DEFAULT_EMAIL: dev@jovian-hersemeule.eu
       PGADMIN_DEFAULT_PASSWORD: root
     ports:
       - "8080:80"
@@ -24,6 +24,8 @@ services:
       - pgadmin_data:/var/lib/pgadmin
     depends_on:
       - db
+    links:
+      - "db:pgsql-server"
 
 volumes:
   db_data: