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
20 changes: 14 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.security:spring-security-core:'
implementation 'io.jsonwebtoken:jjwt:0.12.6'
implementation 'io.github.cdimascio:java-dotenv:5.2.2'
implementation platform("com.google.cloud:spring-cloud-gcp-dependencies:6.1.1")
implementation 'com.google.cloud:spring-cloud-gcp-starter-pubsub'

implementation 'com.google.cloud:google-cloud-pubsub:1.123.0'
implementation "com.google.cloud:spring-cloud-gcp-starter-pubsub:6.1.1"
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'org.springframework.integration:spring-integration-core'
implementation 'com.google.cloud:google-cloud-pubsub:1.113.7'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:gcloud'

compileOnly 'org.projectlombok:lombok:1.18.38'
annotationProcessor 'org.projectlombok:lombok:1.18.38'

testCompileOnly 'org.projectlombok:lombok:1.18.38'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.38'
}

tasks.named('test') {
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/io/autoinvestor/application/PasswordService.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.autoinvestor.application.RegisterUserUseCase;

import io.autoinvestor.application.UserDTO;
import io.autoinvestor.application.UsersReadModel;
import io.autoinvestor.domain.Event;
import io.autoinvestor.domain.EventPublisher;
import io.autoinvestor.domain.UserRepository;
import io.autoinvestor.domain.users.User;
import io.autoinvestor.domain.events.Event;
import io.autoinvestor.domain.events.EventPublisher;
import io.autoinvestor.domain.EventStore;
import io.autoinvestor.domain.model.User;
import io.autoinvestor.exceptions.BadRequestException;
import io.autoinvestor.infrastructure.UserCreatedEventMessageMapper;
import io.autoinvestor.infrastructure.UserCreatedMessage;
import io.autoinvestor.infrastructure.UsersEventPublisher;
import java.util.List;

import lombok.RequiredArgsConstructor;
Expand All @@ -18,25 +16,36 @@
@RequiredArgsConstructor
public class RegisterUserCommandHandler {

private final UserRepository repository;
private final EventStore eventStore;
private final EventPublisher eventPublisher;
private final UsersEventPublisher usersEventPublisher;
private final UserCreatedEventMessageMapper userCreatedEventMessageMapper;
private final UsersReadModel usersReadModel;
private final UsersReadModel readModel;

public void handle(RegisterUserCommand command) {
if (command.email() == null || command.email().isBlank()) {
throw new BadRequestException("Email cannot be null or empty");
}
if (usersReadModel.get(command.email()) != null) {

if (this.readModel.get(command.email()).isPresent()) {
throw UserRegisteredAlreadyExists.with(command.email());
}

User user = User.create(command.firstName(), command.lastName(), command.email(), command.riskLevel());
List<Event<?>> uncommittedEvents = user.releaseEvents();
this.repository.save(uncommittedEvents);
this.eventPublisher.publish(uncommittedEvents);
List<UserCreatedMessage> userCreatedMessages = this.userCreatedEventMessageMapper.map(uncommittedEvents);
this.usersEventPublisher.publishUserCreated(userCreatedMessages);

List<Event<?>> events = user.getUncommittedEvents();

this.eventStore.save(user);

UserDTO dto = new UserDTO(
user.getState().userId().value(),
command.email(),
command.firstName(),
command.lastName(),
command.riskLevel()
);
this.readModel.save(dto);

this.eventPublisher.publish(events);

user.markEventsAsCommitted();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.autoinvestor.application.RequestUserById;

import io.autoinvestor.application.UserNotFound;
import io.autoinvestor.application.UserDTO;
import io.autoinvestor.application.UsersReadModel;
import io.autoinvestor.ui.UserResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GetUserByIdQueryHandler {
private final UsersReadModel readModel;

public UserResponse handle (GetUserByIdQuery query) {
UserDTO dto = this.readModel.getById(query.userId())
.orElseThrow(() -> UserNotFound.with(query.userId()));

return new UserResponse(
dto.userId(),
dto.firstName(),
dto.lastName(),
dto.email(),
dto.riskLevel()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.autoinvestor.application.RequestUserUseCase;

import io.autoinvestor.application.UserDTO;
import io.autoinvestor.application.UserNotFound;
import io.autoinvestor.application.UsersReadModel;
import io.autoinvestor.ui.user.UserResponse;
import io.autoinvestor.ui.UserResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -11,10 +13,16 @@ public class GetUserQueryHandler {

private final UsersReadModel usersReadModel;

public UserResponse handle(GetUserQuery getUserQuery) {
if (usersReadModel.get(getUserQuery.email()) == null) {
throw UserNotFound.with(getUserQuery.email());
}
return usersReadModel.get(getUserQuery.email());
public UserResponse handle(GetUserQuery query) {
UserDTO dto = this.usersReadModel.get(query.email())
.orElseThrow(() -> UserNotFound.with(query.email()));

return new UserResponse(
dto.userId(),
dto.firstName(),
dto.lastName(),
dto.email(),
dto.riskLevel()
);
}
}

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/io/autoinvestor/application/UserDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.autoinvestor.application;

public record UserDTO(String userId,
String email,
String firstName,
String lastName,
int riskLevel) {
}
12 changes: 12 additions & 0 deletions src/main/java/io/autoinvestor/application/UserNotFound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.autoinvestor.application;

public class UserNotFound extends RuntimeException {
private UserNotFound(String message) {
super(message);
}

public static UserNotFound with(String name) {
String message = "User with id/email " + name + " doesn't exist.";
return new UserNotFound(message);
}
}
12 changes: 5 additions & 7 deletions src/main/java/io/autoinvestor/application/UsersReadModel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.autoinvestor.application;

import io.autoinvestor.infrastructure.UserReadModelDocument;
import io.autoinvestor.ui.user.UserResponse;

public interface UsersReadModel {

void add(UserReadModelDocument document);
import java.util.Optional;

UserResponse get(String email);
UserResponse getById(String userId);
public interface UsersReadModel {
void save(UserDTO user);
Optional<UserDTO> get(String email);
Optional<UserDTO> getById(String userId);
}
39 changes: 0 additions & 39 deletions src/main/java/io/autoinvestor/domain/AggregateRoot.java

This file was deleted.

49 changes: 0 additions & 49 deletions src/main/java/io/autoinvestor/domain/Event.java

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/java/io/autoinvestor/domain/EventStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.autoinvestor.domain;

import io.autoinvestor.domain.model.User;
import io.autoinvestor.domain.model.UserId;


public interface EventStore {
void save(User user);
User get(UserId userId);
}
5 changes: 5 additions & 0 deletions src/main/java/io/autoinvestor/domain/Id.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return value();
}
}
7 changes: 0 additions & 7 deletions src/main/java/io/autoinvestor/domain/UserRepository.java

This file was deleted.

Loading