BAEL-7547: formatting & code review
This commit is contained in:
parent
9502473ac2
commit
7d14d37fda
|
@ -17,7 +17,6 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.kafka</groupId>
|
<groupId>org.springframework.kafka</groupId>
|
||||||
<artifactId>spring-kafka</artifactId>
|
<artifactId>spring-kafka</artifactId>
|
||||||
|
@ -28,20 +27,27 @@
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
<version>${postgresql.version}</version>
|
<version>${postgresql.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.modulith</groupId>
|
<groupId>org.springframework.modulith</groupId>
|
||||||
<artifactId>spring-modulith-events-api</artifactId>
|
<artifactId>spring-modulith-events-api</artifactId>
|
||||||
<version>${spring-modulith-events-kafka.version}</version>
|
<version>${spring-modulith.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.modulith</groupId>
|
<groupId>org.springframework.modulith</groupId>
|
||||||
<artifactId>spring-modulith-events-kafka</artifactId>
|
<artifactId>spring-modulith-events-kafka</artifactId>
|
||||||
<version>${spring-modulith-events-kafka.version}</version>
|
<version>${spring-modulith.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.modulith</groupId>
|
<groupId>org.springframework.modulith</groupId>
|
||||||
<artifactId>spring-modulith-starter-jpa</artifactId>
|
<artifactId>spring-modulith-starter-jpa</artifactId>
|
||||||
<version>${spring-modulith-events-kafka.version}</version>
|
<version>${spring-modulith.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.modulith</groupId>
|
||||||
|
<artifactId>spring-modulith-starter-test</artifactId>
|
||||||
|
<version>${spring-modulith.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -54,20 +60,6 @@
|
||||||
<artifactId>spring-boot-testcontainers</artifactId>
|
<artifactId>spring-boot-testcontainers</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.modulith</groupId>
|
|
||||||
<artifactId>spring-modulith-starter-test</artifactId>
|
|
||||||
<version>1.1.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
<version>2.2.224</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testcontainers</groupId>
|
<groupId>org.testcontainers</groupId>
|
||||||
<artifactId>kafka</artifactId>
|
<artifactId>kafka</artifactId>
|
||||||
|
@ -86,7 +78,6 @@
|
||||||
<version>${testcontainers.version}</version>
|
<version>${testcontainers.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testcontainers</groupId>
|
<groupId>org.testcontainers</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
|
@ -100,16 +91,23 @@
|
||||||
<version>${awaitility.version}</version>
|
<version>${awaitility.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>${h2.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<spring-boot.version>3.1.5</spring-boot.version>
|
<spring-boot.version>3.1.5</spring-boot.version>
|
||||||
<spring-modulith-events-kafka.version>1.1.2</spring-modulith-events-kafka.version>
|
<spring-modulith.version>1.1.3</spring-modulith.version>
|
||||||
<testcontainers.version>1.19.3</testcontainers.version>
|
<testcontainers.version>1.19.3</testcontainers.version>
|
||||||
<awaitility.version>4.2.0</awaitility.version>
|
<awaitility.version>4.2.0</awaitility.version>
|
||||||
<postgresql.version>42.3.1</postgresql.version>
|
<postgresql.version>42.3.1</postgresql.version>
|
||||||
|
<h2.version>2.2.224</h2.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
package com.baeldung.springmodulith.application.events.orders;
|
package com.baeldung.springmodulith.application.events.orders;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class OrderRepository {
|
class OrderRepository {
|
||||||
private final List<Order> orders = new ArrayList<>();
|
private final List<Order> orders = new ArrayList<>();
|
||||||
|
|
||||||
public Order save(Order order) {
|
public Order save(Order order) {
|
||||||
order = new Order(UUID.randomUUID().toString(), order.customerId(), order.productIds(), order.timestamp());
|
order = new Order(UUID.randomUUID()
|
||||||
|
.toString(), order.customerId(), order.productIds(), order.timestamp());
|
||||||
orders.add(order);
|
orders.add(order);
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Order> ordersByCustomer(String customerId) {
|
public List<Order> ordersByCustomer(String customerId) {
|
||||||
return orders.stream()
|
return orders.stream()
|
||||||
.filter(it -> it.customerId().equals(customerId))
|
.filter(it -> it.customerId()
|
||||||
|
.equals(customerId))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.baeldung.springmodulith.application.events.orders;
|
package com.baeldung.springmodulith.application.events.orders;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class OrderService {
|
public class OrderService {
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.baeldung.springmodulith.application.events.rewards;
|
package com.baeldung.springmodulith.application.events.rewards;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class LoyalCustomersRepository {
|
public class LoyalCustomersRepository {
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@ public class LoyalCustomersRepository {
|
||||||
|
|
||||||
public Optional<LoyalCustomer> find(String customerId) {
|
public Optional<LoyalCustomer> find(String customerId) {
|
||||||
return customers.stream()
|
return customers.stream()
|
||||||
.filter(it -> it.customerId().equals(customerId))
|
.filter(it -> it.customerId()
|
||||||
|
.equals(customerId))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void awardPoints(String customerId, int points) {
|
public void awardPoints(String customerId, int points) {
|
||||||
var customer = find(customerId)
|
var customer = find(customerId).orElseGet(() -> save(new LoyalCustomer(customerId, 0)));
|
||||||
.orElseGet(() -> save(new LoyalCustomer(customerId, 0)));
|
|
||||||
|
|
||||||
customers.remove(customer);
|
customers.remove(customer);
|
||||||
customers.add(customer.addPoints(points));
|
customers.add(customer.addPoints(points));
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package com.baeldung.springmodulith.application.events.rewards;
|
package com.baeldung.springmodulith.application.events.rewards;
|
||||||
|
|
||||||
import com.baeldung.springmodulith.application.events.orders.OrderCompletedEvent;
|
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.baeldung.springmodulith.application.events.orders.OrderCompletedEvent;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class LoyaltyPointsService {
|
public class LoyaltyPointsService {
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
|
|
||||||
import com.baeldung.springmodulith.application.events.orders.OrderCompletedEvent;
|
import com.baeldung.springmodulith.application.events.orders.OrderCompletedEvent;
|
||||||
import com.baeldung.springmodulith.application.events.rewards.LoyalCustomersRepository;
|
import com.baeldung.springmodulith.application.events.rewards.LoyalCustomersRepository;
|
||||||
|
|
Loading…
Reference in New Issue