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
1 change: 0 additions & 1 deletion HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ For further reference, please consider the following sections:
These additional references should also help you:

* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)

80 changes: 50 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,49 +1,69 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.4'
id 'io.spring.dependency-management' version '1.1.7'
id 'io.freefair.lombok' version '8.13.1'
id 'java'
id 'org.springframework.boot' version '3.4.4'
id 'io.spring.dependency-management' version '1.1.7'
id 'io.freefair.lombok' version '8.13.1'
id 'com.diffplug.spotless' version '7.0.4'
}

group = 'io.autoinvestor'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

repositories {
mavenCentral()
mavenCentral()
}

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 '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 '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'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

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 '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') {
useJUnitPlatform()
useJUnitPlatform()
}

bootBuildImage {
publish = false
publish = false
}

spotless {
java {
googleJavaFormat('1.22.0').aosp()
removeUnusedImports()
trimTrailingWhitespace()
leadingTabsToSpaces()
endWithNewline()
importOrder '', 'java', 'javax', 'org', 'com'
target 'src/**/*.java'
}

format 'misc', {
target '*.gradle', '*.md', '.gitignore'
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
7 changes: 1 addition & 6 deletions src/main/java/io/autoinvestor/application/AlertDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

import java.util.Date;

public record AlertDTO(
String userId,
String assetId,
String type,
Date date
) {}
public record AlertDTO(String userId, String assetId, String type, Date date) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

public interface AlertsReadModelRepository {
void save(AlertDTO alertDTO);

List<AlertDTO> get(String userId);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
package io.autoinvestor.application;


public record EmitAlertsCommand(
String assetId,
String decision,
int riskLevel
) { }
public record EmitAlertsCommand(String assetId, String decision, int riskLevel) {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import io.autoinvestor.domain.model.UserId;
import io.autoinvestor.exceptions.InternalErrorException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

@Slf4j
@Service
public class EmitAlertsCommandHandler {
Expand All @@ -25,9 +26,12 @@ public class EmitAlertsCommandHandler {
private final InboxReadModelRepository inboxReadModel;
private final EventPublisher eventPublisher;

public EmitAlertsCommandHandler(EventStoreRepository eventStore, PortfolioRepository portfolioRepository,
AlertsReadModelRepository alertsReadModel, InboxReadModelRepository inboxReadModel,
EventPublisher eventPublisher) {
public EmitAlertsCommandHandler(
EventStoreRepository eventStore,
PortfolioRepository portfolioRepository,
AlertsReadModelRepository alertsReadModel,
InboxReadModelRepository inboxReadModel,
EventPublisher eventPublisher) {
this.eventStore = eventStore;
this.portfolioRepository = portfolioRepository;
this.alertsReadModel = alertsReadModel;
Expand All @@ -36,7 +40,9 @@ public EmitAlertsCommandHandler(EventStoreRepository eventStore, PortfolioReposi
}

public void handle(EmitAlertsCommand command) {
List<UserId> usersId = this.portfolioRepository.getUsersIdByAssetAndRiskLevel(command.assetId(), command.riskLevel());
List<UserId> usersId =
this.portfolioRepository.getUsersIdByAssetAndRiskLevel(
command.assetId(), command.riskLevel());

for (UserId userId : usersId) {
Optional<InboxId> inboxIdOpt = this.inboxReadModel.getInboxId(userId);
Expand All @@ -60,15 +66,21 @@ public void handle(EmitAlertsCommand command) {

this.eventStore.save(inbox);

Alert alert = inbox.getState().getLastAlert()
.orElseThrow(() -> new InternalErrorException("No alert found after emitting one for userId " + userId.value()));
Alert alert =
inbox.getState()
.getLastAlert()
.orElseThrow(
() ->
new InternalErrorException(
"No alert found after emitting one for userId "
+ userId.value()));

AlertDTO alertDTO = new AlertDTO(
userId.value(),
command.assetId(),
alert.decision().name(),
alert.date()
);
AlertDTO alertDTO =
new AlertDTO(
userId.value(),
command.assetId(),
alert.decision().name(),
alert.date());
this.alertsReadModel.save(alertDTO);

this.eventPublisher.publish(events);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.autoinvestor.application;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

@Service
public class GetAlertsQueryHandler {

Expand All @@ -18,11 +18,7 @@ public List<GetAlertsQueryResponse> handle(GetDecisionsQuery query) {
List<AlertDTO> decisions = this.readModel.get(query.userId());

return decisions.stream()
.map(d -> new GetAlertsQueryResponse(
d.assetId(),
d.type(),
d.date()
))
.map(d -> new GetAlertsQueryResponse(d.assetId(), d.type(), d.date()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

import java.util.Date;

public record GetAlertsQueryResponse(
String assetId,
String type,
Date date
) { }
public record GetAlertsQueryResponse(String assetId, String type, Date date) {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.autoinvestor.application;

public record GetDecisionsQuery(String userId) { }
public record GetDecisionsQuery(String userId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

public interface InboxReadModelRepository {
void save(UserId userId, InboxId inboxId);

Optional<InboxId> getInboxId(UserId userId);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package io.autoinvestor.application;

public record RegisterPortfolioAssetCommand(String userId, String assetId) {
}
public record RegisterPortfolioAssetCommand(String userId, String assetId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import io.autoinvestor.domain.model.Inbox;
import io.autoinvestor.domain.model.InboxId;
import io.autoinvestor.domain.model.UserId;
import io.autoinvestor.exceptions.InternalErrorException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

@Slf4j
@Service
Expand All @@ -24,8 +23,11 @@ public class RegisterPortfolioAssetCommandHandler {
private final InboxReadModelRepository inboxReadModel;
private final EventPublisher eventPublisher;

public RegisterPortfolioAssetCommandHandler(EventStoreRepository eventStore, PortfolioRepository portfolioRepository,
InboxReadModelRepository inboxReadModel, EventPublisher eventPublisher) {
public RegisterPortfolioAssetCommandHandler(
EventStoreRepository eventStore,
PortfolioRepository portfolioRepository,
InboxReadModelRepository inboxReadModel,
EventPublisher eventPublisher) {
this.eventStore = eventStore;
this.portfolioRepository = portfolioRepository;
this.inboxReadModel = inboxReadModel;
Expand All @@ -34,7 +36,8 @@ public RegisterPortfolioAssetCommandHandler(EventStoreRepository eventStore, Por

public void handle(RegisterPortfolioAssetCommand command) {
if (this.portfolioRepository.existsPortfolioAsset(command.userId(), command.assetId())) {
log.info("Asset {} already registered for user {}", command.assetId(), command.userId());
log.info(
"Asset {} already registered for user {}", command.assetId(), command.userId());
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package io.autoinvestor.application;

public record RegisterUserCommand(String userId, int riskLevel) {
}
public record RegisterUserCommand(String userId, int riskLevel) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import io.autoinvestor.domain.model.Inbox;
import io.autoinvestor.domain.model.UserId;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import org.springframework.stereotype.Service;

@Slf4j
@Service
Expand All @@ -21,8 +21,11 @@ public class RegisterUserCommandHandler {
private final InboxReadModelRepository inboxReadModel;
private final EventPublisher eventPublisher;

public RegisterUserCommandHandler(EventStoreRepository eventStore, PortfolioRepository portfolioRepository,
InboxReadModelRepository inboxReadModel, EventPublisher eventPublisher) {
public RegisterUserCommandHandler(
EventStoreRepository eventStore,
PortfolioRepository portfolioRepository,
InboxReadModelRepository inboxReadModel,
EventPublisher eventPublisher) {
this.eventStore = eventStore;
this.portfolioRepository = portfolioRepository;
this.inboxReadModel = inboxReadModel;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/autoinvestor/domain/Id.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ protected static String generateId() {

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Id that))
return false;
if (this == o) return true;
if (!(o instanceof Id that)) return false;
return id.equals(that.id);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/autoinvestor/domain/PortfolioRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

public interface PortfolioRepository {
List<UserId> getUsersIdByAssetAndRiskLevel(String assetId, int riskLevel);

void addUser(String userId, int riskLevel);

void addPortfolioAsset(String userId, String assetId);

boolean existsPortfolioAsset(String userId, String assetId);
}
Loading