Skip to content

A Spring Boot REST API for managing financial transactions with filtering, pagination, and classification capabilities.

Notifications You must be signed in to change notification settings

RickOliwer/transaction-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transaction API

A Spring Boot REST API for managing financial transactions with filtering, pagination, and classification capabilities.

🌐 Related Projects

Frontend Application: Transaction Frontend
A React-based frontend application that consumes this API to provide a user-friendly interface for managing transactions.

✨ Features

  • Transaction Management: Fetch and manage financial transaction data
  • Date Range Filtering: Filter transactions by start and end dates
  • Pagination: Paginated response for efficient data handling
  • Classification Updates: Update recipient classifications with validation
  • CORS Support: Configured for frontend integration (localhost:5173)
  • JSON Data Sources: Read and process JSON transaction data from files
  • Input Validation: Comprehensive validation for API requests

🛠 Tech Stack

  • Java with Spring Boot
  • Maven for dependency management
  • Lombok for reducing boilerplate code
  • Jackson for JSON processing (with JSR310 support for Java 8 date/time)
  • Jakarta Validation for request validation

🚀 Getting Started

Prerequisites

  • Java 8 or higher
  • Maven 3.6+

Installation

  1. Clone the repository:
git clone <repository-url>
cd transaction-api
  1. Build the project:
mvn clean install
  1. Run the application:
mvn spring-boot:run

The API will be available at http://localhost:8080

📋 API Endpoints

Get Transactions

GET /api/transactions

Retrieves a paginated list of transactions with optional date filtering.

Query Parameters:

Parameter Type Required Default Description
start LocalDate (yyyy-MM-dd) No - Start date for filtering
end LocalDate (yyyy-MM-dd) No - End date for filtering
page Integer No 0 Page number (0-based)
size Integer No 10 Number of items per page

Example Request:

GET /api/transactions?start=2023-01-01&end=2023-12-31&page=0&size=20

Response:

{
  "content": [
    {
      "date": "2023-06-15",
      "recipientId": "RECIPIENT_001",
      "description": "Coffee purchase",
      "amount": 4.5,
      "classification": "FOOD_AND_DINING"
    }
  ],
  "page": 0,
  "size": 20,
  "totalElements": 150,
  "totalPages": 8
}

Update Recipient Classification

POST /api/recipients/{recipientId}/classification

Updates the classification for a specific recipient.

Path Parameters:

Parameter Type Required Description
recipientId String Yes Unique identifier for the recipient

Request Body:

{
  "classification": "FOOD_AND_DINING"
}

Validation Rules:

  • Classification must not be blank
  • Must contain only uppercase letters and underscores
  • Maximum 50 characters

Response: 204 No Content on success

⚙️ Configuration

CORS

The application is configured to accept cross-origin requests from the frontend development server:

@CrossOrigin(origins = "http://localhost:5173")

This allows seamless integration with the frontend application during development.

Data Sources

The application reads transaction data from JSON files located in src/main/resources/:

  • transaction-service.json - Main transaction data
  • recipient-Ids.json - Recipient information

🏗 Architecture

Project Structure

src/main/java/dev/transaction/api/
├── controller/         # REST endpoints and request handling
├── service/           # Business logic and data processing
├── repository/        # Data access and JSON file handling
├── model/            # Entity classes and response models
├── dto/              # Data Transfer Objects for requests
└── exception/        # Custom exceptions and global error handling

Key Components

  • Controller Layer: REST endpoints with validation and CORS configuration
  • Service Layer: Business logic for transaction processing and classification updates
  • Repository Layer: Data access abstraction for JSON file operations
  • Model Layer: Entity classes with Lombok annotations for reduced boilerplate
  • Exception Handling: Global exception handler for consistent error responses

🔧 Development Notes

Key Dependencies

  • jackson-datatype-jsr310 - Java 8 LocalDate support in JSON serialization
  • lombok - Reduces boilerplate code with annotations
  • jakarta.validation - Request validation framework

Running with Frontend

  1. Start the backend API (this project):

    mvn spring-boot:run
  2. Clone and start the frontend:

    git clone https://github.com/RickOliwer/transaction-frontend.git
    cd transaction-frontend
    npm install
    npm run dev

The frontend will be available at http://localhost:5173 and will communicate with this API at http://localhost:8080.

📝 API Documentation

For detailed API documentation and testing, you can:

  1. Use the provided endpoint examples above
  2. Import the API into tools like Postman or Insomnia
  3. Check the frontend implementation for real-world usage examples

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Spring Boot REST API for managing financial transactions with filtering, pagination, and classification capabilities.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages