-
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
10 changed files
with
175 additions
and
11 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/income/application/IncomeSourceQuery.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.income.application; | ||
|
||
import io.myfinbox.income.domain.IncomeSource; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Interface for querying income source information. | ||
*/ | ||
public interface IncomeSourceQuery { | ||
|
||
/** | ||
* Searches for income sources associated with a specific account. | ||
* | ||
* @param accountId the unique identifier of the account to search income sources for | ||
* @return a list of {@link IncomeSource} objects associated with the specified account | ||
*/ | ||
List<IncomeSource> search(UUID accountId); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
server/src/main/java/io/myfinbox/income/application/IncomeSourceQueryService.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.income.application; | ||
|
||
import io.myfinbox.income.domain.AccountIdentifier; | ||
import io.myfinbox.income.domain.IncomeSource; | ||
import io.myfinbox.income.domain.IncomeSources; | ||
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 IncomeSourceQueryService implements IncomeSourceQuery { | ||
|
||
private final IncomeSources incomeSources; | ||
|
||
@Override | ||
public List<IncomeSource> search(UUID accountId) { | ||
if (isNull(accountId)) { | ||
return emptyList(); | ||
} | ||
|
||
return incomeSources.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
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/income/application/IncomeSourceQueryServiceSpec.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.income.application | ||
|
||
import io.myfinbox.income.domain.AccountIdentifier | ||
import io.myfinbox.income.domain.IncomeSources | ||
import spock.lang.Specification | ||
import spock.lang.Tag | ||
|
||
import static io.myfinbox.income.DataSamples.* | ||
|
||
@Tag("unit") | ||
class IncomeSourceQueryServiceSpec extends Specification { | ||
|
||
IncomeSources incomeSources | ||
IncomeSourceQueryService service | ||
|
||
def setup() { | ||
incomeSources = Mock() | ||
service = new IncomeSourceQueryService(incomeSources) | ||
} | ||
|
||
def "should get empty list when income sources for provided account id not found"() { | ||
setup: 'mock the repository to return an empty list for any account identifier' | ||
1 * incomeSources.findByAccount(_ as AccountIdentifier) >> [] | ||
|
||
when: 'searching for income sources with a non-exiting account ID' | ||
def incomeSourcesList = service.search(UUID.randomUUID()) | ||
|
||
then: 'the result should be an empty list' | ||
assert incomeSourcesList.isEmpty() | ||
} | ||
|
||
def "should get empty list when account id is null"() { | ||
when: 'searching for income sources with a null account ID' | ||
def incomeSourcesList = service.search(null) | ||
|
||
then: 'the result should be an empty list' | ||
assert incomeSourcesList.isEmpty() | ||
|
||
and: 'the repository should not be queried' | ||
0 * incomeSources.findByAccount(_ as AccountIdentifier) | ||
} | ||
|
||
def "should get a list of income sources"() { | ||
setup: 'mock the repository to return an empty list for any account identifier' | ||
1 * incomeSources.findByAccount(_ as AccountIdentifier) >> [newSampleIncomeSource()] | ||
|
||
when: 'searching for income sources with a random account ID' | ||
def incomeSourcesList = service.search(UUID.randomUUID()) | ||
|
||
then: 'the result should be a list with one income source' | ||
assert incomeSourcesList.containsAll(newSampleIncomeSource()) | ||
} | ||
} |
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.income_source (id, | ||
account_id, | ||
creation_timestamp, | ||
name) | ||
VALUES ('3b257779-a5db-4e87-9365-72c6f8d4977d', | ||
'e2709aa2-7907-4f78-98b6-0f36a0c1b5ca', | ||
'Bills'), | ||
'2024-03-23T10:00:04.224870Z', | ||
'Business'), | ||
('e2709aa2-7907-4f78-98b6-0f36a0c1b5ca', | ||
'e2709aa2-7907-4f78-98b6-0f36a0c1b5ca', | ||
'2024-03-23T10:00:04.224870Z', | ||
'Other'); |