-
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
8 changed files
with
166 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
server/src/main/java/io/myfinbox/expense/application/CategoryQuery.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,21 @@ | ||
package io.myfinbox.expense.application; | ||
|
||
import io.myfinbox.expense.domain.Category; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Interface for querying category information. | ||
*/ | ||
public interface CategoryQuery { | ||
|
||
/** | ||
* Searches for categories associated with a specific account. | ||
* | ||
* @param accountId the unique identifier of the account to search categories for | ||
* @return a list of {@link Category} objects associated with the specified account | ||
*/ | ||
List<Category> search(UUID accountId); | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
server/src/main/java/io/myfinbox/expense/application/CategoryQueryService.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.expense.application; | ||
|
||
import io.myfinbox.expense.domain.AccountIdentifier; | ||
import io.myfinbox.expense.domain.Categories; | ||
import io.myfinbox.expense.domain.Category; | ||
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 CategoryQueryService implements CategoryQuery { | ||
|
||
private final Categories categories; | ||
|
||
@Override | ||
public List<Category> search(UUID accountId) { | ||
if (isNull(accountId)) { | ||
return emptyList(); | ||
} | ||
|
||
return categories.findByAccount(new AccountIdentifier(accountId)); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
server/src/test/groovy/io/myfinbox/expense/application/CategoryQueryServiceSpec.groovy
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,53 @@ | ||
package io.myfinbox.expense.application | ||
|
||
import io.myfinbox.expense.domain.AccountIdentifier | ||
import io.myfinbox.expense.domain.Categories | ||
import spock.lang.Specification | ||
import spock.lang.Tag | ||
|
||
import static io.myfinbox.expense.DataSamples.newSampleCategory | ||
|
||
@Tag("unit") | ||
class CategoryQueryServiceSpec extends Specification { | ||
|
||
Categories categories | ||
CategoryQueryService service | ||
|
||
def setup() { | ||
categories = Mock() | ||
service = new CategoryQueryService(categories) | ||
} | ||
|
||
def "should get empty list when categories for provided account id not found"() { | ||
setup: 'mock the repository to return an empty list for any account identifier' | ||
1 * categories.findByAccount(_ as AccountIdentifier) >> [] | ||
|
||
when: 'searching for categories with a non-exiting account ID' | ||
def categoryList = service.search(UUID.randomUUID()) | ||
|
||
then: 'the result should be an empty list' | ||
assert categoryList.isEmpty() | ||
} | ||
|
||
def "should get empty list when account id is null"() { | ||
when: 'searching for categories with a null account ID' | ||
def categoryList = service.search(null) | ||
|
||
then: 'the result should be an empty list' | ||
assert categoryList.isEmpty() | ||
|
||
and: 'the repository should not be queried' | ||
0 * categories.findByAccount(_ as AccountIdentifier) | ||
} | ||
|
||
def "should get a list of categories"() { | ||
setup: 'mock the repository to return a list with a sample category for any account identifier' | ||
1 * categories.findByAccount(_ as AccountIdentifier) >> [newSampleCategory()] | ||
|
||
when: 'Searching for categories with a random account ID' | ||
def categoryList = service.search(UUID.randomUUID()) | ||
|
||
then: 'the result should be a list with one category' | ||
assert categoryList.size() == 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
server/src/test/resources/expense/web/expensecategory-create.sql
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
INSERT INTO server.expense_category (id, | ||
account_id, | ||
creation_timestamp, | ||
name) | ||
VALUES ('3b257779-a5db-4e87-9365-72c6f8d4977d', | ||
'e2709aa2-7907-4f78-98b6-0f36a0c1b5ca', | ||
'2024-03-23T10:00:04.224870Z', | ||
'Bills'), | ||
('e2709aa2-7907-4f78-98b6-0f36a0c1b5ca', | ||
'e2709aa2-7907-4f78-98b6-0f36a0c1b5ca', | ||
'2024-03-23T10:00:04.224870Z', | ||
'Other'); |