Skip to content

Commit

Permalink
feat: Часть1
Browse files Browse the repository at this point in the history
  • Loading branch information
MAGNAT\sergey_ra committed Apr 23, 2024
1 parent 2edf056 commit e22ee56
Show file tree
Hide file tree
Showing 25 changed files with 677 additions and 6 deletions.
42 changes: 39 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
version: '3.1'
services:
stats-server:
ewm-stats:
build: ewm-stats-server
image: ewm-stats_image
container_name: ewm_stats_container
ports:
- "9090:9090"
- "9090:9090"
depends_on:
- stats-db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://stats-db:5432/ewm_stats
- SPRING_DATASOURCE_USERNAME=ewm_stats
- SPRING_DATASOURCE_PASSWORD=ewm_stats
- STATS_SERVER_URL=http://stats-server:9090

stats-db:
image: postgres:14-alpine
container_name: ewm-stats-db
ports:
- "6541:5432"
environment:
- POSTGRES_PASSWORD=ewm_stats
- POSTGRES_USER=ewm_stats
- POSTGRES_DB=stats

ewm-service:
ewm-main:
build: ewm-main-service
image: ewm_main_image
container_name: ewm_main_container
ports:
- "8080:8080"

depends_on:
- ewm-db
- ewm-stats
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://main-db:5433/ewm_main
- SPRING_DATASOURCE_USERNAME=ewm_main
- SPRING_DATASOURCE_PASSWORD=ewm_main
- STATS_SERVER_URL=http://stats-server:9090

ewm-db:
image: postgres:14-alpine
container_name: main-db
ports:
- "6542:5433"
environment:
- POSTGRES_PASSWORD=ewm_main
- POSTGRES_USER=ewm_main
- POSTGRES_DB=ewm_main
3 changes: 3 additions & 0 deletions main-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM amazoncorretto:11
COPY target/*.jar main-service.jar
ENTRYPOINT ["java", "-jar", "/main-service.jar"]
76 changes: 76 additions & 0 deletions main-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>main-service</artifactId>
<packaging>jar</packaging>

<name>main-service</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stats-client</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
14 changes: 14 additions & 0 deletions main-service/src/main/java/ru/practicum/ewm/EWMMainServiceApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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);
}

}
22 changes: 22 additions & 0 deletions main-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server.port=8080
logging.level.org.springframework.web.client.RestTemplate=info
logging.level.org.apache.http=DEBUG
logging.level.httpclient.wire=info
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.show_sql=true
spring.sql.init.mode=always
#---
db.name=ewm_main
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5433/${db.name}
spring.datasource.username=ewm_main
spring.datasource.password=ewm_main
#---
spring.config.activate.on-profile=ci,test
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:${db.name}
spring.datasource.username=ewm_main
spring.datasource.password=ewm_main
spring.h2.console.enabled=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ru.practicum.ewm;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Unit test for simple App.
*/
public class EWMMainServiceAppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public EWMMainServiceAppTest(String testName )
{
super( testName );
}

/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( EWMMainServiceAppTest.class );
}

/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
14 changes: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
<version>2.7.9</version>
<relativePath/>
</parent>

<name>Explore With Me</name>

<groupId>ru.practicum</groupId>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<java.version>11</java.version>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
<module>stats</module>
<module>main-service</module>
</modules>

<build>
<pluginManagement>
<plugins>
Expand Down
25 changes: 25 additions & 0 deletions stats/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>stats</artifactId>
<packaging>pom</packaging>

<name>stats</name>
<url>http://maven.apache.org</url>
<modules>
<module>stats-client</module>
<module>stats-dto</module>
<module>stats-server</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
43 changes: 43 additions & 0 deletions stats/stats-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>stats</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>stats-client</artifactId>
<name>stats-client</name>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stats-dto</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.practicum.ewm.client.stats;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.practicum.ewm.client.stats;

public class StatsClient {
// RestTemplate restTemplate;

// аналог baseclient, два метода, которые умеют общаться с endpoint из statsserver
}
33 changes: 33 additions & 0 deletions stats/stats-dto/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>stats</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>stats-dto</artifactId>
<name>stats-dto</name>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

</dependencies>
</project>
Loading

0 comments on commit e22ee56

Please sign in to comment.