Skip to content

Commit

Permalink
1 iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
TY95MC committed Dec 27, 2023
1 parent 41c6ea8 commit e142f4c
Show file tree
Hide file tree
Showing 28 changed files with 761 additions and 10 deletions.
28 changes: 19 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
version: '3.1'
services:
stats-server:
ports:
- "9090:9090"

stats-db:
statistics-db:
image: postgres:14-alpine

ewm-service:
container_name: statistics_postgres_container
ports:
- "8080:8080"
- "6541:5432"
environment:
- POSTGRES_DB=statistics-db
- POSTGRES_USER=iamstatsroot
- POSTGRES_PASSWORD=iamstatsroot

ewm-db:
image: postgres:14-alpine
statistics-server:
build: statistics-service/statistics-server
image: statistics_server_image
container_name: statistics_server_container
ports:
- "9090:9090"
depends_on:
- statistics-db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://statistics-db:5432/statistics-db
- SPRING_DATASOURCE_USERNAME=iamstatsroot
- SPRING_DATASOURCE_PASSWORD=iamstatsroot
3 changes: 3 additions & 0 deletions event-service/DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM amazoncorretto:11-alpine-jdk
COPY target/*.jar event-service.jar
ENTRYPOINT ["java","-jar","/event-service.jar"]
44 changes: 44 additions & 0 deletions event-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>explore-with-me</artifactId>
<groupId>ru.practicum</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>event-service</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

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

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions event-service/src/main/java/ru/practicum/EventServiceApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.practicum;

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

@SpringBootApplication
public class EventServiceApp {
public static void main(String[] args) {
SpringApplication.run(EventServiceApp.class, args);
}
}
26 changes: 26 additions & 0 deletions event-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
server.port=8080
statistics-server.url=http://localhost:9090

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

logging.level.org.springframework.orm.jpa=INFO
logging.level.org.springframework.transaction=INFO
logging.level.org.springframework.transaction.interceptor=TRACE
logging.level.org.springframework.orm.jpa.JpaTransactionManager=DEBUG

#---
spring.config.activate.on-profile=dev
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/event-db
spring.datasource.username=iameventroot
spring.datasource.password=iameventroot
#---
spring.config.activate.on-profile=ci,test
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:event-db
spring.datasource.username=test
spring.datasource.password=test
92 changes: 91 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modules>
<module>event-service</module>
<module>statistics-service</module>
</modules>

<parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
Expand All @@ -17,6 +21,64 @@
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencies>
<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>

<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-starter-test</artifactId>
<scope>test</scope>
</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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.5.Final</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
</dependencies>

<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -34,6 +96,34 @@
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down
40 changes: 40 additions & 0 deletions statistics-service/dto-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>statistics-service</artifactId>
<groupId>ru.practicum</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

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

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

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

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

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public class InputEventDto {
private long id;
private String app;
private String uri;
private String ip;
private LocalDateTime requestDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.practicum.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Setter
public class OutputStatsDto {
private String app;
private String uri;
private long hits;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.practicum.exception;

public class EntityNotFoundException extends RuntimeException {

public EntityNotFoundException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.practicum.exception;

public class EntityValidationException extends RuntimeException {

public EntityValidationException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ru.practicum.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import ru.practicum.exception.model.ErrorResponse;

@RestControllerAdvice
public class ErrorHandler extends ResponseEntityExceptionHandler {

@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse handleEntityInvalidException(final EntityValidationException e) {
return new ErrorResponse(
e.getMessage()
);
}

@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
public ErrorResponse handleEntityNotFoundException(final EntityNotFoundException e) {
return new ErrorResponse(
e.getMessage()
);
}

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ErrorResponse handleUnexpectedException(final Throwable e) {
return new ErrorResponse(
"Произошла непредвиденная ошибка."
);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.practicum.exception.model;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class ErrorResponse {
private final String error;
}
Loading

0 comments on commit e142f4c

Please sign in to comment.