# EVM Wheels — Car Rental Management

A Spring Boot 3 + Thymeleaf + PostgreSQL web app for managing a self-drive car rental business.

## Features

- **Public site** — landing page with hero, search bar, and featured cars
- **Browse & detail** — `/cars` (with optional date-range availability filter) and `/cars/{id}`
- **Auth** — username/password registration & login (Spring Security + BCrypt)
- **Customer flow** — book a car, view your bookings at `/my-bookings`
- **Admin panel** — `/admin` dashboard, full CRUD for cars, manage all bookings & update status
- **Date-range conflict detection** — prevents double-booking the same car

## Stack

| Layer    | Choice                         |
|----------|--------------------------------|
| Runtime  | Java 17, Spring Boot 3.3       |
| Web      | Spring MVC + Thymeleaf         |
| Data     | Spring Data JPA + Hibernate    |
| DB       | PostgreSQL                     |
| Security | Spring Security 6 + BCrypt     |
| Build    | Maven                          |

## Prerequisites

- JDK 17+
- Maven 3.9+
- PostgreSQL 13+ running locally

## Database setup

```sql
CREATE DATABASE evm_wheels;
```

By default the app connects with `postgres` / `postgres` on `localhost:5432/evm_wheels`. Override via env vars or by editing [src/main/resources/application.properties](src/main/resources/application.properties):

```bash
export DB_URL=jdbc:postgresql://localhost:5432/evm_wheels
export DB_USER=postgres
export DB_PASSWORD=postgres
```

Hibernate's `ddl-auto=update` creates the schema on first run, and `data.sql` seeds 6 demo cars. Users are seeded from [DataInitializer.java](src/main/java/com/evmwheels/carrental/config/DataInitializer.java) using the real password encoder.

## Run

```bash
mvn spring-boot:run
```

Then open <http://localhost:8080>.

## Seeded accounts

| Role     | Username | Password   |
|----------|----------|------------|
| Admin    | `admin`  | `admin123` |
| Customer | `demo`   | `demo1234` |

Change these immediately if you deploy this anywhere real.

## Project layout

```
src/main/java/com/evmwheels/carrental/
├── CarRentalApplication.java
├── config/         SecurityConfig, DataInitializer
├── controller/     Home, Car, Booking, Auth, Admin
├── model/          Car, User, Booking + enums
├── repository/     Spring Data JPA interfaces
└── service/        Business logic (booking conflict checks, etc.)

src/main/resources/
├── application.properties
├── data.sql                  seed cars
├── static/{css,images}/      assets
└── templates/                Thymeleaf views
```

## Routes

| Method | Path                            | Access     |
|--------|----------------------------------|------------|
| GET    | `/`                              | public     |
| GET    | `/cars`, `/cars/{id}`            | public     |
| GET/POST | `/login`, `/register`          | public     |
| GET/POST | `/cars/{id}/book`              | customer   |
| GET    | `/my-bookings`                   | customer   |
| GET    | `/admin`                         | admin      |
| GET/POST | `/admin/cars`, `/admin/cars/**` | admin     |
| GET    | `/admin/bookings`                | admin      |
| POST   | `/admin/bookings/{id}/status`    | admin      |
