A REST API for money transfers between accounts.
- Koin - Dependency Injection Framework
- JaCoCo - code coverage
- hibernate-validator - request validation
- JUnit5 - testing
- kotlinx-coroutines-core - validating/testing concurrency
- mockito - mocking in tests
- assertJ - assertions in tests
- gson - json parser for tests
Run the below command on terminal to build the jar:
./gradlew clean build
A fat-jar will be created in location ./build/libs/internal-transfers-api-1.0.0-all.jar
Once you have built the jar using above step, you can start the application by any of the below commands:
./gradlew run
java -jar ./build/libs/internal-transfers-api-1.0.0-all.jar
Make sure docker is running on your machine and then trigger the docker.sh
script located in the resources/scripts
path.
./resources/scripts/docker.sh
The above script will run the application on post 8090 and will also run the swagger-ui docker container for api-spec on port 8091.
Run the below command on terminal to test the application and generate a test report and a JaCoCo code coverage report:
./gradlew clean test
Test reports can be found at ./build/reports/tests/test/index.html
Code Coverage reports can be found at ./build/reports/jacoco/test/html/index.html
This api doesn't have a Swagger/OpenAPI integration because of the lack of an official/cleaner OpenAPI support for Ktor Framework.
OpenAPI spec for this service is available under docs
directory in api-spec.yml
file. Also, the available end-points information has been added below.
GET localhost:8090/accounts
- Returns all the accounts available.
(For the ease of testability, I have created 10 random accounts already)
curl --request GET \
--url http://localhost:8090/accounts
[
{
"id": "833fb7f0-9549-4dbd-b570-2d9e4be2b0ef",
"balance": 605.43
},
{
"id": "89861c9e-5ca8-4814-a5c0-a284ea23d9e3",
"balance": 86.84
}
]
POST localhost:8090/accounts
- Creates a new account.
curl --request POST \
--url http://localhost:8090/accounts \
--header 'content-type: application/json' \
--data '{
"balance": "123"
}'
{
"id": "3c8754aa-6fbe-4b72-ad08-dcbf29501ea3",
"balance": 123
}
POST localhost:8090/internal/transfer/
- Transfers Money from one account to another
curl --request POST \
--url http://localhost:8090/internal/transfer/ \
--header 'content-type: application/json' \
--data '{
"senderAccountId": "833fb7f0-9549-4dbd-b570-2d9e4be2b0ef",
"receiverAccountId": "3c8754aa-6fbe-4b72-ad08-dcbf29501ea3",
"amount": 12
}'
No json response for this endpoint, just HTTP status gets returned.