-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ralf Ueberfuhr
committed
Jun 26, 2024
1 parent
d15260d
commit 16a468a
Showing
19 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.3.0</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>de.sample.schulung.spring</groupId> | ||
<artifactId>statistics-service-provider</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>Statistics Service Provider</name> | ||
<properties> | ||
<java.version>17</java.version> | ||
<mapstruct.version>1.5.5.Final</mapstruct.version> | ||
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version> | ||
</properties> | ||
<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-devtools</artifactId> | ||
<scope>runtime</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct</artifactId> | ||
<version>${mapstruct.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</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> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${lombok.version}</version> | ||
</path> | ||
<path> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct-processor</artifactId> | ||
<version>${mapstruct.version}</version> | ||
</path> | ||
<path> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok-mapstruct-binding</artifactId> | ||
<version>${lombok-mapstruct-binding.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</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> | ||
<exclude> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct</artifactId> | ||
</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...der/src/main/java/de/sample/schulung/statistics/StatisticsServiceProviderApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package de.sample.schulung.statistics; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class StatisticsServiceProviderApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(StatisticsServiceProviderApplication.class, args); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...-provider/src/main/java/de/sample/schulung/statistics/boundary/CustomerStatisticsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package de.sample.schulung.statistics.boundary; | ||
|
||
import lombok.Data; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Data | ||
public class CustomerStatisticsDto { | ||
|
||
private long count; | ||
private LocalDate earliestBirthdate; | ||
private LocalDate latestBirthdate; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...der/src/main/java/de/sample/schulung/statistics/boundary/CustomerStatisticsDtoMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.sample.schulung.statistics.boundary; | ||
|
||
import de.sample.schulung.statistics.domain.CustomerStatistics; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface CustomerStatisticsDtoMapper { | ||
|
||
CustomerStatisticsDto map(CustomerStatistics source); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...e-provider/src/main/java/de/sample/schulung/statistics/boundary/StatisticsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.sample.schulung.statistics.boundary; | ||
|
||
import de.sample.schulung.statistics.domain.CustomerStatisticsService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/statistics") | ||
@RequiredArgsConstructor | ||
public class StatisticsController { | ||
|
||
private final CustomerStatisticsService customerStatisticsService; | ||
private final CustomerStatisticsDtoMapper customerStatisticsDtoMapper; | ||
|
||
@GetMapping( | ||
value = "/customers", | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public CustomerStatisticsDto getStatistics() { | ||
return this.customerStatisticsDtoMapper | ||
.map( | ||
this.customerStatisticsService | ||
.getStatistics() | ||
); | ||
} | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
statistics-service-provider/src/main/java/de/sample/schulung/statistics/domain/Customer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.sample.schulung.statistics.domain; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public class Customer { | ||
|
||
@NotNull | ||
private UUID uuid; | ||
private LocalDate dateOfBirth; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...rvice-provider/src/main/java/de/sample/schulung/statistics/domain/CustomerStatistics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package de.sample.schulung.statistics.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Data | ||
@Builder | ||
public class CustomerStatistics { | ||
|
||
@Builder.Default | ||
private long count = 0; | ||
private LocalDate earliestBirthdate; | ||
private LocalDate latestBirthdate; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...rovider/src/main/java/de/sample/schulung/statistics/domain/CustomerStatisticsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.sample.schulung.statistics.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CustomerStatisticsService { | ||
|
||
private final CustomerStatisticsSink customerStatisticsSink; | ||
|
||
public CustomerStatistics getStatistics() { | ||
return customerStatisticsSink.getStatistics(); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...e-provider/src/main/java/de/sample/schulung/statistics/domain/CustomerStatisticsSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.sample.schulung.statistics.domain; | ||
|
||
public interface CustomerStatisticsSink { | ||
|
||
CustomerStatistics getStatistics(); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...ice-provider/src/main/java/de/sample/schulung/statistics/domain/CustomersInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.sample.schulung.statistics.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDate; | ||
import java.util.UUID; | ||
|
||
@Component | ||
@ConditionalOnProperty( | ||
name = "application.init-sample-data.enabled", | ||
havingValue = "true" | ||
) | ||
@RequiredArgsConstructor | ||
public class CustomersInitializer { | ||
|
||
private final CustomersService customersService; | ||
|
||
@EventListener(ContextRefreshedEvent.class) | ||
public void createSamples() { | ||
if (customersService.count() < 1) { | ||
customersService.saveCustomer( | ||
Customer.builder() | ||
.uuid(UUID.randomUUID()) | ||
.dateOfBirth(LocalDate.now().minusYears(20).minusDays(100)) | ||
.build() | ||
); | ||
customersService.saveCustomer( | ||
Customer.builder() | ||
.uuid(UUID.randomUUID()) | ||
.dateOfBirth(LocalDate.now().minusYears(30).minusDays(55)) | ||
.build() | ||
); | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...service-provider/src/main/java/de/sample/schulung/statistics/domain/CustomersService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.sample.schulung.statistics.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import java.util.UUID; | ||
|
||
@Validated | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CustomersService { | ||
|
||
private final CustomersSink customersSink; | ||
|
||
public void saveCustomer(Customer customer) { | ||
customersSink.saveCustomer(customer); | ||
} | ||
|
||
public void deleteCustomer(UUID uuid) { | ||
customersSink.deleteCustomer(uuid); | ||
} | ||
|
||
public long count() { | ||
return customersSink.count(); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...cs-service-provider/src/main/java/de/sample/schulung/statistics/domain/CustomersSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.sample.schulung.statistics.domain; | ||
|
||
import java.util.UUID; | ||
|
||
public interface CustomersSink { | ||
|
||
void saveCustomer(Customer customer); | ||
void deleteCustomer(UUID uuid); | ||
long count(); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...vice-provider/src/main/java/de/sample/schulung/statistics/persistence/CustomerEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.sample.schulung.statistics.persistence; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@Entity(name = "Customer") | ||
@Table(name = "CUSTOMERS") | ||
public class CustomerEntity { | ||
|
||
@NotNull | ||
@Id | ||
private UUID uuid; | ||
private LocalDate dateOfBirth; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...rovider/src/main/java/de/sample/schulung/statistics/persistence/CustomerEntityMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.sample.schulung.statistics.persistence; | ||
|
||
import de.sample.schulung.statistics.domain.Customer; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface CustomerEntityMapper { | ||
|
||
CustomerEntity map(Customer customer); | ||
|
||
} |
Oops, something went wrong.