-
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
9 changed files
with
335 additions
and
1 deletion.
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
49 changes: 49 additions & 0 deletions
49
server/src/main/java/io/myfinbox/spendingplan/application/JarQuery.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,49 @@ | ||
package io.myfinbox.spendingplan.application; | ||
|
||
import io.myfinbox.spendingplan.domain.Jar; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Represents a query interface for searching and retrieving jars. | ||
*/ | ||
public interface JarQuery { | ||
|
||
/** | ||
* Initiates a search for jars. | ||
* | ||
* @return a builder to further customize the jar search. | ||
*/ | ||
JarQueryBuilder search(); | ||
|
||
/** | ||
* Builder interface for constructing and executing a jar query. | ||
*/ | ||
interface JarQueryBuilder { | ||
|
||
/** | ||
* Filters the jars by the specified plan ID. | ||
* | ||
* @param planId the unique identifier of the plan. | ||
* @return the updated query builder. | ||
*/ | ||
JarQueryBuilder withPlanId(UUID planId); | ||
|
||
/** | ||
* Filters the jars by the specified jar ID. | ||
* | ||
* @param jarId the unique identifier of the jar. | ||
* @return the updated query builder. | ||
*/ | ||
JarQueryBuilder withJarId(UUID jarId); | ||
|
||
/** | ||
* Executes the query and returns a list of jars matching the criteria. | ||
* | ||
* @return a list of jars matching the query criteria. | ||
*/ | ||
List<Jar> list(); | ||
} | ||
} | ||
|
70 changes: 70 additions & 0 deletions
70
server/src/main/java/io/myfinbox/spendingplan/application/JarQueryService.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.Jar; | ||
import io.myfinbox.spendingplan.domain.JarIdentifier; | ||
import io.myfinbox.spendingplan.domain.Jars; | ||
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.*; | ||
import static java.util.Collections.emptyList; | ||
import static java.util.Objects.nonNull; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
class JarQueryService implements JarQuery { | ||
|
||
private final Jars jars; | ||
|
||
@Override | ||
public JarQueryBuilder search() { | ||
return new DefaultJarQueryBuilder(jars); | ||
} | ||
|
||
@RequiredArgsConstructor | ||
private static final class DefaultJarQueryBuilder implements JarQueryBuilder { | ||
|
||
private final Jars jars; | ||
|
||
private UUID planId; | ||
private UUID jarId; | ||
|
||
@Override | ||
public JarQueryBuilder withPlanId(UUID planId) { | ||
this.planId = planId; | ||
return this; | ||
} | ||
|
||
@Override | ||
public JarQueryBuilder withJarId(UUID jarId) { | ||
this.jarId = jarId; | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<Jar> list() { | ||
if (nonNull(planId) && nonNull(jarId)) { | ||
return jars.findByIdAndPlanId(new JarIdentifier(jarId), new PlanIdentifier(planId)) | ||
.map(List::of) | ||
.orElse(emptyList()); | ||
} | ||
|
||
if (nonNull(jarId)) { | ||
return jars.findById(new JarIdentifier(jarId)) | ||
.map(List::of) | ||
.orElse(emptyList()); | ||
} | ||
|
||
if (nonNull(planId)) { | ||
return jars.findByPlanId(new PlanIdentifier(planId)); | ||
} | ||
|
||
return emptyList(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.