Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# java-explore-with-me
Template repository for ExploreWithMe project.
Итоговый проект учебного курса. май 2025. гр. 53.
48 changes: 45 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
version: '3.1'
services:
stats-db:
image: postgres:16.1
container_name: postgres-stat
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=statdb
- POSTGRES_USER=statdb
- POSTGRES_DB=statdb
healthcheck:
test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER
timeout: 5s
interval: 5s
retries: 10

stats-server:
build: stats-server
image: stats-server
container_name: stats-server
ports:
- "9090:9090"

stats-db:
image: postgres:16.1
depends_on:
- stats-db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://stats-db:5432/statdb
- SPRING_DATASOURCE_USERNAME=statdb
- SPRING_DATASOURCE_PASSWORD=statdb

ewm-service:
build: ewm-service
image: ewm-service
container_name: ewm-service
ports:
- "8080:8080"
depends_on:
- stats-server
environment:
- STATSERVER_URL=http://stats-server:9090

ewm-db:
image: postgres:16.1
container_name: postgres-ewm
ports:
- "5434:5434"
environment:
- POSTGRES_PASSWORD=statewm
- POSTGRES_USER=statewm
- POSTGRES_DB=statewm
healthcheck:
test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER
timeout: 5s
interval: 5s
retries: 10

5 changes: 5 additions & 0 deletions ewm-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions ewm-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ewm-service
79 changes: 79 additions & 0 deletions ewm-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>ewm-service</artifactId>

<dependencies>
<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-actuator</artifactId>
</dependency>

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

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>

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

<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stat-dto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stat-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

</dependencies>

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

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.practicum.evmsevice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class EwmServiceApp {
public static void main(String[] args) {
SpringApplication.run(EwmServiceApp.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ru.practicum.evmsevice.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.util.DefaultUriBuilderFactory;
import ru.practicum.statclient.BaseClient;
import ru.practicum.statdto.HitDto;

import java.util.Map;

@Component
public class StatsClient extends BaseClient {
private static final String PREFIX_HIT = "/hit";
private static final String PREFIX_STATS = "/stats";

@Autowired
public StatsClient(@Value("${statserver.url}") String serverUrl, RestTemplateBuilder builder) {
super(
builder
.uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl))
.requestFactory(() -> new HttpComponentsClientHttpRequestFactory())
.build()
);
}

public void post(HitDto dto) {
makeAndSendRequest(HttpMethod.POST, PREFIX_HIT, null, dto);
}

public ResponseEntity<Object> get(Map<String, Object> parameters) {
return makeAndSendRequest(HttpMethod.GET, PREFIX_STATS, parameters, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ru.practicum.evmsevice.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ru.practicum.evmsevice.client.StatsClient;
import ru.practicum.statdto.HitDto;

import java.util.HashMap;
import java.util.Map;

/**
* Класс для проверки работы клиента сервера посещений
*/
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping
public class TestClientController {
private final StatsClient statsClient;

@PostMapping("/hit")
@ResponseStatus(HttpStatus.CREATED)
public void hit(@RequestBody HitDto dto) {
log.info("Поступила информация о посещении : " + dto.toString());
statsClient.post(dto);
}

@GetMapping("/stats")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Object> getStats(
@RequestParam(required = false) String start,
@RequestParam(required = false) String end,
@RequestParam(required = false) String uris,
@RequestParam(defaultValue = "false") Boolean unique,
@RequestParam(defaultValue = "10") Integer size) {
log.info("Запрашивается информация о посещении эндпоинта {} с {} до {}.", uris, start, end);

Map<String, Object> parameters = new HashMap<>();
if (start != null) parameters.put("start", start);
if (end != null) parameters.put("end", end);
if (uris != null) parameters.put("uris", uris);
if (unique != null) parameters.put("unique", unique);
if (size != null) parameters.put("size", size);
ResponseEntity<Object> response = statsClient.get(parameters);
return response;
}
}

2 changes: 2 additions & 0 deletions ewm-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server.port=8080
statserver.url=http://localhost:9090
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
</parent>

<name>Explore With Me</name>
<modules>
<module>stats-server</module>
<module>ewm-service</module>
</modules>

<groupId>ru.practicum</groupId>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
Expand Down
5 changes: 5 additions & 0 deletions stats-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM eclipse-temurin:21-jre-jammy
VOLUME /tmp
ARG JAR_FILE=stat-svc/target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"]
3 changes: 3 additions & 0 deletions stats-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# stats-server

модуль сервера статистики посещений
41 changes: 41 additions & 0 deletions stats-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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-server</artifactId>
<packaging>pom</packaging>
<modules>
<module>stat-dto</module>
<module>stat-svc</module>
<module>stat-client</module>
</modules>

<dependencies>

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

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

</dependencies>

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

</project>
3 changes: 3 additions & 0 deletions stats-server/stat-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# stat-client

модуль описания классов для подключения клиента.
56 changes: 56 additions & 0 deletions stats-server/stat-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>stat-client</artifactId>

<dependencies>
<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-actuator</artifactId>
</dependency>

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

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>

<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stat-dto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

</dependencies>

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

</project>
Loading