-
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
13 changed files
with
201 additions
and
38 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
server/src/main/java/io/myfinbox/account/adapter/persistence/JpaAccountQuery.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,37 @@ | ||
package io.myfinbox.account.adapter.persistence; | ||
|
||
import io.myfinbox.account.application.AccountQuery; | ||
import io.myfinbox.account.domain.Account; | ||
import io.myfinbox.account.domain.Accounts; | ||
import io.myfinbox.shared.Failure; | ||
import io.vavr.control.Either; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
import static io.myfinbox.account.domain.Account.AccountIdentifier; | ||
import static io.myfinbox.shared.Failure.ofNotFound; | ||
import static java.util.Objects.isNull; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
class JpaAccountQuery implements AccountQuery { | ||
|
||
static final String ACCOUNT_NOT_FOUND = "Account '%s' not found."; | ||
|
||
private final Accounts accounts; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public Either<Failure, Account> findOne(UUID accountId) { | ||
if (isNull(accountId)) { | ||
return Either.left(ofNotFound(ACCOUNT_NOT_FOUND.formatted(accountId))); | ||
} | ||
|
||
return accounts.findById(new AccountIdentifier(accountId)) | ||
.<Either<Failure, Account>>map(Either::right) | ||
.orElseGet(() -> Either.left(ofNotFound(ACCOUNT_NOT_FOUND.formatted(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
21 changes: 21 additions & 0 deletions
21
server/src/main/java/io/myfinbox/account/application/AccountQuery.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.account.application; | ||
|
||
import io.myfinbox.account.domain.Account; | ||
import io.myfinbox.shared.Failure; | ||
import io.vavr.control.Either; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Interface for querying account information. | ||
*/ | ||
public interface AccountQuery { | ||
|
||
/** | ||
* Finds an account by its unique identifier. | ||
* | ||
* @param accountId the unique identifier of the account to find | ||
* @return an {@link Either} instance containing either a {@link Failure} or the {@link Account} found | ||
*/ | ||
Either<Failure, Account> findOne(UUID 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
10 changes: 5 additions & 5 deletions
10
server/src/main/resources/db/migration/V1_01__accounts_schema.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,9 @@ | ||
CREATE TABLE IF NOT EXISTS accounts | ||
( | ||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
email_address VARCHAR(256) NOT NULL UNIQUE, | ||
first_name VARCHAR(255), | ||
last_name VARCHAR(255) | ||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
creation_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
email_address VARCHAR(256) NOT NULL UNIQUE, | ||
first_name VARCHAR(255), | ||
last_name VARCHAR(255) | ||
) | ||
; |
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.