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
5 changes: 4 additions & 1 deletion .github/workflows/pull-request-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ jobs:
java-version: 21

- name: Build & Test
run: ./gradlew clean build
run: ./gradlew clean build

- name: Spotless Check
run: ./gradlew spotlessCheck
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)

69 changes: 44 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.3'
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.3'
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'
implementation 'com.yahoofinance-api:YahooFinanceAPI:3.17.0'

testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:gcloud'
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'
implementation 'com.yahoofinance-api:YahooFinanceAPI:3.17.0'

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

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}

bootBuildImage {
publish = false
publish = false
}

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

format 'misc', {
target '*.gradle', '*.md', '.gitignore'
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
6 changes: 3 additions & 3 deletions src/main/java/io/autoinvestor/CoreApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@SpringBootApplication
public class CoreApplication {

public static void main(String[] args) {
SpringApplication.run(CoreApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(CoreApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.autoinvestor.exceptions.DuplicatedException;

public class AssetAlreadyExists extends DuplicatedException {
public AssetAlreadyExists(String message) {
super(message);
}
public AssetAlreadyExists(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.autoinvestor.exceptions.BadRequestException;

public class AssetNotFoundException extends BadRequestException {
public AssetNotFoundException(String message) {
super(message);
}
public AssetNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@

import io.autoinvestor.domain.Asset;
import io.autoinvestor.domain.AssetRepository;
import org.springframework.stereotype.Service;

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

import org.springframework.stereotype.Service;

@Service
public class GetAllAssetsCommandHandler {

private final AssetRepository repository;
private final AssetRepository repository;

public GetAllAssetsCommandHandler(AssetRepository repository) {
this.repository = repository;
}
public GetAllAssetsCommandHandler(AssetRepository repository) {
this.repository = repository;
}

public List<GetAssetResponse> handle() {
List<Asset> assets = this.repository.findAll();
return assets.stream()
.map(asset -> new GetAssetResponse(
asset.id(),
asset.mic(),
asset.ticker(),
asset.name()
))
.collect(Collectors.toList());
}
public List<GetAssetResponse> handle() {
List<Asset> assets = this.repository.findAll();
return assets.stream()
.map(asset -> new GetAssetResponse(asset.id(), asset.mic(), asset.ticker(), asset.name()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
package io.autoinvestor.application;

public record GetAssetCommand(
String assetId
) {}

public record GetAssetCommand(String assetId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,28 @@
import io.autoinvestor.domain.Asset;
import io.autoinvestor.domain.AssetId;
import io.autoinvestor.domain.AssetRepository;
import org.springframework.stereotype.Service;

import java.util.Optional;

import org.springframework.stereotype.Service;

@Service
public class GetAssetCommandHandler {

private final AssetRepository repository;
private final AssetRepository repository;

public GetAssetCommandHandler(AssetRepository repository) {
this.repository = repository;
}
public GetAssetCommandHandler(AssetRepository repository) {
this.repository = repository;
}

public GetAssetResponse handle(GetAssetCommand command) {
Optional<Asset> asset = repository.findById(AssetId.of(command.assetId()));
public GetAssetResponse handle(GetAssetCommand command) {
Optional<Asset> asset = repository.findById(AssetId.of(command.assetId()));

if (asset.isEmpty()) {
throw new AssetNotFoundException("Asset not found with ID: " + command.assetId());
}

return new GetAssetResponse(
asset.get().id(),
asset.get().mic(),
asset.get().ticker(),
asset.get().name()
);
if (asset.isEmpty()) {
throw new AssetNotFoundException("Asset not found with ID: " + command.assetId());
}

return new GetAssetResponse(
asset.get().id(), asset.get().mic(), asset.get().ticker(), asset.get().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import java.util.Date;

public record GetAssetPriceCommand(String assetId, Date date) { }
public record GetAssetPriceCommand(String assetId, Date date) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
import io.autoinvestor.domain.AssetId;
import io.autoinvestor.domain.AssetPriceFetcher;
import io.autoinvestor.domain.AssetRepository;
import org.springframework.stereotype.Service;

import java.util.Optional;

import org.springframework.stereotype.Service;

@Service
public class GetAssetPriceCommandHandler {

private final AssetPriceFetcher fetcher;
private final AssetRepository repository;
private final AssetPriceFetcher fetcher;
private final AssetRepository repository;

public GetAssetPriceCommandHandler(AssetRepository repository, AssetPriceFetcher fetcher) {
this.repository = repository;
this.fetcher = fetcher;
}
public GetAssetPriceCommandHandler(AssetRepository repository, AssetPriceFetcher fetcher) {
this.repository = repository;
this.fetcher = fetcher;
}

public GetAssetPriceResponse handle(GetAssetPriceCommand command) {
Optional<Asset> asset = repository.findById(AssetId.of(command.assetId()));
public GetAssetPriceResponse handle(GetAssetPriceCommand command) {
Optional<Asset> asset = repository.findById(AssetId.of(command.assetId()));

if (asset.isEmpty()) {
throw new AssetNotFoundException("Asset not found with ID: " + command.assetId());
}

float price = fetcher.priceOn(asset.get(), command.date());
return new GetAssetPriceResponse(price, command.date());
if (asset.isEmpty()) {
throw new AssetNotFoundException("Asset not found with ID: " + command.assetId());
}

float price = fetcher.priceOn(asset.get(), command.date());
return new GetAssetPriceResponse(price, command.date());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

import java.util.Date;


public record GetAssetPriceResponse(float price, Date date) { }
public record GetAssetPriceResponse(float price, Date date) {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
package io.autoinvestor.application;

public record GetAssetResponse(
String assetId,
String mic,
String ticker,
String name
) {}
public record GetAssetResponse(String assetId, String mic, String ticker, String name) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package io.autoinvestor.application;


public record RegisterAssetCommand(String mic, String ticker, String name) { }
public record RegisterAssetCommand(String mic, String ticker, String name) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,31 @@
import io.autoinvestor.domain.Asset;
import io.autoinvestor.domain.AssetRepository;
import io.autoinvestor.domain.EventPublisher;
import org.springframework.stereotype.Service;

import org.springframework.stereotype.Service;

@Service
public class RegisterAssetCommandHandler {

private final AssetRepository repository;
private final EventPublisher eventPublisher;
private final AssetRepository repository;
private final EventPublisher eventPublisher;

public RegisterAssetCommandHandler(AssetRepository repository,
EventPublisher eventPublisher) {
this.repository = repository;
this.eventPublisher = eventPublisher;
}
public RegisterAssetCommandHandler(AssetRepository repository, EventPublisher eventPublisher) {
this.repository = repository;
this.eventPublisher = eventPublisher;
}

public RegisterAssetResponse handle(RegisterAssetCommand command) {
if (this.repository.exists(command.mic(), command.ticker())) {
throw new AssetAlreadyExists("Duplicated asset for this mic: " + command.mic() + " and ticker: " + command.ticker());
}
public RegisterAssetResponse handle(RegisterAssetCommand command) {
if (this.repository.exists(command.mic(), command.ticker())) {
throw new AssetAlreadyExists(
"Duplicated asset for this mic: " + command.mic() + " and ticker: " + command.ticker());
}

Asset asset = Asset.create(command.mic(), command.ticker(), command.name());
Asset asset = Asset.create(command.mic(), command.ticker(), command.name());

this.repository.save(asset);
this.eventPublisher.publish(asset.releaseEvents());
this.repository.save(asset);
this.eventPublisher.publish(asset.releaseEvents());

return new RegisterAssetResponse(
asset.id(),
asset.mic(),
asset.ticker(),
asset.name()
);
}
return new RegisterAssetResponse(asset.id(), asset.mic(), asset.ticker(), asset.name());
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
package io.autoinvestor.application;

public record RegisterAssetResponse(
String assetId,
String mic,
String ticker,
String name
) {}
public record RegisterAssetResponse(String assetId, String mic, String ticker, String name) {}
Loading