Skip to content

Commit 3f99287

Browse files
RND-38: implement initial Spring Boot project with 3 layered architecture
1 parent 55e15c2 commit 3f99287

33 files changed

Lines changed: 1026 additions & 12 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ target/
2626

2727
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2828
hs_err_pid*
29+
30+
*.iml

‎golden-example/controller/pom.xml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.intellias</groupId>
9+
<artifactId>golden-example</artifactId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>controller</artifactId>
15+
<packaging>jar</packaging>
16+
17+
<properties>
18+
<maven.compiler.source>17</maven.compiler.source>
19+
<maven.compiler.target>17</maven.compiler.target>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-web</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.intellias</groupId>
30+
<artifactId>service-api</artifactId>
31+
<version>0.0.1-SNAPSHOT</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
</dependency>
37+
</dependencies>
38+
39+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.intellias.golden_example.controller;
2+
3+
import com.intellias.golden_example.model.Book;
4+
import com.intellias.golden_example.service.IBooksService;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.validation.annotation.Validated;
7+
import org.springframework.web.bind.annotation.*;
8+
9+
import java.util.Collection;
10+
import java.util.Optional;
11+
12+
@RestController
13+
@RequestMapping("/v1/books")
14+
@RequiredArgsConstructor
15+
public class BooksController {
16+
17+
private final IBooksService booksService;
18+
19+
@GetMapping
20+
public Collection<Book> getAll() {
21+
return booksService.getAll();
22+
}
23+
24+
@GetMapping("/{id}")
25+
public Optional<Book> getById(@PathVariable long id) {
26+
return booksService.getById(id);
27+
}
28+
29+
@PostMapping
30+
public Book save(@Validated @RequestBody Book book) {
31+
return booksService.save(book);
32+
}
33+
34+
@PutMapping
35+
public Book update(@Validated @RequestBody Book book) {
36+
return booksService.update(book);
37+
}
38+
39+
@DeleteMapping("/{id}")
40+
public void delete(@PathVariable long id) {
41+
booksService.deleteById(id);
42+
}
43+
44+
45+
}

‎golden-example/docker/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.mysql-data
2+
.postgres-data
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "3.3"
2+
3+
services:
4+
5+
mysql-db:
6+
image: mysql/mysql-server:5.7
7+
environment:
8+
MYSQL_DATABASE: 'db'
9+
MYSQL_ROOT_PASSWORD: 'secret-pw'
10+
MYSQL_ROOT_HOST: '%'
11+
ports:
12+
- '3306:3306'
13+
expose:
14+
- '3306'
15+
volumes:
16+
- './.mysql-data/db:/var/lib/mysql'
17+
18+
postgres-db:
19+
image: postgres:15.2
20+
environment:
21+
POSTGRES_USER: "root"
22+
POSTGRES_PASSWORD: "secret-pw-postgres"
23+
POSTGRES_DB: "db"
24+
PGDATA: /var/lib/postgresql/data
25+
ports:
26+
- '5432:5432'
27+
volumes:
28+
- './.postgres-data:/var/lib/postgresql/data'

‎golden-example/exe/pom.xml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.intellias</groupId>
8+
<artifactId>golden-example</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>exe</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<properties>
17+
<maven.compiler.source>17</maven.compiler.source>
18+
<maven.compiler.target>17</maven.compiler.target>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.intellias</groupId>
25+
<artifactId>controller</artifactId>
26+
<version>0.0.1-SNAPSHOT</version>
27+
<scope>compile</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.intellias</groupId>
31+
<artifactId>service-impl</artifactId>
32+
<version>0.0.1-SNAPSHOT</version>
33+
<scope>compile</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.intellias</groupId>
37+
<artifactId>repository-impl</artifactId>
38+
<version>0.0.1-SNAPSHOT</version>
39+
<scope>compile</scope>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-maven-plugin</artifactId>
48+
<configuration>
49+
<image>
50+
<name>intellias.com/golden_example</name>
51+
</image>
52+
</configuration>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
57+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.intellias.golden_example;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
datasource:
3+
url: jdbc:mysql://${MYSQL_HOST:localhost}:3306/db
4+
username: root
5+
password: secret-pw
6+
flyway:
7+
enabled: false
8+
sql:
9+
init:
10+
platform: mysql
11+
mode: always
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
datasource:
3+
url: jdbc:postgresql://localhost:5432/db?currentSchema=golden_example
4+
username: root
5+
password: secret-pw-postgres
6+
7+
repository:
8+
mysql:
9+
enabled: false
10+
postgres:
11+
enabled: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring:
2+
jpa:
3+
show-sql: true
4+
profiles:
5+
# active: postgres-jooq-repository
6+
active: mysql-jpa-repository

0 commit comments

Comments
 (0)