Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UpdateUserCommandHandler {
public void handle (UpdateUserCommand command) {

String userIdToUpdate = String.valueOf(readModel.getById(command.userId())
.map(UserDTO::riskLevel)
.map(UserDTO::userId)
.orElseThrow(() -> UserNotFound.with(command.userId())));
User user = this.eventStore.get(UserId.from(userIdToUpdate));
user.update(userIdToUpdate, command.riskLevel());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/autoinvestor/domain/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ protected void when(Event<?> event) {
}

private void whenUserCreated(UserWasRegisteredEvent event) {
if (this.state != null) {
if (this.state == null) {
this.state = UserState.empty();
}
assert this.state != null;
this.state = this.state.withUserCreated(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import io.autoinvestor.domain.events.Event;
import io.autoinvestor.domain.events.EventId;
import io.autoinvestor.domain.events.EventPayload;
import io.autoinvestor.domain.model.UserId;
import io.autoinvestor.domain.model.UserWasRegisteredEvent;
import io.autoinvestor.domain.model.UserWasRegisteredEventPayload;
import io.autoinvestor.domain.model.*;
import org.springframework.stereotype.Component;

import java.util.Date;
Expand Down Expand Up @@ -45,6 +43,11 @@ public Event<?> toDomain(EventDocument doc) {

return UserWasRegisteredEvent.hydrate(id, aggId, payload, occurred, version);
}
case UserWasUpdatedEvent.TYPE -> {
UserWasUpdatedEventPayload payload =
json.convertValue(doc.getPayload(), UserWasUpdatedEventPayload.class);
return UserWasUpdatedEvent.hydrate(id, aggId, payload, occurred, version);
}

default -> throw new IllegalArgumentException(
"Unknown event type: " + doc.getType()
Expand Down