Skip to content

Commit

Permalink
[Spring boot config]
Browse files Browse the repository at this point in the history
-added group of folders
-created basic examples
 (model, endpoints, db)
-configuration of mysql
  • Loading branch information
github-actions committed Nov 15, 2024
1 parent 1850928 commit 08ebeb6
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 121 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/spring_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Spring mvn tests pipeline

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

jobs:
build:

runs-on: ubuntu-latest

# services:
# db:
# image: mysql:8.0
# ports:
# - 3306:3306
# env:
# MYSQL_ROOT_PASSWORD: root_password
# MYSQL_DATABASE: foo
# MYSQL_USER: user1
# MYSQL_PASSWORD: user1_password
# options: >-
# --health-cmd "mysqladmin ping"
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# steps:
# - name: Show Docker containers
# run: docker ps -a
# - name: Show databases for root user
# run: mysql --protocol=tcp -h localhost -P 3306 -u root -proot_password -e "SHOW DATABASES"
# - name: Show databases for user1
# run: mysql --protocol=tcp -h localhost -P 3306 -u user1 -puser1_password -e "SHOW DATABASES"

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Run mvn tests
working-directory: ./spring
run: mvn test

- name: Spring format check
working-directory: ./spring
run: mvn formatter:validate
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.

52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI with Spring Boot and MySQL

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: testdb
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping --host 127.0.0.1 --silent" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
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
run: mvn clean install -DskipTests

- name: Run tests
run: mvn test
env:
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/testdb
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
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


140 changes: 77 additions & 63 deletions spring/pom.xml
Original file line number Diff line number Diff line change
@@ -1,59 +1,75 @@
<?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>
<!-- 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>

<!-- 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>
Expand All @@ -69,19 +85,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 08ebeb6

Please sign in to comment.