From e22ee56d61a451c176c2299c3ef84d52d84c13e3 Mon Sep 17 00:00:00 2001 From: "MAGNAT\\sergey_ra" Date: Tue, 23 Apr 2024 19:00:26 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A7=D0=B0=D1=81=D1=82=D1=8C1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 42 +++++++++- main-service/Dockerfile | 3 + main-service/pom.xml | 76 +++++++++++++++++++ .../ru/practicum/ewm/EWMMainServiceApp.java | 14 ++++ .../src/main/resources/application.properties | 22 ++++++ .../practicum/ewm/EWMMainServiceAppTest.java | 38 ++++++++++ pom.xml | 14 +++- stats/pom.xml | 25 ++++++ stats/stats-client/pom.xml | 43 +++++++++++ .../ru/practicum/ewm/client/stats/App.java | 13 ++++ .../ewm/client/stats/StatsClient.java | 7 ++ stats/stats-dto/pom.xml | 33 ++++++++ .../java/ru/practicum/dto/EndpointHit.java | 29 +++++++ .../main/java/ru/practicum/dto/ViewStats.java | 14 ++++ stats/stats-server/Dockerfile | 3 + stats/stats-server/pom.xml | 75 ++++++++++++++++++ .../ewm/stats/EWMStatsServiceApp.java | 11 +++ .../practicum/ewm/stats/mapper/HitMapper.java | 33 ++++++++ .../ru/practicum/ewm/stats/model/Hit.java | 38 ++++++++++ .../stats/repository/HitJpaRepository.java | 36 +++++++++ .../ewm/stats/service/StatsService.java | 14 ++++ .../ewm/stats/service/StatsServiceImpl.java | 59 ++++++++++++++ .../practicum/ewm/stats/utils/Constant.java | 11 +++ .../src/main/resources/application.properties | 22 ++++++ .../src/main/resources/schema.sql | 8 ++ 25 files changed, 677 insertions(+), 6 deletions(-) create mode 100644 main-service/Dockerfile create mode 100644 main-service/pom.xml create mode 100644 main-service/src/main/java/ru/practicum/ewm/EWMMainServiceApp.java create mode 100644 main-service/src/main/resources/application.properties create mode 100644 main-service/src/test/java/ru/practicum/ewm/EWMMainServiceAppTest.java create mode 100644 stats/pom.xml create mode 100644 stats/stats-client/pom.xml create mode 100644 stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/App.java create mode 100644 stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/StatsClient.java create mode 100644 stats/stats-dto/pom.xml create mode 100644 stats/stats-dto/src/main/java/ru/practicum/dto/EndpointHit.java create mode 100644 stats/stats-dto/src/main/java/ru/practicum/dto/ViewStats.java create mode 100644 stats/stats-server/Dockerfile create mode 100644 stats/stats-server/pom.xml create mode 100644 stats/stats-server/src/main/java/ru/practicum/ewm/stats/EWMStatsServiceApp.java create mode 100644 stats/stats-server/src/main/java/ru/practicum/ewm/stats/mapper/HitMapper.java create mode 100644 stats/stats-server/src/main/java/ru/practicum/ewm/stats/model/Hit.java create mode 100644 stats/stats-server/src/main/java/ru/practicum/ewm/stats/repository/HitJpaRepository.java create mode 100644 stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsService.java create mode 100644 stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsServiceImpl.java create mode 100644 stats/stats-server/src/main/java/ru/practicum/ewm/stats/utils/Constant.java create mode 100644 stats/stats-server/src/main/resources/application.properties create mode 100644 stats/stats-server/src/main/resources/schema.sql diff --git a/docker-compose.yml b/docker-compose.yml index b387e1a6..110ee8c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/main-service/Dockerfile b/main-service/Dockerfile new file mode 100644 index 00000000..4049bfc8 --- /dev/null +++ b/main-service/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:11 +COPY target/*.jar main-service.jar +ENTRYPOINT ["java", "-jar", "/main-service.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..9d1231c2 --- /dev/null +++ b/main-service/pom.xml @@ -0,0 +1,76 @@ + + 4.0.0 + + + ru.practicum + explore-with-me + 0.0.1-SNAPSHOT + ../pom.xml + + + main-service + jar + + main-service + http://maven.apache.org + + + UTF-8 + + + + + + ru.practicum + stats-client + ${project.version} + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.postgresql + postgresql + runtime + + + + com.h2database + h2 + runtime + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + junit + junit + 3.8.1 + test + + + 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..7d415b34 --- /dev/null +++ b/main-service/src/main/java/ru/practicum/ewm/EWMMainServiceApp.java @@ -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); + } + +} diff --git a/main-service/src/main/resources/application.properties b/main-service/src/main/resources/application.properties new file mode 100644 index 00000000..48d98fb1 --- /dev/null +++ b/main-service/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/main-service/src/test/java/ru/practicum/ewm/EWMMainServiceAppTest.java b/main-service/src/test/java/ru/practicum/ewm/EWMMainServiceAppTest.java new file mode 100644 index 00000000..8fb374d8 --- /dev/null +++ b/main-service/src/test/java/ru/practicum/ewm/EWMMainServiceAppTest.java @@ -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 ); + } +} diff --git a/pom.xml b/pom.xml index ad386209..46b25385 100644 --- a/pom.xml +++ b/pom.xml @@ -6,22 +6,30 @@ org.springframework.boot spring-boot-starter-parent - 2.7.5 - + 2.7.9 + Explore With Me - ru.practicum + ru.practicum explore-with-me 0.0.1-SNAPSHOT pom 11 + 11 + 11 + 11 UTF-8 + + stats + main-service + + diff --git a/stats/pom.xml b/stats/pom.xml new file mode 100644 index 00000000..12701931 --- /dev/null +++ b/stats/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + ru.practicum + explore-with-me + 0.0.1-SNAPSHOT + + + stats + pom + + stats + http://maven.apache.org + + stats-client + stats-dto + stats-server + + + + UTF-8 + + + diff --git a/stats/stats-client/pom.xml b/stats/stats-client/pom.xml new file mode 100644 index 00000000..3d382b99 --- /dev/null +++ b/stats/stats-client/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + + ru.practicum + stats + 0.0.1-SNAPSHOT + + + stats-client + stats-client + + + 11 + 11 + UTF-8 + + + + + + ru.practicum + stats-dto + ${project.version} + + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-web + + + + diff --git a/stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/App.java b/stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/App.java new file mode 100644 index 00000000..a1ce0d64 --- /dev/null +++ b/stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/App.java @@ -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!" ); + } +} diff --git a/stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/StatsClient.java b/stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/StatsClient.java new file mode 100644 index 00000000..606fb83a --- /dev/null +++ b/stats/stats-client/src/main/java/ru/practicum/ewm/client/stats/StatsClient.java @@ -0,0 +1,7 @@ +package ru.practicum.ewm.client.stats; + +public class StatsClient { +// RestTemplate restTemplate; + + // аналог baseclient, два метода, которые умеют общаться с endpoint из statsserver +} diff --git a/stats/stats-dto/pom.xml b/stats/stats-dto/pom.xml new file mode 100644 index 00000000..9eae9a32 --- /dev/null +++ b/stats/stats-dto/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + ru.practicum + stats + 0.0.1-SNAPSHOT + + + stats-dto + stats-dto + + + 11 + 11 + UTF-8 + + + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-validation + + + + diff --git a/stats/stats-dto/src/main/java/ru/practicum/dto/EndpointHit.java b/stats/stats-dto/src/main/java/ru/practicum/dto/EndpointHit.java new file mode 100644 index 00000000..b31eaa72 --- /dev/null +++ b/stats/stats-dto/src/main/java/ru/practicum/dto/EndpointHit.java @@ -0,0 +1,29 @@ +package ru.practicum.dto; + +import lombok.Builder; +import lombok.Value; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +@Builder(toBuilder = true) +@Value +public class EndpointHit { + + Long id; + + @NotNull + @Size(max = 255) + String app; + + @NotNull + @Size(max = 512) + String uri; + + @NotNull + @Size(max = 16) + String ip; + + @NotNull + String timestamp; +} diff --git a/stats/stats-dto/src/main/java/ru/practicum/dto/ViewStats.java b/stats/stats-dto/src/main/java/ru/practicum/dto/ViewStats.java new file mode 100644 index 00000000..e6c09075 --- /dev/null +++ b/stats/stats-dto/src/main/java/ru/practicum/dto/ViewStats.java @@ -0,0 +1,14 @@ +package ru.practicum.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Value; + +@Builder(toBuilder = true) +@Value +@AllArgsConstructor +public class ViewStats { + String app; + String uri; + Long hits; +} diff --git a/stats/stats-server/Dockerfile b/stats/stats-server/Dockerfile new file mode 100644 index 00000000..2c3f349d --- /dev/null +++ b/stats/stats-server/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:11 +COPY target/*.jar stats-server.jar +ENTRYPOINT ["java", "-jar", "/stats-server.jar"] \ No newline at end of file diff --git a/stats/stats-server/pom.xml b/stats/stats-server/pom.xml new file mode 100644 index 00000000..75c42b74 --- /dev/null +++ b/stats/stats-server/pom.xml @@ -0,0 +1,75 @@ + + 4.0.0 + + ru.practicum + stats + 0.0.1-SNAPSHOT + + + stats-server + jar + stats-server + + + 11 + 11 + UTF-8 + + + + + + ru.practicum + stats-dto + ${project.version} + compile + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.postgresql + postgresql + runtime + + + + com.h2database + h2 + runtime + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + diff --git a/stats/stats-server/src/main/java/ru/practicum/ewm/stats/EWMStatsServiceApp.java b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/EWMStatsServiceApp.java new file mode 100644 index 00000000..d4caec77 --- /dev/null +++ b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/EWMStatsServiceApp.java @@ -0,0 +1,11 @@ +package ru.practicum.ewm.stats; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class EWMStatsServiceApp { + public static void main(String[] args) { + SpringApplication.run(EWMStatsServiceApp.class, args); + } +} diff --git a/stats/stats-server/src/main/java/ru/practicum/ewm/stats/mapper/HitMapper.java b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/mapper/HitMapper.java new file mode 100644 index 00000000..e08f4334 --- /dev/null +++ b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/mapper/HitMapper.java @@ -0,0 +1,33 @@ +package ru.practicum.ewm.stats.mapper; + +import ru.practicum.dto.EndpointHit; +import ru.practicum.ewm.stats.model.Hit; + +import java.time.LocalDateTime; + +import static ru.practicum.ewm.stats.utils.Constant.DATE_TIME_FORMATTER; + +public class HitMapper { + + + public static Hit toHit(EndpointHit endpointHit) { + return Hit.builder() + .id(endpointHit.getId()) + .app(endpointHit.getApp()) + .uri(endpointHit.getUri()) + .ip(endpointHit.getIp()) + .timestamp(LocalDateTime.parse(endpointHit.getTimestamp(), DATE_TIME_FORMATTER)) + .build(); + } + + public static EndpointHit toEndpointHit(Hit hit) { + return EndpointHit.builder() + .id(hit.getId()) + .app(hit.getApp()) + .uri(hit.getUri()) + .ip(hit.getIp()) + .timestamp(hit.getTimestamp().format(DATE_TIME_FORMATTER)) + .build(); + } + +} diff --git a/stats/stats-server/src/main/java/ru/practicum/ewm/stats/model/Hit.java b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/model/Hit.java new file mode 100644 index 00000000..cf5eeab2 --- /dev/null +++ b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/model/Hit.java @@ -0,0 +1,38 @@ +package ru.practicum.ewm.stats.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.time.LocalDateTime; + +@Entity +@Table(name = "hits") +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +public class Hit { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(name = "app", nullable = false) + private String app; + + @Column(name = "uri", length = 512, nullable = false) + private String uri; + + @Column(name = "ip", length = 16, nullable = false) + private String ip; + + @Column(name = "timestamp", nullable = false) + private LocalDateTime timestamp; +} diff --git a/stats/stats-server/src/main/java/ru/practicum/ewm/stats/repository/HitJpaRepository.java b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/repository/HitJpaRepository.java new file mode 100644 index 00000000..9e5afc93 --- /dev/null +++ b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/repository/HitJpaRepository.java @@ -0,0 +1,36 @@ +package ru.practicum.ewm.stats.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; +import ru.practicum.ewm.stats.model.Hit; + +import java.time.LocalDateTime; +import java.util.List; + +@Repository +public interface HitJpaRepository extends JpaRepository { + + @Query(value = "SELECT h.app, h.uri, COUNT(h.*) " + + "FROM hits AS h " + + "WHERE h.timestamp >= ?1 AND h.timestamp <= ?2 AND " + + "(0 = ?3 OR h.uri in ?4) " + + "GROUP BY h.app, h.uri " + + "ORDER BY COUNT(h.*) DESC" + , nativeQuery = true) + List findStatisticsBetweenStartAndEnd(LocalDateTime start, LocalDateTime end, int isUris, List uris); + + @Query(value = "SELECT v.app, v.uri, COUNT(v.*) " + + "FROM ( " + + "SELECT DISTINCT h.ip, h.app, h.uri " + + "FROM hits AS h " + + "WHERE timestamp >= ?1 AND timestamp <= ?2 AND " + + "(0 = ?3 OR h.uri in ?4) " + + ") AS v " + + "GROUP BY v.app, v.uri " + + "ORDER BY COUNT(v.*) DESC" + , nativeQuery = true) + List findStatisticsBetweenStartAndEndUniqueIp(LocalDateTime start, LocalDateTime end, int isUris, List uris); + + +} \ No newline at end of file diff --git a/stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsService.java b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsService.java new file mode 100644 index 00000000..52087f28 --- /dev/null +++ b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsService.java @@ -0,0 +1,14 @@ +package ru.practicum.ewm.stats.service; + +import ru.practicum.dto.EndpointHit; +import ru.practicum.dto.ViewStats; + +import java.time.LocalDateTime; +import java.util.List; + +public interface StatsService { + + EndpointHit create(EndpointHit endpointHit); + + List getStats(LocalDateTime start, LocalDateTime end, List uris, boolean required); +} diff --git a/stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsServiceImpl.java b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsServiceImpl.java new file mode 100644 index 00000000..dea459a9 --- /dev/null +++ b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/service/StatsServiceImpl.java @@ -0,0 +1,59 @@ +package ru.practicum.ewm.stats.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.practicum.dto.EndpointHit; +import ru.practicum.dto.ViewStats; +import ru.practicum.ewm.stats.mapper.HitMapper; +import ru.practicum.ewm.stats.model.Hit; +import ru.practicum.ewm.stats.repository.HitJpaRepository; + +import java.math.BigInteger; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Service +@RequiredArgsConstructor +@Slf4j +public class StatsServiceImpl implements StatsService { + + private final HitJpaRepository hitJpaRepository; + + @Override + public EndpointHit create(EndpointHit endpointHit) { + Hit hit = HitMapper.toHit(endpointHit); + hit = hitJpaRepository.save(hit); + log.info("Create endpoint hit {}", hit); + return HitMapper.toEndpointHit(hit); + } + + @Override + @Transactional(readOnly = true) + public List getStats(LocalDateTime start, LocalDateTime end, List uris, boolean unique) { + + int isSearchUrl = (uris == null || uris.isEmpty() ? 0 : 1); + List list = unique ? + hitJpaRepository.findStatisticsBetweenStartAndEndUniqueIp(start, end, isSearchUrl, uris) : + hitJpaRepository.findStatisticsBetweenStartAndEnd(start, end, isSearchUrl, uris); + + List stats = convertViewStatesFromObject(list); + log.info("stats --> {}", stats); + return stats; + } + + private List convertViewStatesFromObject(List list) { + List result = new ArrayList<>(); + if (list != null && !list.isEmpty()) { + list.stream() + .map(object -> result.add(new ViewStats( + (String) object[0], + (String) object[1], + ((BigInteger) object[2]).longValue()))).toArray(); + } + return result; + } + +} diff --git a/stats/stats-server/src/main/java/ru/practicum/ewm/stats/utils/Constant.java b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/utils/Constant.java new file mode 100644 index 00000000..78924b20 --- /dev/null +++ b/stats/stats-server/src/main/java/ru/practicum/ewm/stats/utils/Constant.java @@ -0,0 +1,11 @@ +package ru.practicum.ewm.stats.utils; + +import java.time.format.DateTimeFormatter; + +public class Constant { + + public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + + +} diff --git a/stats/stats-server/src/main/resources/application.properties b/stats/stats-server/src/main/resources/application.properties new file mode 100644 index 00000000..42a7acef --- /dev/null +++ b/stats/stats-server/src/main/resources/application.properties @@ -0,0 +1,22 @@ +server.port=9090 +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_stats +spring.datasource.driverClassName=org.postgresql.Driver +spring.datasource.url=jdbc:postgresql://localhost:5432/${db.name} +spring.datasource.username=ewm_stats +spring.datasource.password=ewm_stats +#--- +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_stats +spring.datasource.password=ewm_stats +spring.h2.console.enabled=true \ No newline at end of file diff --git a/stats/stats-server/src/main/resources/schema.sql b/stats/stats-server/src/main/resources/schema.sql new file mode 100644 index 00000000..36fca718 --- /dev/null +++ b/stats/stats-server/src/main/resources/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS hits ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, + app VARCHAR(255) NOT NULL, + uri VARCHAR(512) NOT NULL, + ip VARCHAR(16) NOT NULL, + timestamp timestamp NOT NULL, + CONSTRAINT pk_hits_id PRIMARY KEY (id) + ); \ No newline at end of file