Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20 create a projection showing the current balance of an account #45

Conversation

rafaelcp94
Copy link
Contributor

This PR aims to refactor the package structure has discussed on EDM(Event-driven-microservice) day with suggestions:

  • Refactor packages to split between account and query.
  • Add 2 flyway configurations for each database type (read and write)
  • Refactor the code.
  • Add accountBalance Projection to fetch the account balance.

Ps: On the next issue #21 the linking between the sync of the balance with read model will be done.

Add entity and domain class.
Add ports and jpa adapter
Fix table annotation on account entity.
Add getAccountBalance implementation and new ports
…-the-current-balance-of-an-account

# Conflicts:
#	demo-transactions/src/main/kotlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/adapter/inbound/account/AccountRestInAdapter.kt
#	demo-transactions/src/test/kotlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/integrationtest/GlobalIT.kt
…be reusable for negative values (negative balance of the account).

Validation of amount rules in useCase.
add schema of read database to flyway
Use root user on database for now.
Refactor: Add 2 flyway migration schemas for each database.
Refactor code.
@rafaelcp94 rafaelcp94 self-assigned this May 3, 2024
@rafaelcp94 rafaelcp94 linked an issue May 3, 2024 that may be closed by this pull request
@mmiikkkkaa
Copy link
Contributor

The current package splitting confuses me a bit.
I understand the separation into command and query (even if I'm not sure whether I like the naming), but than it's weird to me, that there is still an infrastructure and domain package on the same level. If we have shared components, than those might be moved into a shared package.

Than all 1st level packages (command, query and shared, while root is level zero) can have the typical separation into domain, application and infrastructure again.
That would also support a later separation into differend maven modules, if desired.

"Amount must be positive"
}
}

val account = accountOutPort.findAccount(iban)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I really don't like the naming, that we introduced here in the beginning. Reading "InPort" and "OutPort" in the usecase doesn't feel right, since it doesn't help to understand what is happening, but distracts by bringing "reading complexity".
I would like to have those things named by what they are meant to do, than by what they are. Like AccountService or AccountRepo instead of AccountOutPort. We can add OutPort and InPort annotations to the framework package, and mark the port-interfaces with those annotations, but that should be it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you mean and i will do the change. The outPort could be in fact called Services like AccountService instead of AccountOutPort. but i think the inPort could be kept no ? Since InPort immediately tells you what its purpose is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it unison - name it after its domain/application purpose and add the architectural purpose as annotation. But this is not for now, we can do that later.

@@ -0,0 +1,5 @@
CREATE TABLE `cqrs-meets-hexagonal-read-db`.account_balance(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it add any confusion to on the one side use the wording 'read' and 'write' (within db resources) and on the other side 'command' and 'query' (in package structures)?
Maybe we should stick to command-model and query-model instead of write and read (especially since on both sides data is writted and read).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i changed to a better suited name, which means that you need to clear the database.

rafaelcp94 added 2 commits May 3, 2024 16:34
Refactor: Rename outPorts to services for better readability
Refactor: Moved packages to match hexagonal architecture pattern.
@rafaelcp94 rafaelcp94 requested a review from mmiikkkkaa May 6, 2024 11:44
@@ -33,9 +33,13 @@ spring:
generate_statistics: true
database-platform: org.hibernate.dialect.MySQL8Dialect
flyway:
enabled: true
enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not enabled? 🤔

Copy link
Contributor Author

@rafaelcp94 rafaelcp94 May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because i added .../shared/infrastructure/database/flyway/FlywayConfig.kt file that creates 2 flyway migration schemas, and i can't use flyway enable since it overrides the other. With 2 flyway schemas we can have V0_0_0 in query and also V0_0_0 in command. So we complete split the 2 databases migration schemas. i think this as also an ideia that patrik added on the last EDM event tell me what you think 🙈

flyway.url=jdbc:mysql://localhost:3306/
flyway.locations=classpath:db
flyway.locations=classpath:db/read,classpath:db/write
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the same here: query and command instead of read and write

private lateinit var accountService: AccountService

//@Autowired
//private lateinit var accountBalanceInPort: AccountBalanceInPort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better removed then commented out :-)

@rafaelcp94 rafaelcp94 requested a review from mmiikkkkaa May 27, 2024 10:26
@rafaelcp94 rafaelcp94 merged commit 90d9769 into develop May 31, 2024
2 checks passed
@rafaelcp94 rafaelcp94 deleted the 20-create-a-projection-showing-the-current-balance-of-an-account branch May 31, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a projection showing the current balance of an account
2 participants