-
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.
Enhance jar expense category query api
- Loading branch information
Showing
14 changed files
with
250 additions
and
22 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
19 changes: 19 additions & 0 deletions
19
...o/myfinbox/spendingplan/adapter/web/converters/JarExpenseCategoryToResourceConverter.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,19 @@ | ||
package io.myfinbox.spendingplan.adapter.web.converters; | ||
|
||
import io.myfinbox.rest.JarExpenseCategoryResource; | ||
import io.myfinbox.spendingplan.domain.JarExpenseCategory; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
final class JarExpenseCategoryToResourceConverter implements Converter<JarExpenseCategory, JarExpenseCategoryResource> { | ||
|
||
@Override | ||
public JarExpenseCategoryResource convert(JarExpenseCategory category) { | ||
return new JarExpenseCategoryResource() | ||
.id(category.getId()) | ||
.categoryId(category.getCategoryId().id()) | ||
.categoryName(category.getCategoryName()) | ||
.creationTimestamp(category.getCreationTimestamp().toString()); | ||
} | ||
} |
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
server/src/main/java/io/myfinbox/spendingplan/application/JarExpenseCategoryQuery.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.application; | ||
|
||
import io.myfinbox.spendingplan.domain.JarExpenseCategory; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Represents a query interface for searching and retrieving jar expense categories. | ||
*/ | ||
public interface JarExpenseCategoryQuery { | ||
|
||
/** | ||
* Searches for jar expense categories based on the specified plan ID and jar ID. | ||
* | ||
* @param planId the unique identifier of the plan. | ||
* @param jarId the unique identifier of the jar. | ||
* @return a list of jar expense categories matching the specified plan ID and jar ID. | ||
*/ | ||
List<JarExpenseCategory> search(UUID planId, UUID jarId); | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...er/src/main/java/io/myfinbox/spendingplan/application/JarExpenseCategoryQueryService.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,34 @@ | ||
package io.myfinbox.spendingplan.application; | ||
|
||
import io.myfinbox.spendingplan.domain.*; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static java.util.Objects.isNull; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
class JarExpenseCategoryQueryService implements JarExpenseCategoryQuery { | ||
|
||
private final JarExpenseCategories jarExpenseCategories; | ||
private final Jars jars; | ||
|
||
@Override | ||
public List<JarExpenseCategory> search(UUID planId, UUID jarId) { | ||
if (isNull(planId) || isNull(jarId)) { | ||
return emptyList(); | ||
} | ||
|
||
if (!jars.existsByIdAndPlan(new Plan.PlanIdentifier(planId), new JarIdentifier(jarId))) { | ||
return emptyList(); | ||
} | ||
|
||
return jarExpenseCategories.findByJarId(new JarIdentifier(jarId)); | ||
} | ||
} |
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
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.