- Java 11 or higher
- Apache Maven
- MongoDB cluster
- Temporal CLI
Set the MongoDB connection string as an environment variable.
This is likely to be mongodb://127.0.0.1:27017
for a local MongoDB cluster.
export MONGO_CONNECTION_STRING="your_connection_string_here"
set MONGO_CONNECTION_STRING=your_connection_string_here
$env:MONGO_CONNECTION_STRING="your_connection_string_here"
Use Maven to compile the code:
mvn compile
mvn exec:java -Dexec.mainClass="org.mongodb.banking.Main"
This starts the REST API server on http://localhost:8480
.
It also launches a GUI that you can use to view the available
bank accounts and control whether each of them will accept
requests.
All endpoints are available at http://localhost:8480
.
Creates a new bank account.
Endpoint:
GET /api/createBank?bankName={name}&initialBalance={balance}
Example:
curl -X GET "http://localhost:8480/api/createBank?bankName=Maria&initialBalance=1000"
Response:
{
"status": "SUCCESS",
"message": "Bank created successfully"
}
Retrieve the balance of a bank account.
Endpoint:
GET /api/balance?bankName={name}
Example:
curl -X GET "http://localhost:8480/api/balance?bankName=Maria"
Response:
{
"status": "SUCCESS",
"balance": 1000
}
Deposit money into a specific bank.
Endpoint:
GET /api/deposit?bankName={name}&amount={amount}&idempotencyKey={key}
Example:
curl -X GET "http://localhost:8480/api/deposit?bankName=Maria&amount=500&idempotencyKey=key123"
Response:
{
"status": "SUCCESS",
"transaction-id": "D123456789"
}
Withdraw money from a specific bank.
Endpoint:
GET /api/withdraw?bankName={name}&amount={amount}&idempotencyKey={key}
Example:
curl -X GET "http://localhost:8480/api/withdraw?bankName=Maria&amount=200&idempotencyKey=key456"
Response:
{
"status": "SUCCESS",
"transaction-id": "W987654321"
}
-
Start the Backend Service:
mvn exec:java -Dexec.mainClass="org.mongodb.banking.Main"
-
Test API Endpoints:
- Use the provided
curl
commands to interact with the service. - Verify the expected responses.
- Use the provided
-
Simulate Downtime:
- Stop a bank in the GUI (Stop button).
- Attempt a transaction and observe that it fails due to the bank being offline.
-
Add and Remove Banks:
-
Add new banks using the
createBank
API. -
Remove a bank directly from the MongoDB database:
use bankingdemo db.accounts.deleteOne({ bankName: "Maria" })
-
Verify that the UI updates to reflect the changes.
-
If the application cannot connect to MongoDB, ensure the MONGO_CONNECTION_STRING
environment variable is set correctly.
If the service is unreachable, ensure the backend server is running on http://localhost:8480
.
Ensure the MongoDB instance is running and accessible from the application.