Skip to content

Commit 030b10e

Browse files
authored
Merge pull request #1 from aKorishev/stat_svc
[stat_svc] Добавил струтуру проекта, добавил модули
2 parents f348a2c + 10b1a5b commit 030b10e

37 files changed

+1470
-5
lines changed

docker-compose.yml

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
services:
22
stats-server:
3+
build: ./stat-service/stat-server
4+
image: stat-server
5+
container_name: stat-server
36
ports:
47
- "9090:9090"
8+
depends_on:
9+
- stats-db
10+
environment:
11+
- SPRING_DATASOURCE_URL=jdbc:postgresql://stats-db:5432/stats
12+
- SPRING_DATASOURCE_USERNAME=postgres
13+
- SPRING_DATASOURCE_PASSWORD=1
14+
515

616
stats-db:
717
image: postgres:16.1
18+
container_name: postgres
19+
ports:
20+
- "6541:5432"
21+
environment:
22+
- POSTGRES_PASSWORD=1
23+
- POSTGRES_USER=postgres
24+
- POSTGRES_DB=stats
25+
healthcheck:
26+
test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER
27+
timeout: 5s
28+
interval: 5s
29+
retries: 10
830

931
ewm-service:
10-
ports:
11-
- "8080:8080"
32+
build: main-service
33+
image: evm-service
34+
container_name: evm-service
35+
ports:
36+
- "8080:8080"
1237

1338
ewm-db:
14-
image: postgres:16.1
39+
image: postgres:16.1
40+

main-service/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM eclipse-temurin:21-jre-jammy
2+
VOLUME /tmp
3+
ARG JAR_FILE=target/*.jar
4+
COPY ${JAR_FILE} app.jar
5+
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"]

main-service/pom.xml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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>ru.practicum</groupId>
8+
<artifactId>explore-with-me</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>explore-with-me-service</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>21</maven.compiler.source>
16+
<maven.compiler.target>21</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-actuator</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.zalando</groupId>
28+
<artifactId>logbook-spring-boot-starter</artifactId>
29+
<version>3.9.0</version>
30+
</dependency>
31+
</dependencies>
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-maven-plugin</artifactId>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.practicum.ewm;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class EwmServiceApp {
8+
public static void main(String[] args) {
9+
SpringApplication.run(EwmServiceApp.class, args);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.port=8080

pom.xml

+32-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.3.2</version>
9+
<version>3.3.0</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212

@@ -17,11 +17,41 @@
1717
<version>0.0.1-SNAPSHOT</version>
1818
<packaging>pom</packaging>
1919

20+
<modules>
21+
<module>stat-service</module>
22+
<module>main-service</module>
23+
</modules>
24+
2025
<properties>
2126
<java.version>21</java.version>
2227
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
28+
<mapstruct.version>1.6.0.Beta2</mapstruct.version>
29+
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
30+
<querydsl-jpa.version>5.1.0</querydsl-jpa.version>
2331
</properties>
2432

33+
<dependencyManagement>
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.mapstruct</groupId>
37+
<artifactId>mapstruct</artifactId>
38+
<version>${mapstruct.version}</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.projectlombok</groupId>
42+
<artifactId>lombok-mapstruct-binding</artifactId>
43+
<version>${lombok-mapstruct-binding.version}</version>
44+
<scope>provided</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.querydsl</groupId>
48+
<artifactId>querydsl-jpa</artifactId>
49+
<classifier>jakarta</classifier>
50+
<version>${querydsl-jpa.version}</version>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
2555
<build>
2656
<pluginManagement>
2757
<plugins>
@@ -184,4 +214,4 @@
184214
</profile>
185215
</profiles>
186216

187-
</project>
217+
</project>

stat-service/pom.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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>ru.practicum</groupId>
8+
<artifactId>explore-with-me</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>explore-with-me-stats</artifactId>
13+
<packaging>pom</packaging>
14+
<modules>
15+
<module>statistic-dto</module>
16+
<module>statistic-client</module>
17+
<module>stat-server</module>
18+
</modules>
19+
20+
<properties>
21+
<maven.compiler.source>21</maven.compiler.source>
22+
<maven.compiler.target>21</maven.compiler.target>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
</properties>
25+
</project>

stat-service/stat-server/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM eclipse-temurin:21-jre-jammy
2+
VOLUME /tmp
3+
ARG JAR_FILE=target/*.jar
4+
COPY ${JAR_FILE} app.jar
5+
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"]

stat-service/stat-server/pom.xml

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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>ru.practicum</groupId>
8+
<artifactId>explore-with-me-stats</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<name>Stat server</name>
13+
14+
<artifactId>explore-with-me-stats-service</artifactId>
15+
<version>0.0.1-SNAPSHOT</version>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-web</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-actuator</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-validation</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.postgresql</groupId>
32+
<artifactId>postgresql</artifactId>
33+
<scope>runtime</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.h2database</groupId>
37+
<artifactId>h2</artifactId>
38+
<scope>runtime</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-configuration-processor</artifactId>
43+
<optional>true</optional>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-data-jpa</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.mapstruct</groupId>
56+
<artifactId>mapstruct</artifactId>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.projectlombok</groupId>
60+
<artifactId>lombok</artifactId>
61+
<optional>true</optional>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.projectlombok</groupId>
65+
<artifactId>lombok-mapstruct-binding</artifactId>
66+
<scope>provided</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>ru.practicum</groupId>
70+
<artifactId>explore-with-me-stats-dto</artifactId>
71+
<version>0.0.1-SNAPSHOT</version>
72+
<scope>compile</scope>
73+
</dependency>
74+
</dependencies>
75+
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.springframework.boot</groupId>
80+
<artifactId>spring-boot-maven-plugin</artifactId>
81+
<configuration>
82+
<excludes>
83+
<exclude>
84+
<groupId>org.projectlombok</groupId>
85+
<artifactId>lombok</artifactId>
86+
</exclude>
87+
</excludes>
88+
</configuration>
89+
</plugin>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-compiler-plugin</artifactId>
93+
<version>3.11.0</version>
94+
<configuration>
95+
<annotationProcessorPaths>
96+
<path>
97+
<groupId>org.projectlombok</groupId>
98+
<artifactId>lombok</artifactId>
99+
<version>1.18.32</version>
100+
</path>
101+
<path>
102+
<groupId>org.projectlombok</groupId>
103+
<artifactId>lombok-mapstruct-binding</artifactId>
104+
<version>0.2.0</version>
105+
</path>
106+
<path>
107+
<groupId>org.mapstruct</groupId>
108+
<artifactId>mapstruct-processor</artifactId>
109+
<version>1.6.0.Beta2</version>
110+
</path>
111+
</annotationProcessorPaths>
112+
</configuration>
113+
</plugin>
114+
</plugins>
115+
</build>
116+
117+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.practicum.statistic.api;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class StatisticApiApp {
8+
public static void main(String[] args) {
9+
SpringApplication.run(StatisticApiApp.class, args);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.practicum.statistic.api.exceptions;
2+
3+
public class IdIsAlreadyInUseException extends RuntimeException {
4+
public IdIsAlreadyInUseException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.practicum.statistic.api.exceptions;
2+
3+
public class NotFoundException extends RuntimeException {
4+
public NotFoundException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.practicum.statistic.api.exceptions;
2+
3+
public class NotValidException extends RuntimeException {
4+
public NotValidException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ru.practicum.statistic.api.service;
2+
3+
import jakarta.validation.Valid;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.web.bind.annotation.*;
6+
import ru.practicum.statistic.dto.StatisticRequest;
7+
import ru.practicum.statistic.dto.StatisticInfo;
8+
9+
import java.util.List;
10+
11+
@RestController
12+
@RequiredArgsConstructor
13+
public class StatisticController {
14+
public final StatisticService statisticService;
15+
16+
@GetMapping("/stats")
17+
public List<StatisticInfo> getStatistics(
18+
@RequestParam(defaultValue = "") String start,
19+
@RequestParam(defaultValue = "") String end,
20+
@RequestParam(defaultValue = "") String[] uris,
21+
@RequestParam(defaultValue = "false") Boolean unique
22+
) {
23+
return statisticService.getStatistics(start, end, uris, unique);
24+
}
25+
26+
@PostMapping("/hit")
27+
public StatisticRequest postRequest(
28+
@Valid @RequestBody StatisticRequest statisticRequest) {
29+
return statisticService.postRequest(statisticRequest);
30+
}
31+
}

0 commit comments

Comments
 (0)