Skip to content

justjordan15/eCommerceAPI-Web-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ByteDistrict eCommerce API

A comprehensive RESTful API for an eCommerce platform built with Spring Boot, featuring user authentication, product management, shopping cart functionality, and category management.

🚀 Features

Core Functionality

  • User Authentication & Authorization - JWT-based authentication with role-based access control
  • Product Management - CRUD operations for products with pagination and search
  • Category Management - Organize products into categories
  • Shopping Cart - Add, update, and manage cart items
  • User Management - User registration, login, and profile management
  • Image Upload - Support for product image uploads
  • Search & Filtering - Search products by keywords with pagination

Security Features

  • JWT token-based authentication
  • Role-based authorization (USER, ADMIN)
  • Password encryption with BCrypt
  • CORS configuration
  • Secure endpoints with Spring Security

🛠️ Technology Stack

  • Framework: Spring Boot 3.4.2
  • Language: Java 21
  • Security: Spring Security with JWT
  • Database: H2 (In-memory for development)
  • ORM: Spring Data JPA with Hibernate
  • Build Tool: Maven
  • Documentation: Swagger/OpenAPI
  • Validation: Bean Validation (Hibernate Validator)
  • Mapping: ModelMapper
  • Utilities: Lombok

📁 Project Structure

src/
├── main/
│   ├── java/com/bytedistrict/eCommerceAPI/
│   │   ├── config/          # Configuration classes
│   │   ├── controller/      # REST controllers
│   │   ├── model/          # Entity classes
│   │   ├── payload/        # DTOs and response objects
│   │   ├── repositories/   # Data access layer
│   │   ├── security/       # Security configuration and JWT
│   │   ├── service/        # Business logic layer
│   │   ├── util/          # Utility classes
│   │   └── exceptions/     # Custom exception classes
│   └── resources/
│       ├── application.properties
│       └── application.properties.example
└── test/                   # Test classes

🚦 Getting Started

Prerequisites

  • Java 21 or higher
  • Maven 3.6+
  • Git

Installation

  1. Clone the repository

    git clone <repository-url>
    cd eCommerceAPI-Web-Server
  2. Configure the application

    cp src/main/resources/application.properties.example src/main/resources/application.properties

    Update the JWT secret and other sensitive configurations in application.properties:

    spring.app.jwtSecret=your_jwt_secret_here
    spring.app.jwtExpirationMs=your_expiration_time_here
  3. Build the project

    ./mvnw clean install
  4. Run the application

    ./mvnw spring-boot:run

The application will start on http://localhost:8080

Database Access

  • H2 Console: http://localhost:8080/h2-console
  • JDBC URL: jdbc:h2:mem:eComm
  • Username: sa
  • Password: (leave empty)

📚 API Documentation

Base URL

http://localhost:8080/api

Authentication Endpoints

Method Endpoint Description Access
POST /auth/signin User login Public
POST /auth/signup User registration Public
POST /auth/signout User logout Authenticated
GET /auth/user Get user details Authenticated

Product Endpoints

Method Endpoint Description Access
GET /public/products Get all products (paginated) Public
GET /public/products/keyword/{keyword} Search products Public
POST /admin/categories/{categoryId}/product Add new product Admin
PUT /admin/products/{productId} Update product Admin
DELETE /admin/products/{productId} Delete product Admin

Category Endpoints

Method Endpoint Description Access
GET /public/categories Get all categories (paginated) Public
POST /public/categories Create category Public
PUT /public/categories/{categoryId} Update category Public
DELETE /admin/categories/{categoryId} Delete category Admin

Cart Endpoints

Method Endpoint Description Access
POST /carts/products/{productId}/quantity/{quantity} Add product to cart Authenticated
GET /carts Get all carts Authenticated
GET /carts/users/cart Get user's cart Authenticated
PUT /carts/products/{productId}/quantity/{operation} Update cart item Authenticated

Query Parameters

Most endpoints support pagination and sorting:

  • pageNumber (default: 0)
  • pageSize (default: 50)
  • sortBy (default: varies by endpoint)
  • sortOrder (default: asc)

🔐 Authentication

The API uses JWT (JSON Web Tokens) for authentication:

  1. Register a new user via /auth/signup
  2. Login via /auth/signin to receive a JWT token
  3. Include the JWT token in subsequent requests via cookies or Authorization header
  4. Logout via /auth/signout to invalidate the token

User Roles

  • USER: Basic user with access to public endpoints and cart management
  • ADMIN: Administrative access to product and category management

🧪 Testing

Run the test suite:

./mvnw test

🔧 Configuration

Key configuration properties in application.properties:

# Application
spring.application.name=eCommerceAPI

# Database
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:eComm

# JWT Configuration
spring.app.jwtSecret=your_secret_key
spring.app.jwtExpirationMs=3000000
spring.app.jwtCookieName=springBootEcom

# File Upload
project.image=images/

# Logging
logging.level.org.springframework=DEBUG

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

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

🐛 Known Issues

  • Some admin endpoints are currently commented out in security configuration for testing
  • Image upload functionality is implemented but may need additional configuration

📞 Support

For support and questions, please open an issue in the repository.


Built with ❤️ by ByteDistrict

About

Spring & Spring Boot / Spring MVC / Spring Security & JWT / Spring Cloud & Hibernate / Thyme leaf

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages