Skip to content

A clean Spring Boot + MongoDB REST API for managing vehicles and owners, built with DTOs, mappers, services, and a modular layered architecture.

Notifications You must be signed in to change notification settings

lowkeyarhan/GarageManagement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Garage Management API

A simple Spring Boot REST API for managing vehicles and owners in a garage, using MongoDB as the database.

Tech Stack

  • Java: 25
  • Spring Boot: 4.0.0 (Web MVC, Actuator, Devtools)
  • Database: MongoDB
  • Build Tool: Maven
  • Other: Spring Data MongoDB, Lombok (for annotations)

Features

Vehicle Management

  • Create Vehicle: Add a new vehicle to the garage
  • Retrieve Vehicles: Get all vehicles or a specific vehicle by ID
  • Update Vehicle: Modify an existing vehicle's details
  • Delete Vehicle: Remove a vehicle from the garage
  • Filter Vehicles:
    • By color
    • By maximum price (vehicles less than specified price)
    • By minimum year (vehicles greater than specified year)

Owner Management

  • Models and services are implemented for owners, but REST endpoints are not yet exposed (only vehicle endpoints are available in the controller).

Project Structure

garage/
├── HELP.md                          # Help documentation
├── mvnw                             # Maven wrapper for Unix
├── mvnw.cmd                         # Maven wrapper for Windows
├── pom.xml                          # Maven configuration
├── README.md                        # This file
└── src/
    ├── main/
    │   ├── java/
    │   │   └── com/example/garage/
    │   │       ├── GarageApplication.java          # Main Spring Boot application class
    │   │       ├── controllers/
    │   │       │   └── VehicleController.java      # REST controller for vehicle endpoints
    │   │       ├── dto/
    │   │       │   ├── CreateOwnerDTO.java         # DTO for creating owners
    │   │       │   ├── CreateVehicleDTO.java       # DTO for creating vehicles
    │   │       │   ├── OwnerDTO.java               # DTO for owner responses
    │   │       │   └── VehicleDTO.java             # DTO for vehicle responses
    │   │       ├── mapper/
    │   │       │   ├── OwnerMapper.java            # Mapper for owner entity-DTO conversion
    │   │       │   └── VehicleMapper.java          # Mapper for vehicle entity-DTO conversion
    │   │       ├── models/
    │   │       │   ├── Owner.java                  # Owner entity model
    │   │       │   └── Vehicle.java                # Vehicle entity model
    │   │       ├── repository/
    │   │       │   ├── OwnerRepository.java        # Data access for owners
    │   │       │   └── VehicleRepository.java      # Data access for vehicles
    │   │       └── service/
    │   │           ├── OwnerService.java           # Business logic for owners
    │   │           └── VehicleService.java         # Business logic for vehicles
    │   └── resources/
    │       ├── application.yaml                    # Application configuration
    │       ├── static/                             # Static web resources
    │       └── templates/                          # Thymeleaf templates (if used)
    └── test/
        └── java/
            └── com/example/garage/
                └── GarageApplicationTests.java     # Unit tests

Getting Started

Prerequisites

  • Java: 21 or higher (project configured for Java 25)
  • Maven: 3.8 or higher
  • MongoDB: Running locally on mongodb://localhost:27017

Installation

  1. Clone the repository (if applicable):

    git clone https://github.com/lowkeyarhan/GarageManagement.git
    cd garage
  2. Start MongoDB:

    brew services start mongodb-community  # On macOS with Homebrew
    # Or use Docker: docker run -d -p 27017:27017 --name mongodb mongo:latest
  3. Build the project:

    ./mvnw clean compile
  4. Run the application:

    ./mvnw spring-boot:run

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

Configuration

The default configuration is in src/main/resources/application.yaml:

spring:
  application:
    name: garage
  mongodb:
    uri: mongodb://localhost:27017/garage_DB

You can override these settings by creating a application-local.yaml or using environment variables.

API Documentation

Base URL

http://localhost:8080/api

Vehicle Endpoints

1. Get All Vehicles

  • Method: GET
  • URL: /api/vehicles/
  • Response: 200 OK with list of vehicles
  • Example Response:
    [
      {
        "id": "507f1f77bcf86cd799439011",
        "name": "Tesla Model S",
        "model": "Model S",
        "year": 2024,
        "color": "Red",
        "price": 79999.99,
        "ownerId": 1
      }
    ]

2. Get Vehicle by ID

  • Method: GET
  • URL: /api/vehicles/id/{vehicleId}
  • Path Parameter: vehicleId (String)
  • Response: 200 OK with vehicle object or 404 Not Found

3. Create Vehicle

  • Method: POST
  • URL: /api/vehicles/
  • Headers: Content-Type: application/json
  • Body:
    {
      "name": "Tesla Model S",
      "model": "Model S",
      "year": 2024,
      "color": "Red",
      "price": 79999.99,
      "ownerId": 1
    }
  • Response: true (boolean) on success

4. Update Vehicle

  • Method: PUT
  • URL: /api/vehicles/id/{vehicleId}
  • Path Parameter: vehicleId (String)
  • Headers: Content-Type: application/json
  • Body: Same as create
  • Response: true (boolean) on success

5. Delete Vehicle

  • Method: DELETE
  • URL: /api/vehicles/id/{vehicleId}
  • Path Parameter: vehicleId (String)
  • Response: true (boolean) on success

6. Filter Vehicles by Color

  • Method: GET
  • URL: /api/vehicles/color/{color}
  • Path Parameter: color (String)
  • Response: 200 OK with list of vehicles

7. Filter Vehicles by Max Price

  • Method: GET
  • URL: /api/vehicles/price/{maxPrice}
  • Path Parameter: maxPrice (double)
  • Response: 200 OK with list of vehicles less than the price

8. Filter Vehicles by Min Year

  • Method: GET
  • URL: /api/vehicles/year/{minYear}
  • Path Parameter: minYear (int)
  • Response: 200 OK with list of vehicles greater than the year

Owner Endpoints

Currently, no REST endpoints are implemented for owners. The models, repositories, and services exist but are not exposed via controllers.

Testing

Run the tests with:

./mvnw test

About

A clean Spring Boot + MongoDB REST API for managing vehicles and owners, built with DTOs, mappers, services, and a modular layered architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages