This project is a simple bank API built using Go, Echo framework, and PostgreSQL. The API supports user authentication, account management, and transaction operations, including deposits, withdrawals, transfers, and fetching account history with pagination.
- User Authentication (Signup, Login)
- Account Management (Deposit, Withdraw, Transfer)
- Transaction History with Pagination
- Secure Access to Accounts
- Go
- Echo framework
- PostgreSQL
- GORM
- JWT for authentication
- Go (version 1.16+)
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/yourusername/bank-api.git cd bank-api
-
Create a
.env
file with the following environment variables:DB_HOST=db DB_USER=postgres DB_PASSWORD=postgres DB_NAME=bank JWT_SECRET=your_jwt_secret
-
Run Docker Compose to start PostgreSQL:
docker-compose up -d
-
Run the application:
go run main.go
-
Signup:
- URL:
/signup
- Method:
POST
- Body:
{ "username": "testuser", "password": "testpassword" }
- URL:
-
Login:
- URL:
/login
- Method:
POST
- Body:
{ "username": "testuser", "password": "testpassword" }
- URL:
-
Deposit:
- URL:
/deposit
- Method:
POST
- Headers:
Authorization: Bearer <jwt_token>
- Body:
{ "account_id": 1, "amount": 100.0 }
- URL:
-
Withdraw:
- URL:
/withdraw
- Method:
POST
- Headers:
Authorization: Bearer <jwt_token>
- Body:
{ "account_id": 1, "amount": 50.0 }
- URL:
-
Transfer:
- URL:
/transfer
- Method:
POST
- Headers:
Authorization: Bearer <jwt_token>
- Body:
{ "from_account_id": 1, "to_account_id": 2, "amount": 25.0 }
- URL:
-
Get Account History:
- URL:
/account/:account_id/history
- Method:
GET
- Headers:
Authorization: Bearer <jwt_token>
- Query Parameters:
page
: Page number (default: 1)limit
: Number of transactions per page (default: 10)
- URL:
-
Get Transfer History:
- URL:
/account/:account_id/transfer-history
- Method:
GET
- Headers:
Authorization: Bearer <jwt_token>
- Query Parameters:
page
: Page number (default: 1)limit
: Number of transactions per page (default: 10)
- URL:
You can import the Postman collection provided in the postman_collection.json
file to test the API endpoints.
This project is licensed under the MIT License. See the LICENSE file for details..