diff --git a/docker-compose.yml b/docker-compose.yml
index be96142..1e26a3e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,14 +1,46 @@
+version: '3.1'
+
services:
stats-server:
+ build: stats/stats-server
+ container_name: stat-server
ports:
- "9090:9090"
+ environment:
+ - SPRING_DATASOURCE_URL=jdbc:postgresql://stats-db:5432/ewm-stats
+ - SPRING_DATASOURCE_USERNAME=stat
+ - SPRING_DATASOURCE_PASSWORD=stat
+ depends_on:
+ - stats-db
stats-db:
image: postgres:16.1
+ container_name: postgres-ewm-stats-db
+ ports:
+ - "6542:5432"
+ environment:
+ - POSTGRES_PASSWORD=stat
+ - POSTGRES_USER=stat
+ - POSTGRES_DB=ewm-stats
ewm-service:
+ build: main-service
ports:
- "8080:8080"
+ environment:
+ - CLIENT_URL=http://stats-server:9090
+ - SPRING_DATASOURCE_URL=jdbc:postgresql://ewm-db:5432/ewm-main
+ - SPRING_DATASOURCE_USERNAME=main
+ - SPRING_DATASOURCE_PASSWORD=main
+ depends_on:
+ - ewm-db
ewm-db:
image: postgres:16.1
+ container_name: postgres-ewm-main-service-db
+ ports:
+ - "7542:5432"
+ environment:
+ - POSTGRES_PASSWORD=main
+ - POSTGRES_USER=main
+ - POSTGRES_DB=ewm-main
\ No newline at end of file
diff --git a/main-service/Dockerfile b/main-service/Dockerfile
new file mode 100644
index 0000000..0ff1817
--- /dev/null
+++ b/main-service/Dockerfile
@@ -0,0 +1,5 @@
+FROM eclipse-temurin:21-jre-jammy
+VOLUME /tmp
+ARG JAR_FILE=target/*.jar
+COPY ${JAR_FILE} app.jar
+ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"]
\ No newline at end of file
diff --git a/main-service/pom.xml b/main-service/pom.xml
new file mode 100644
index 0000000..dea6df8
--- /dev/null
+++ b/main-service/pom.xml
@@ -0,0 +1,87 @@
+
+
+ 4.0.0
+
+ ru.practicum
+ explore-with-me
+ 0.0.1-SNAPSHOT
+
+
+ main-service
+
+
+ 21
+ 21
+ UTF-8
+
+
+
+
+ org.zalando
+ logbook-spring-boot-starter
+ 3.7.2
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.postgresql
+ postgresql
+ runtime
+
+
+
+ com.h2database
+ h2
+ runtime
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ ru.practicum
+ stats-dto
+ 0.0.1-SNAPSHOT
+ compile
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
\ No newline at end of file
diff --git a/main-service/src/main/java/ewm/MainServiceApplication.java b/main-service/src/main/java/ewm/MainServiceApplication.java
new file mode 100644
index 0000000..fce1434
--- /dev/null
+++ b/main-service/src/main/java/ewm/MainServiceApplication.java
@@ -0,0 +1,11 @@
+package ewm;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class MainServiceApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(MainServiceApplication.class, args);
+ }
+}
diff --git a/pom.xml b/pom.xml
index b15acb2..6a4fa1e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,8 +11,12 @@
Explore With Me
+
+ main-service
+ stats
+
- ru.practicum
+ ru.practicum
explore-with-me
0.0.1-SNAPSHOT
pom
diff --git a/stats/pom.xml b/stats/pom.xml
new file mode 100644
index 0000000..7785b9b
--- /dev/null
+++ b/stats/pom.xml
@@ -0,0 +1,31 @@
+
+
+ 4.0.0
+
+ ru.practicum
+ explore-with-me
+ 0.0.1-SNAPSHOT
+
+
+
+ Explore With Me Stats
+
+ stats
+ 0.0.1-SNAPSHOT
+ pom
+
+
+ stats-client
+ stats-dto
+ stats-server
+
+
+
+ 21
+ 21
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/stats/stats-client/pom.xml b/stats/stats-client/pom.xml
new file mode 100644
index 0000000..c65653f
--- /dev/null
+++ b/stats/stats-client/pom.xml
@@ -0,0 +1,83 @@
+
+
+ 4.0.0
+
+ ru.practicum
+ explore-with-me
+ 0.0.1-SNAPSHOT
+ ../../pom.xml
+
+
+ stats-client
+
+
+
+ org.zalando
+ logbook-spring-boot-starter
+ 3.7.2
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.hibernate.validator
+ hibernate-validator
+
+
+
+ org.apache.httpcomponents.client5
+ httpclient5
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ ru.practicum
+ stats-dto
+ 0.0.1-SNAPSHOT
+ compile
+
+
+ ru.practicum
+ stats-server
+ 0.0.1-SNAPSHOT
+ compile
+
+
+
+
+ 22
+ 22
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/stats/stats-client/src/main/java/client/StatsClient.java b/stats/stats-client/src/main/java/client/StatsClient.java
new file mode 100644
index 0000000..79a3337
--- /dev/null
+++ b/stats/stats-client/src/main/java/client/StatsClient.java
@@ -0,0 +1,67 @@
+package client;
+
+import dto.CreateDto;
+import org.apache.hc.client5.http.classic.HttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpStatusCodeException;
+import org.springframework.web.client.RestTemplate;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+
+@Service
+public class StatsClient {
+ @Value("${client.url}")
+ private String serverUrl;
+ private final RestTemplate rest;
+
+ public StatsClient() {
+ this.rest = new RestTemplate();
+ HttpClient httpClient = HttpClientBuilder.create().build();
+ HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
+ rest.setRequestFactory(requestFactory);
+ }
+
+ public ResponseEntity