Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
S
Spec-Driven Development
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shouib.sobh
Spec-Driven Development
Commits
89f94d34
Commit
89f94d34
authored
Nov 02, 2026
by
Shouib
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: complete foundational infrastructure
parent
dd9f3c65
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
250 additions
and
5 deletions
+250
-5
.gitignore
.gitignore
+5
-5
Account.java
src/main/java/com/banking/models/Account.java
+9
-0
RequestDTO.java
src/main/java/com/banking/models/RequestDTO.java
+10
-0
ResponseDTO.java
src/main/java/com/banking/models/ResponseDTO.java
+9
-0
Transaction.java
src/main/java/com/banking/models/Transaction.java
+15
-0
AccountRepository.java
src/main/java/com/banking/persistence/AccountRepository.java
+75
-0
TransactionLedgerRepository.java
.../com/banking/persistence/TransactionLedgerRepository.java
+56
-0
ModelTest.java
src/test/java/com/banking/models/ModelTest.java
+71
-0
No files found.
.gitignore
View file @
89f94d34
node_modules/
dist/
build/
target/
target/
*.class
*.jar
.gradle/
build/
.idea/
*.log
*.log
.env*
.env*
data/
.DS_Store
.DS_Store
Thumbs.db
Thumbs.db
*.tmp
*.tmp
*.swp
*.swp
.vscode/
.vscode/
.idea/
src/main/java/com/banking/models/Account.java
0 → 100644
View file @
89f94d34
package
com
.
banking
.
models
;
import
java.math.BigDecimal
;
public
record
Account
(
String
accountId
,
BigDecimal
balance
,
long
lastProcessedSeqKey
)
{}
src/main/java/com/banking/models/RequestDTO.java
0 → 100644
View file @
89f94d34
package
com
.
banking
.
models
;
import
java.math.BigDecimal
;
public
record
RequestDTO
(
String
accountId
,
BigDecimal
amount
,
long
sequenceKey
,
boolean
isRetry
)
{}
src/main/java/com/banking/models/ResponseDTO.java
0 → 100644
View file @
89f94d34
package
com
.
banking
.
models
;
import
java.math.BigDecimal
;
public
record
ResponseDTO
(
String
status
,
BigDecimal
balance
,
String
message
)
{}
src/main/java/com/banking/models/Transaction.java
0 → 100644
View file @
89f94d34
package
com
.
banking
.
models
;
import
java.math.BigDecimal
;
import
java.time.Instant
;
public
record
Transaction
(
Long
id
,
String
accountId
,
long
sequenceKey
,
BigDecimal
amount
,
String
outcome
,
BigDecimal
balanceAfter
,
String
responseMessage
,
Instant
timestamp
)
{}
src/main/java/com/banking/persistence/AccountRepository.java
0 → 100644
View file @
89f94d34
package
com
.
banking
.
persistence
;
import
com.banking.models.Account
;
import
java.math.BigDecimal
;
import
java.sql.*
;
import
java.util.Optional
;
public
class
AccountRepository
{
private
final
Connection
connection
;
public
AccountRepository
(
Connection
connection
)
{
this
.
connection
=
connection
;
}
public
void
createAccount
(
String
accountId
,
BigDecimal
initialBalance
)
throws
SQLException
{
String
sql
=
"INSERT INTO ACCOUNT (account_id, balance, last_processed_seq_key) VALUES (?, ?, 0)"
;
try
(
PreparedStatement
pstmt
=
connection
.
prepareStatement
(
sql
))
{
pstmt
.
setString
(
1
,
accountId
);
pstmt
.
setBigDecimal
(
2
,
initialBalance
);
pstmt
.
executeUpdate
();
}
}
public
Optional
<
Account
>
findById
(
String
accountId
)
throws
SQLException
{
String
sql
=
"SELECT account_id, balance, last_processed_seq_key FROM ACCOUNT WHERE account_id = ?"
;
try
(
PreparedStatement
pstmt
=
connection
.
prepareStatement
(
sql
))
{
pstmt
.
setString
(
1
,
accountId
);
try
(
ResultSet
rs
=
pstmt
.
executeQuery
())
{
if
(
rs
.
next
())
{
return
Optional
.
of
(
new
Account
(
rs
.
getString
(
"account_id"
),
rs
.
getBigDecimal
(
"balance"
),
rs
.
getLong
(
"last_processed_seq_key"
)
));
}
}
}
return
Optional
.
empty
();
}
public
Optional
<
Account
>
findByIdForUpdate
(
String
accountId
)
throws
SQLException
{
String
sql
=
"SELECT account_id, balance, last_processed_seq_key FROM ACCOUNT WHERE account_id = ? FOR UPDATE"
;
try
(
PreparedStatement
pstmt
=
connection
.
prepareStatement
(
sql
))
{
pstmt
.
setString
(
1
,
accountId
);
try
(
ResultSet
rs
=
pstmt
.
executeQuery
())
{
if
(
rs
.
next
())
{
return
Optional
.
of
(
new
Account
(
rs
.
getString
(
"account_id"
),
rs
.
getBigDecimal
(
"balance"
),
rs
.
getLong
(
"last_processed_seq_key"
)
));
}
}
}
return
Optional
.
empty
();
}
public
void
updateBalance
(
String
accountId
,
BigDecimal
newBalance
)
throws
SQLException
{
String
sql
=
"UPDATE ACCOUNT SET balance = ? WHERE account_id = ?"
;
try
(
PreparedStatement
pstmt
=
connection
.
prepareStatement
(
sql
))
{
pstmt
.
setBigDecimal
(
1
,
newBalance
);
pstmt
.
setString
(
2
,
accountId
);
pstmt
.
executeUpdate
();
}
}
public
void
updateSeqKey
(
String
accountId
,
long
newSeqKey
)
throws
SQLException
{
String
sql
=
"UPDATE ACCOUNT SET last_processed_seq_key = ? WHERE account_id = ?"
;
try
(
PreparedStatement
pstmt
=
connection
.
prepareStatement
(
sql
))
{
pstmt
.
setLong
(
1
,
newSeqKey
);
pstmt
.
setString
(
2
,
accountId
);
pstmt
.
executeUpdate
();
}
}
}
src/main/java/com/banking/persistence/TransactionLedgerRepository.java
0 → 100644
View file @
89f94d34
package
com
.
banking
.
persistence
;
import
com.banking.models.Transaction
;
import
java.sql.*
;
import
java.util.Optional
;
import
java.math.BigDecimal
;
import
java.time.Instant
;
public
class
TransactionLedgerRepository
{
private
final
Connection
connection
;
public
TransactionLedgerRepository
(
Connection
connection
)
{
this
.
connection
=
connection
;
}
public
Optional
<
Transaction
>
findByAccountAndSeqKey
(
String
accountId
,
long
sequenceKey
)
throws
SQLException
{
String
sql
=
"SELECT * FROM transaction_ledger WHERE account_id = ? AND sequence_key = ?"
;
try
(
PreparedStatement
pstmt
=
connection
.
prepareStatement
(
sql
))
{
pstmt
.
setString
(
1
,
accountId
);
pstmt
.
setLong
(
2
,
sequenceKey
);
try
(
ResultSet
rs
=
pstmt
.
executeQuery
())
{
if
(
rs
.
next
())
{
return
Optional
.
of
(
mapRowToTransaction
(
rs
));
}
}
}
return
Optional
.
empty
();
}
public
void
save
(
String
accountId
,
long
sequenceKey
,
BigDecimal
amount
,
String
outcome
,
BigDecimal
balanceAfter
,
String
responseMessage
)
throws
SQLException
{
String
sql
=
"INSERT INTO transaction_ledger (account_id, sequence_key, amount, outcome, balance_after, response_message, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)"
;
try
(
PreparedStatement
pstmt
=
connection
.
prepareStatement
(
sql
))
{
pstmt
.
setString
(
1
,
accountId
);
pstmt
.
setLong
(
2
,
sequenceKey
);
pstmt
.
setBigDecimal
(
3
,
amount
);
pstmt
.
setString
(
4
,
outcome
);
pstmt
.
setBigDecimal
(
5
,
balanceAfter
);
pstmt
.
setString
(
6
,
responseMessage
);
pstmt
.
setTimestamp
(
7
,
Timestamp
.
from
(
Instant
.
now
()));
pstmt
.
executeUpdate
();
}
}
private
Transaction
mapRowToTransaction
(
ResultSet
rs
)
throws
SQLException
{
return
new
Transaction
(
rs
.
getLong
(
"id"
),
rs
.
getString
(
"account_id"
),
rs
.
getLong
(
"sequence_key"
),
rs
.
getBigDecimal
(
"amount"
),
rs
.
getString
(
"outcome"
),
rs
.
getBigDecimal
(
"balance_after"
),
rs
.
getString
(
"response_message"
),
rs
.
getTimestamp
(
"timestamp"
).
toInstant
()
);
}
}
src/test/java/com/banking/models/ModelTest.java
0 → 100644
View file @
89f94d34
package
com
.
banking
.
models
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.junit.jupiter.api.*
;
import
java.math.BigDecimal
;
import
java.util.Optional
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
ModelTest
{
private
final
ObjectMapper
mapper
=
new
ObjectMapper
();
@Test
void
testAccountModel
()
{
Account
account
=
new
Account
(
"ACC1"
,
new
BigDecimal
(
"100.00"
),
10L
);
assertEquals
(
"ACC1"
,
account
.
accountId
());
assertEquals
(
0
,
new
BigDecimal
(
"100.00"
).
compareTo
(
account
.
balance
()));
assertEquals
(
10L
,
account
.
lastProcessedSeqKey
());
}
@Test
void
testRequestDTOSerialization
()
throws
Exception
{
RequestDTO
request
=
new
RequestDTO
(
"ACC1"
,
new
BigDecimal
(
"20.00"
),
101L
,
false
);
String
json
=
mapper
.
writeValueAsString
(
request
);
RequestDTO
deserialized
=
mapper
.
readValue
(
json
,
RequestDTO
.
class
);
assertEquals
(
"ACC1"
,
deserialized
.
accountId
());
assertEquals
(
0
,
new
BigDecimal
(
"20.00"
).
compareTo
(
deserialized
.
amount
()));
assertEquals
(
101L
,
deserialized
.
sequenceKey
());
assertFalse
(
deserialized
.
isRetry
());
}
@Test
void
testResponseDTOSerialization
()
throws
Exception
{
ResponseDTO
response
=
new
ResponseDTO
(
"SUCCESS"
,
new
BigDecimal
(
"80.00"
),
"Success message"
);
String
json
=
mapper
.
writeValueAsString
(
response
);
ResponseDTO
deserialized
=
mapper
.
readValue
(
json
,
ResponseDTO
.
class
);
assertEquals
(
"SUCCESS"
,
deserialized
.
status
());
assertEquals
(
0
,
new
BigDecimal
(
"80.00"
).
compareTo
(
deserialized
.
balance
()));
assertEquals
(
"Success message"
,
deserialized
.
message
());
}
@Test
void
testResponseDTOResponseWithNullBalance
()
throws
Exception
{
ResponseDTO
response
=
new
ResponseDTO
(
"INVALID_ACCOUNT"
,
null
,
"Account not found"
);
String
json
=
mapper
.
writeValueAsString
(
response
);
ResponseDTO
deserialized
=
mapper
.
readValue
(
json
,
ResponseDTO
.
class
);
assertEquals
(
"INVALID_ACCOUNT"
,
deserialized
.
status
());
assertNull
(
deserialized
.
balance
());
assertEquals
(
"Account not found"
,
deserialized
.
message
());
}
@Test
void
testBigDecimalPrecision
()
{
BigDecimal
amount
=
new
BigDecimal
(
"100.0000000001"
);
RequestDTO
request
=
new
RequestDTO
(
"ACC1"
,
amount
,
101L
,
false
);
assertEquals
(
amount
,
request
.
amount
());
}
@Test
void
testTransactionModel
()
{
Transaction
tx
=
new
Transaction
(
1L
,
"ACC1"
,
101L
,
new
BigDecimal
(
"20.00"
),
"SUCCESS"
,
new
BigDecimal
(
"80.00"
),
"Msg"
,
java
.
time
.
Instant
.
now
()
);
assertEquals
(
"ACC1"
,
tx
.
accountId
());
assertEquals
(
0
,
new
BigDecimal
(
"20.00"
).
compareTo
(
tx
.
amount
()));
assertEquals
(
"SUCCESS"
,
tx
.
outcome
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment