Skip to content

Commit fc46d5c

Browse files
committed
fix2
1 parent 99eee69 commit fc46d5c

13 files changed

Lines changed: 138 additions & 10 deletions

File tree

docker-compose.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,32 @@ services:
2525
environment:
2626
STATS_DB_URL: jdbc:postgresql://stats-db:5432/statsdb
2727
STATS_DB_USER: postgres
28-
STATS_DB_PASSWORD: password
28+
STATS_DB_PASSWORD: password
29+
30+
ewm-db:
31+
image: postgres:16.1
32+
container_name: ewm-db
33+
ports:
34+
- "5433:5432"
35+
environment:
36+
POSTGRES_DB: ewmdb
37+
POSTGRES_USER: postgres
38+
POSTGRES_PASSWORD: password
39+
healthcheck:
40+
test: ["CMD-SHELL", "pg_isready -U postgres"]
41+
interval: 10s
42+
timeout: 5s
43+
retries: 5
44+
45+
ewm-service:
46+
build: ./ewm-service
47+
container_name: ewm-service
48+
ports:
49+
- "8080:8080"
50+
depends_on:
51+
ewm-db:
52+
condition: service_healthy
53+
environment:
54+
SPRING_DATASOURCE_URL: jdbc:postgresql://ewm-db:5432/ewmdb
55+
SPRING_DATASOURCE_USERNAME: postgres
56+
SPRING_DATASOURCE_PASSWORD: password

ewm-service/Dockerfile

Lines changed: 5 additions & 0 deletions
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"]

ewm-service/pom.xml

Lines changed: 40 additions & 0 deletions
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>ru.practicum</groupId>
9+
<artifactId>explore-with-me</artifactId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>ewm-service</artifactId>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-actuator</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.projectlombok</groupId>
27+
<artifactId>lombok</artifactId>
28+
<optional>true</optional>
29+
</dependency>
30+
</dependencies>
31+
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>
Lines changed: 11 additions & 0 deletions
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+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.port=8080
2+
spring.application.name=ewm-service

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<module>statistics/dto</module>
2727
<module>statistics/client</module>
2828
<module>statistics/server</module>
29+
<module>ewm-service</module>
2930
</modules>
3031

3132
<build>

statistics/client/src/main/java/ru/practicum/statistics/client/StatsClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
@Service
2020
public class StatsClient {
21+
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
22+
2123
private final RestTemplate rest;
2224
private final String serverUrl;
2325

@@ -33,9 +35,8 @@ public void sendHit(EndpointHit hit) {
3335
}
3436

3537
public List<ViewStats> getStats(LocalDateTime start, LocalDateTime end, List<String> uris, boolean unique) {
36-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
37-
String startStr = URLEncoder.encode(start.format(formatter), StandardCharsets.UTF_8);
38-
String endStr = URLEncoder.encode(end.format(formatter), StandardCharsets.UTF_8);
38+
String startStr = URLEncoder.encode(start.format(DATE_TIME_FORMATTER), StandardCharsets.UTF_8);
39+
String endStr = URLEncoder.encode(end.format(DATE_TIME_FORMATTER), StandardCharsets.UTF_8);
3940

4041
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(serverUrl + "/stats")
4142
.queryParam("start", startStr)

statistics/dto/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
<groupId>com.fasterxml.jackson.core</groupId>
2424
<artifactId>jackson-annotations</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>jakarta.validation</groupId>
28+
<artifactId>jakarta.validation-api</artifactId>
29+
</dependency>
2630
</dependencies>
2731
</project>

statistics/dto/src/main/java/ru/practicum/statistics/dto/EndpointHit.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package ru.practicum.statistics.dto;
22

33
import com.fasterxml.jackson.annotation.JsonFormat;
4+
import jakarta.validation.constraints.NotBlank;
5+
import jakarta.validation.constraints.NotNull;
46
import lombok.AllArgsConstructor;
57
import lombok.Data;
68
import lombok.NoArgsConstructor;
@@ -12,9 +14,17 @@
1214
@AllArgsConstructor
1315
public class EndpointHit {
1416
private Long id;
17+
18+
@NotBlank(message = "Название приложения не может быть пустым")
1519
private String app;
20+
21+
@NotBlank(message = "URI не может быть пустым")
1622
private String uri;
23+
24+
@NotBlank(message = "IP-адрес не может быть пустым")
1725
private String ip;
26+
27+
@NotNull(message = "Временная метка не может быть null")
1828
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
1929
private LocalDateTime timestamp;
2030
}

statistics/server/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
<artifactId>lombok</artifactId>
4343
<optional>true</optional>
4444
</dependency>
45-
4645
<dependency>
4746
<groupId>org.springframework.boot</groupId>
4847
<artifactId>spring-boot-starter-test</artifactId>

0 commit comments

Comments
 (0)