diff --git a/docker-compose.yml b/docker-compose.yml
index b387e1a6..19196d1b 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,15 +1,50 @@
version: '3.1'
services:
- stats-server:
+ server:
+ build: stat-service/server
+ image: server
+ container_name: server
ports:
- "9090:9090"
+ - "9091:9091"
+ depends_on:
+ - statdb
+ environment:
+ - SPRING_DATASOURCE_URL=jdbc:postgresql://statdb:5432/statdb
+ - SPRING_DATASOURCE_USERNAME=ewm
+ - SPRING_DATASOURCE_PASSWORD=ewm
- stats-db:
- image: postgres:14-alpine
+ statdb:
+ image: postgres:13.7-alpine
+ container_name: statdb
+ ports:
+ - "5432:5432"
+ environment:
+ - POSTGRES_PASSWORD=ewm
+ - POSTGRES_USER=ewm
+ - POSTGRES_DB=statdb
- ewm-service:
+ main-service:
+ build: main-service
+ image: main-service
+ container_name: main-service
ports:
- "8080:8080"
+ depends_on:
+ - main-db
+ - server
+ environment:
+ - SPRING_DATASOURCE_URL=jdbc:postgresql://main-db:5432/main-db
+ - SPRING_DATASOURCE_USERNAME=ewm
+ - SPRING_DATASOURCE_PASSWORD=ewm
+ - STATS_SERVER_URL=http://server:9090
- ewm-db:
- image: postgres:14-alpine
+ main-db:
+ image: postgres:13.7-alpine
+ container_name: main-db
+ ports:
+ - "6542:5432"
+ environment:
+ - POSTGRES_PASSWORD=ewm
+ - POSTGRES_USER=ewm
+ - POSTGRES_DB=main-db
\ No newline at end of file
diff --git a/ewm-main-service-spec.json b/ewm-main-service-spec.json
index f28d1413..65c4182d 100644
--- a/ewm-main-service-spec.json
+++ b/ewm-main-service-spec.json
@@ -2833,4 +2833,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/ewm-stats-service-spec.json b/ewm-stats-service-spec.json
index 436892a8..96f7408b 100644
--- a/ewm-stats-service-spec.json
+++ b/ewm-stats-service-spec.json
@@ -167,4 +167,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/main-service/Dockerfile b/main-service/Dockerfile
new file mode 100644
index 00000000..2118327f
--- /dev/null
+++ b/main-service/Dockerfile
@@ -0,0 +1,3 @@
+FROM amazoncorretto:11-alpine-jdk
+COPY target/*.jar app.jar
+ENTRYPOINT ["java","-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 00000000..54d1ac03
--- /dev/null
+++ b/main-service/pom.xml
@@ -0,0 +1,57 @@
+
+
+ 4.0.0
+
+ ru.practicum
+ explore-with-me
+ 0.0.1-SNAPSHOT
+
+
+ main-service
+
+
+
+ ru.practicum
+ client
+ ${project.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+
+
+ 11
+ 11
+ UTF-8
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
\ No newline at end of file
diff --git a/main-service/src/main/java/ru/practicum/ewm/EWMMainServiceApp.java b/main-service/src/main/java/ru/practicum/ewm/EWMMainServiceApp.java
new file mode 100644
index 00000000..413a7bae
--- /dev/null
+++ b/main-service/src/main/java/ru/practicum/ewm/EWMMainServiceApp.java
@@ -0,0 +1,11 @@
+package ru.practicum.ewm;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class EWMMainServiceApp {
+ public static void main(String[] args) {
+ SpringApplication.run(EWMMainServiceApp.class, args);
+ }
+}
\ No newline at end of file
diff --git a/main-service/src/resources/application.properties b/main-service/src/resources/application.properties
new file mode 100644
index 00000000..67e50e5f
--- /dev/null
+++ b/main-service/src/resources/application.properties
@@ -0,0 +1,24 @@
+server.port=8080
+STAT_SERVER_URL=http://localhost:9090
+
+spring.application.name=ewm-main-service
+spring.jpa.hibernate.ddl-auto=none
+spring.jpa.properties.hibernate.jdbc.time_zone=UTC
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect
+spring.jpa.properties.hibernate.format_sql=true
+spring.sql.init.mode=always
+#---
+spring.datasource.driverClassName=org.postgresql.Driver
+spring.datasource.url=jdbc:postgresql://localhost:6542/main-db
+spring.datasource.username=ewm
+spring.datasource.password=ewm
+#---
+spring.config.activate.on-profile=local
+spring.datasource.url=jdbc:postgresql://localhost:6542/postgres
+stats-server.url=http://localhost:9090
+#---
+spring.config.activate.on-profile=ci,test
+spring.datasource.driverClassName=org.h2.Driver
+spring.datasource.url=jdbc:h2:mem:main-db
+spring.datasource.username=ewm
+spring.datasource.password=ewm
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index ad386209..b83f48f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,6 +1,6 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
@@ -11,6 +11,10 @@
Explore With Me
+
+ stat-service
+ main-service
+
ru.practicum
explore-with-me
@@ -183,5 +187,14 @@
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.14.1
+
+
-
+
+
\ No newline at end of file
diff --git a/stat-service/client/pom.xml b/stat-service/client/pom.xml
new file mode 100644
index 00000000..a6eaf073
--- /dev/null
+++ b/stat-service/client/pom.xml
@@ -0,0 +1,34 @@
+
+
+ 4.0.0
+
+ ru.practicum
+ stat-service
+ 0.0.1-SNAPSHOT
+ ../pom.xml
+
+
+ client
+
+
+
+ ru.practicum
+ dto
+ ${project.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ 11
+ 11
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/stat-service/client/src/main/java/ru/practicum/ewm/BaseClient.java b/stat-service/client/src/main/java/ru/practicum/ewm/BaseClient.java
new file mode 100644
index 00000000..194d7d84
--- /dev/null
+++ b/stat-service/client/src/main/java/ru/practicum/ewm/BaseClient.java
@@ -0,0 +1,59 @@
+package ru.practicum.ewm;
+
+import org.springframework.http.*;
+import org.springframework.lang.Nullable;
+import org.springframework.web.client.HttpStatusCodeException;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
+import java.util.Map;
+
+public class BaseClient {
+ protected final RestTemplate restTemplate;
+
+ public BaseClient(RestTemplate restTemplate) {
+ this.restTemplate = restTemplate;
+ }
+
+ protected ResponseEntity