This Go project provides a simple API for managing bank accounts. The project includes functionality to create a bank account, retrieve a list of all accounts, update account details and amounts, and remove a bank account.
Endpoint: POST /account/create
Functionality: Allows the creation of a new bank account by providing details such as name, government ID, address, and initial amount.
Endpoint: GET /accounts/list
Functionality: Retrieves a list of all bank accounts stored in the MongoDB database.
Endpoint: PUT /account/update/{id}
Functionality: Updates the details and amount of a specific bank account identified by its MongoDB ObjectID. Requires providing the updated parameters in the request body.
Endpoint: DELETE /account/remove/{id}
Functionality: Deletes a specific bank account identified by its MongoDB ObjectID.
-
Make sure you have Go installed on your machine.
-
Make sure you have MongoDB installed and running on your machine.
-
Install the necessary dependencies using:
go get gofr.dev/pkg/gofr go get go.mongodb.org/mongo-driver/mongo
-
To run the Project execute the following command in the terminal:
go run main.go
To facilitate the testing of the Bank Account Management API, you can use Postman, a popular API testing tool. Follow the steps below to test the various functionalities provided by the API.
-
Postman Installed: Ensure that you have Postman installed on your machine. If not, you can download it from Postman's official website.
-
Go Server Running: Make sure that your Go server is running. If not, start the server using the following command in the terminal:
go run main.go
Running Tests
-
Open Postman and create a new request collection.
-
Add requests for each endpoints with the specified details.
-
Click on the "Send" button to execute the requests and observe the responses.
-
Ensure that the responses match the expected results based on the API functionalities.
Example for the POST, GET, PUT AND DELETE
Endpoint: POST /account/create
Request:
- Method: POST
- URL:
http://localhost:8080/account/create
- Headers: Content-Type: application/json
- Body:
{ "name": "Tarun Gupta", "govid": "123456789", "address": "Main Street, Mumbai, Maharashtra", "amount": 1000 }
Endpoint: GET /accounts/list
Request:
- Method: GET
- URL:
http://localhost:8080/accounts/list
Endpoint: PUT /account/update/{id}
Request:
- Method: PUT
- URL: Replace
{id}
with the actual ObjectID of the bank account you want to update. Example:http://localhost:8080/account/update/5f5b4f1c7d6ff7e5884ea57c
- Headers: Content-Type: application/json
- Body:
{ "amount": 1500 }
Endpoint: DELETE /account/remove/{id}
Request:
- Method: DELETE
- URL: Replace
{id}
with the actual ObjectID of the bank account you want to remove. Example:http://localhost:8080/account/remove/5f5b4f1c7d6ff7e5884ea57c