Refactor. | lol digg (C) whatthecommit.com

This commit is contained in:
Maksim Kostromin
2019-08-01 03:15:14 +03:00
parent a465108209
commit 0297e4498d
3 changed files with 8 additions and 4 deletions

View File

@@ -13,3 +13,7 @@ http :8080
```
**NOTE:** _For better developer experience during testing, use idea cURL integration tests from `rest-client*` files. Read more: https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html_
resources:
* [YouTube: Building Event Driven Systems with Spring Cloud Stream](https://www.youtube.com/watch?v=LvmPa7YKgqM&t=2673s)

View File

@@ -98,8 +98,7 @@ public class User implements Function<DomainEvent, User> {
/* es */
public static User recreate(UUID userId, Collection<DomainEvent> domainEvents) {
User snapshot = new User(userId);
public static User recreate(User snapshot, Collection<DomainEvent> domainEvents) {
return io.vavr.collection.List.ofAll(domainEvents)
.foldLeft(snapshot, User::apply);
}

View File

@@ -26,8 +26,9 @@ public class InMemoryUserRepository implements UserRepository {
@Override
public User find(UUID userId) {
User snapshot = new User();
return eventStore.containsKey(userId)
? User.recreate(userId, eventStore.get(userId))
: null;
? User.recreate(snapshot, eventStore.get(userId))
: snapshot;
}
}