Skip to content

Commit

Permalink
Merge pull request #9 from Bart3kTK/spring_db_conf
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart3kTK authored Nov 17, 2024
2 parents 1850928 + 0819532 commit 43d6819
Show file tree
Hide file tree
Showing 34 changed files with 904 additions and 121 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/spring_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Spring Boot CI/CD Pipeline

on:
push:
branches:
- main
paths:
- spring/**
pull_request:
paths:
- spring/**

jobs:
test:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: Weather
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping --host 127.0.0.1 --silent" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Cache Maven dependencies
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
working-directory: ./spring
run: mvn clean install -DskipTests


- name: Run mvn tests
working-directory: ./spring
run: mvn test
env:
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/Weather
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root

- name: Spring format check
working-directory: ./spring
run: mvn formatter:validate
env:
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/Weather
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
29 changes: 0 additions & 29 deletions .github/workflows/spring_format_check.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/spring_mvn_test.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ spring/*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*


14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"configurations": [
{
"type": "java",
"name": "Spring Boot-WeatherApplication<weather>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.pogoda.weather.WeatherApplication",
"projectName": "weather",
"args": "",
"envFile": "${workspaceFolder}/.env"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
17 changes: 17 additions & 0 deletions spring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE DATABASE Weather;
CREATE USER 'WeatherServer'@'localhost' IDENTIFIED BY 't4jn3h4sL0';
GRANT ALL PRIVILEGES ON Weather.* TO 'WeatherServer'@'localhost';
FLUSH PRIVILEGES;
SHOW GRANTS FOR 'WeatherServer'@'localhost';



odpalanie: mvn spring-boot:run

dopisanie w controller wiecej getow (i wiecej metod w )

stworzenie w model nowych obiektow (tych co jest w projekcie bazy danych)
do nich wlasne interface
i wlasne repa w data


151 changes: 88 additions & 63 deletions spring/pom.xml
Original file line number Diff line number Diff line change
@@ -1,64 +1,91 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.pogoda</groupId>
<artifactId>weather</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>weather</name>
<description>Backend for data from esp</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.pogoda</groupId>
<artifactId>weather</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>weather</name>
<description>Backend for data from esp</description>

<properties>
<java.version>17</java.version>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- MySQL Driver -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version> <!-- Dodano brakującą wersję -->
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Removed missing dependency com.Weatherdatabase:Weather:1.0.0 -->


<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- Jakarta Persistence API -->
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>

<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<!-- Spring Boot Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>



<build>
<plugins>
<!-- Maven Spring Boot Plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.1</version>
<configuration>

<encoding>UTF-8</encoding>
</configuration>
<executions>
Expand All @@ -69,19 +96,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<!-- Maven Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
44 changes: 44 additions & 0 deletions spring/src/main/java/com/pogoda/weather/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.pogoda.weather.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pogoda.weather.data.EspMeasurementsRepo;
import com.pogoda.weather.model.EspMeasurements;

import lombok.AllArgsConstructor;

@AllArgsConstructor
@RestController
@RequestMapping("/weather")
public class Controller {

@Autowired
EspMeasurementsRepo espDataRepo;

@GetMapping("/test")
public String aja() {
return "cos tam";
}

@PostMapping("/test")
public void ajaa() {
System.out.println("DOSTALEM");
}

@PostMapping("/measurments")
public ResponseEntity<EspMeasurements> zapis(@RequestBody EspMeasurements espMeasurements) {
return ResponseEntity.ok(espDataRepo.saveMeasurements(espMeasurements));
}

@GetMapping("/measurments/{id}")
public ResponseEntity<EspMeasurements> odczyty(@PathVariable String id) {
return ResponseEntity.ok(espDataRepo.getMeasurements(id));
}
}
Loading

0 comments on commit 43d6819

Please sign in to comment.