-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
543 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...src/main/java/io/myfinbox/spendingplan/adapter/web/converters/JarToResourceConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.myfinbox.spendingplan.adapter.web.converters; | ||
|
||
import io.myfinbox.rest.JarResource; | ||
import io.myfinbox.spendingplan.domain.Jar; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
final class JarToResourceConverter implements Converter<Jar, JarResource> { | ||
|
||
@Override | ||
public JarResource convert(Jar jar) { | ||
return new JarResource() | ||
.jarId(jar.getId().id()) | ||
.creationTimestamp(jar.getCreationTimestamp().toString()) | ||
.amountToReach(jar.getAmountToReachAsNumber()) | ||
.currencyCode(jar.getCurrencyCode()) | ||
.name(jar.getName()) | ||
.percentage(jar.getPercentage().value()) | ||
.description(jar.getDescription()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...rc/main/java/io/myfinbox/spendingplan/adapter/web/converters/PlanToResourceConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.myfinbox.spendingplan.adapter.web.converters; | ||
|
||
import io.myfinbox.rest.JarResource; | ||
import io.myfinbox.rest.PlanResource; | ||
import io.myfinbox.spendingplan.domain.Jar; | ||
import io.myfinbox.spendingplan.domain.Plan; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
final class PlanToResourceConverter implements Converter<Plan, PlanResource> { | ||
|
||
private final Converter<Jar, JarResource> jarResourceConverter; | ||
|
||
@Override | ||
public PlanResource convert(Plan plan) { | ||
return new PlanResource() | ||
.planId(plan.getId().id()) | ||
.name(plan.getName()) | ||
.creationTimestamp(plan.getCreationTimestamp().toString()) | ||
.amount(plan.getAmountAsNumber()) | ||
.currencyCode(plan.getCurrencyCode()) | ||
.accountId(plan.getAccount().id()) | ||
.description(plan.getDescription()) | ||
.jars(plan.getJars().stream() | ||
.map(jarResourceConverter::convert) | ||
.toList()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
server/src/main/java/io/myfinbox/spendingplan/application/PlanQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.myfinbox.spendingplan.application; | ||
|
||
import io.myfinbox.spendingplan.domain.Plan; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Represents a query interface for searching and retrieving plans. | ||
*/ | ||
public interface PlanQuery { | ||
|
||
/** | ||
* Initiates a search for plans. | ||
* | ||
* @return a builder to further customize the plan search. | ||
*/ | ||
PlanQueryBuilder search(); | ||
|
||
/** | ||
* Builder interface for constructing and executing a plan query. | ||
*/ | ||
interface PlanQueryBuilder { | ||
|
||
/** | ||
* Filters the plans by the specified plan ID. | ||
* | ||
* @param planId the unique identifier of the plan. | ||
* @return the updated query builder. | ||
*/ | ||
PlanQueryBuilder withPlanId(UUID planId); | ||
|
||
/** | ||
* Filters the plans by the specified account ID. | ||
* | ||
* @param accountId the unique identifier of the account. | ||
* @return the updated query builder. | ||
*/ | ||
PlanQueryBuilder withAccountId(UUID accountId); | ||
|
||
/** | ||
* Executes the query and returns a list of plans matching the criteria. | ||
* | ||
* @return a list of plans matching the query criteria. | ||
*/ | ||
List<Plan> list(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
server/src/main/java/io/myfinbox/spendingplan/application/PlanQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.myfinbox.spendingplan.application; | ||
|
||
import io.myfinbox.spendingplan.domain.AccountIdentifier; | ||
import io.myfinbox.spendingplan.domain.Plan; | ||
import io.myfinbox.spendingplan.domain.Plans; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static io.myfinbox.spendingplan.domain.Plan.PlanIdentifier; | ||
import static java.util.Collections.emptyList; | ||
import static java.util.Objects.nonNull; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
class PlanQueryService implements PlanQuery { | ||
|
||
private final Plans plans; | ||
|
||
@Override | ||
public PlanQueryBuilder search() { | ||
return new DefaultPlanQueryBuilder(plans); | ||
} | ||
|
||
@RequiredArgsConstructor | ||
private static class DefaultPlanQueryBuilder implements PlanQueryBuilder { | ||
|
||
private final Plans plans; | ||
|
||
private UUID planId; | ||
private UUID accountId; | ||
|
||
@Override | ||
public PlanQueryBuilder withPlanId(UUID planId) { | ||
this.planId = planId; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PlanQueryBuilder withAccountId(UUID accountId) { | ||
this.accountId = accountId; | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<Plan> list() { | ||
if (nonNull(planId) && nonNull(accountId)) { | ||
return plans.findByIdAndAccountIdEagerJars(new PlanIdentifier(planId), new AccountIdentifier(accountId)) | ||
.map(List::of) | ||
.orElse(emptyList()); | ||
} | ||
|
||
if (nonNull(accountId)) { | ||
return plans.findByAccountIdEagerJars(new AccountIdentifier(accountId)); | ||
} | ||
|
||
if (nonNull(planId)) { | ||
return plans.findByIdEagerJars(new PlanIdentifier(planId)) | ||
.map(List::of) | ||
.orElse(emptyList()); | ||
} | ||
|
||
return emptyList(); | ||
} | ||
} | ||
} |
Oops, something went wrong.