A Spring Boot REST API that enables user management and wallet operations including creating users, managing wallets, and handling deposits/withdrawals.
- User-Wallet Relationship: There's a one-to-many relationship between users and wallets.
- Java 17
- Spring Boot
- PostgreSQL
- Docker
- JPA/Hibernate
- Maven
Before running this application, make sure you have the following installed:
- Java Development Kit (JDK) 17 or later
- Docker and Docker Compose
- Maven
- Git
git clone https://github.com/kristiyankiryakov/Wall-e.git
cd Wall-eThe application uses PostgreSQL running in a Docker container. Start the database using Docker Compose:
docker compose upThis will start a PostgreSQL instance with the following configuration:
- Port: 5432
- Database: postgres
- Username: postgres
- Password: postgres
The application uses profile-specific YAML configuration:
application.yml: Contains the base configuration and production settingsapplication-dev.yml: Contains development-specific settings with default JWT values
The development profile is activated by default for ease of testing.
For production deployments, ensure you provide the actual JWT configuration through environment variables:
- JWT_SECRET
- JWT_EXPIRATION
Build the application using Maven:
mvn clean installRun the application:
mvn spring-boot:runThe API will be available at http://localhost:8080
- POST
/api/auth/register - Creates a new user account
- Request Body (
AuthRequest):{ "username": "string", // Required "password": "string" // Required, minimal length = 6 } - Response (
AuthResponse):{ "token": "string" }
- POST
/api/auth/login - Authenticates user
- Request Body (
AuthRequest):{ "username": "string", // Required "password": "string" // Required } - Response (
AuthResponse):{ "token": "string" }
- POST
/api/wallets - Creates a new wallet for a user
- Request Body(
WalletRequest){ "walletName": "string" // Required } - Response (
WalletResponse):{ "id" : "number", "name": "string", "owner": "string", // Username of the owner "balance": "number" }
- GET
/api/wallets/{walletId} - Retrieves the current wallet
- Path Variables:
walletId: The ID of the wallet
- Response (
WalletResponse):{ "id" : "number", "name": "string", "owner": "string", // Username of the owner "balance": "number" }
- PUT
/api/wallets/{walletId}/deposit - Adds funds to a wallet
- Path Variables:
walletId: The ID of the wallet
- Request Body (
TransactionRequest):{ "amount": "number" // Required, must be positive } - Response (
TransactionResponse):{ "walletId": "number", "userId": "number", "previousBalance": "number", "currentBalance": "number", "transactionType": "string", "transactionAmount": "number" }
- PUT
/api/wallets/{walletId}/withdraw - Withdraws funds from a wallet
- Path Variables:
walletId: The ID of the wallet
- Request Body (
TransactionRequest):{ "amount": "number" // Required, must be positive } - Response (
TransactionResponse):{ "walletId": "number", "userId": "number", "previousBalance": "number", "currentBalance": "number", "transactionType": "string", "transactionAmount": "number" }
- GET
/api/transactions/{walletId} - Retrieves the transactions of a wallet
- Path Variables:
walletId: The ID of the wallet- Response (
List<TransactionDto>):{ "id" : "number", "amount": "number", "type": "string", "walletId": "number" }
Execute the test suite using Maven:
mvn testYou can use tools like Postman or curl to test the API endpoints. Here's an example using curl:
# Create a new user
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "John_Doe", "password": "john123"}'The following endpoints require authentication via Bearer token in the Authorization header:
# Wallet endpoints
curl -X GET http://localhost:8080/api/wallets \
-H "Authorization: Bearer your_jwt_token_here"
# Transaction endpoints
curl -X GET http://localhost:8080/api/transactions \
-H "Authorization: Bearer your_jwt_token_here"This project uses GitHub Actions for continuous integration and deployment. The pipeline is triggered on:
- Push to the
mainbranch - Pull requests to the
mainbranch
The workflow file is located at .github/workflows/ci-cd.yml and consists of the following steps:
The build job runs on Ubuntu latest and sets up a PostgreSQL service container for integration tests.
- Image: postgres:latest
- Credentials:
- Username: postgres
- Password: postgres
- Database: postgres
- Port: 5432
- Health checks configured for reliability
- Checkout Code
- Uses:
actions/checkout@v3 - Fetches the repository code
- Setup JDK
- Uses:
actions/setup-java@v3 - Configures JDK 17 (Temurin distribution)
- Cache Dependencies
- Uses:
actions/cache@v3 - Caches Maven dependencies to speed up builds
- Cache key based on pom.xml hash
- Build Project
- Runs:
mvn clean install - Compiles the code and packages the application
- Run Tests
- Runs:
mvn test -X - Executes all tests with detailed logging
name: Java CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: --health-cmd="pg_isready -U user" --health-timeout=30s --health-start-period=5s --health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Cache Maven repository
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven
- name: Build with Maven
run: mvn clean install
- name: Run tests
run: mvn test -XYou can view the status of pipeline runs in the "Actions" tab of the GitHub repository.