A simple Spring Boot REST API for managing vehicles and owners in a garage, using MongoDB as the database.
- Java: 25
- Spring Boot: 4.0.0 (Web MVC, Actuator, Devtools)
- Database: MongoDB
- Build Tool: Maven
- Other: Spring Data MongoDB, Lombok (for annotations)
- 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)
- Models and services are implemented for owners, but REST endpoints are not yet exposed (only vehicle endpoints are available in the controller).
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
- Java: 21 or higher (project configured for Java 25)
- Maven: 3.8 or higher
- MongoDB: Running locally on
mongodb://localhost:27017
-
Clone the repository (if applicable):
git clone https://github.com/lowkeyarhan/GarageManagement.git cd garage -
Start MongoDB:
brew services start mongodb-community # On macOS with Homebrew # Or use Docker: docker run -d -p 27017:27017 --name mongodb mongo:latest
-
Build the project:
./mvnw clean compile
-
Run the application:
./mvnw spring-boot:run
The application will start on
http://localhost:8080.
The default configuration is in src/main/resources/application.yaml:
spring:
application:
name: garage
mongodb:
uri: mongodb://localhost:27017/garage_DBYou can override these settings by creating a application-local.yaml or using environment variables.
http://localhost:8080/api
- Method:
GET - URL:
/api/vehicles/ - Response:
200 OKwith list of vehicles - Example Response:
[ { "id": "507f1f77bcf86cd799439011", "name": "Tesla Model S", "model": "Model S", "year": 2024, "color": "Red", "price": 79999.99, "ownerId": 1 } ]
- Method:
GET - URL:
/api/vehicles/id/{vehicleId} - Path Parameter:
vehicleId(String) - Response:
200 OKwith vehicle object or404 Not Found
- 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
- 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
- Method:
DELETE - URL:
/api/vehicles/id/{vehicleId} - Path Parameter:
vehicleId(String) - Response:
true(boolean) on success
- Method:
GET - URL:
/api/vehicles/color/{color} - Path Parameter:
color(String) - Response:
200 OKwith list of vehicles
- Method:
GET - URL:
/api/vehicles/price/{maxPrice} - Path Parameter:
maxPrice(double) - Response:
200 OKwith list of vehicles less than the price
- Method:
GET - URL:
/api/vehicles/year/{minYear} - Path Parameter:
minYear(int) - Response:
200 OKwith list of vehicles greater than the year
Currently, no REST endpoints are implemented for owners. The models, repositories, and services exist but are not exposed via controllers.
Run the tests with:
./mvnw test