Midas Core: Kafka Integration, H2 Persistence, Incentive API & Balance REST Endpoint - #303
Open
ptewary02 wants to merge 1 commit into
Open
Midas Core: Kafka Integration, H2 Persistence, Incentive API & Balance REST Endpoint#303ptewary02 wants to merge 1 commit into
ptewary02 wants to merge 1 commit into
Conversation
…, and balance REST endpoint
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Integrates Midas Core with Kafka for transaction ingestion, adds H2-backed persistence for users and transactions, integrates the external incentive API, and exposes a REST endpoint for querying user balances.
Changes
Kafka Integration
Added spring-kafka dependency and consumer/producer configuration in application.yml, driven by the general.kafka-topic config value
Implemented TransactionListener, a @KafkaListener that consumes and deserializes incoming messages into Transaction objects
H2 Persistence
Added spring-boot-starter-data-jpa and h2 dependencies with an in-memory H2 datasource
Added TransactionRecord entity with @manytoone relationships to UserRecord for both sender and recipient
Added TransactionRecordRepository
Implemented validation and processing logic in DatabaseConduit.processTransaction():
Validates sender/recipient existence and sufficient sender balance
Adjusts both balances and persists a TransactionRecord on success
Discards invalid transactions with no DB changes
Incentive API Integration
Added Incentive DTO mirroring the incentive API response
Added IncentiveClient, which POSTs validated transactions to http://localhost:8080/incentive via RestTemplate and returns the incentive amount
Extended TransactionRecord with an incentive field
Updated processTransaction() to apply the incentive to the recipient's balance only (not deducted from the sender)
Balance REST API
Added BalanceController exposing GET /balance?userId={id}, returning a serialized Balance
Returns Balance(0) for unknown user IDs
Configured server.port: 33400 so the API runs alongside the Kafka listener in the same Spring Boot application
Testing
Verified via TaskOneTests through TaskFiveTests using the embedded Kafka broker and debugger/log inspection
Incentive API (services/transaction-incentive-api.jar) run locally on port 8080 during Task 5/5 verification