A comprehensive RESTful API built with Java Spring Boot for managing hotel operations including room management, reservations, billing, and manager authentication.
- Create, read, update, and delete hotel rooms
- Check room availability for specific date ranges
- Filter available rooms by check-in and check-out dates
- Room type categorization (Standard, Deluxe, Suite, etc.)
- Create and manage guest reservations
- Prevent double-booking with overlap detection
- View all reservations or specific reservation details
- Update and cancel reservations
- Automatic bill calculation based on nights stayed
- Support for reservation extensions
- Tax calculation (12%)
- Service charge calculation (5%)
- Detailed billing breakdown
- Secure JWT-based authentication
- BCrypt password hashing
- Role-based access control
- Protected endpoints for critical operations
- 30 minutes token validity
- Java 17+
- Spring Boot 3.x
- Spring Security - Authentication and authorization
- Spring Data JPA - Database interaction
- JWT (JSON Web Tokens) - Secure token-based authentication
- BCrypt - Password hashing
- MySQL - Database
- Maven - Dependency management
- Lombok - Boilerplate code reduction
http://localhost:8080/api
POST /api/managers/login
Content-Type: application/json
{
"username": "admin",
"password": "admin123"
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"manager": {
"id": "MGR_1234567890",
"username": "admin",
"name": "System Administrator",
"email": "admin@hotel.com"
},
"message": "Login successful"
}POST /api/rooms
Authorization: Bearer <token>
Content-Type: application/json
{
"roomNumber": 101,
"roomType": "Deluxe",
"price": 150.00,
"isAvailable": true
}GET /api/roomsGET /api/rooms/101GET /api/rooms/available?checkIn=2024-12-01&checkOut=2024-12-05PUT /api/rooms/101
Authorization: Bearer <token>
Content-Type: application/json
{
"roomType": "Suite",
"price": 250.00,
"isAvailable": true
}DELETE /api/rooms/101
Authorization: Bearer <token>POST /api/reservations
Content-Type: application/json
{
"roomNumber": 101,
"guestName": "John Doe",
"guestEmail": "john@example.com",
"guestPhone": "+1234567890",
"checkIn": "2024-12-01",
"checkOut": "2024-12-05",
"numberOfGuests": 2
}GET /api/reservationsGET /api/reservations/1PUT /api/reservations/1
Content-Type: application/json
{
"guestName": "John Updated",
"checkIn": "2024-12-01",
"checkOut": "2024-12-06"
}DELETE /api/reservations/1POST /api/reservations/1/bill?extended=falseResponse:
{
"reservationId": 1,
"totalPayable": "702.00"
}POST /api/reservations/1/bill?extended=true&newCheckOut=2024-12-10POST /api/create/manager
Authorization: Bearer <token>
Content-Type: application/json
{
"username": "manager2",
"passwordHash": "password123",
"name": "Jane Smith",
"email": "jane@hotel.com"
}GET /api/managers/allGET /api/managers/id/MGR_1234567890GET /api/managers/adminPUT /api/managers/MGR_1234567890
Authorization: Bearer <token>
Content-Type: application/json
{
"name": "Updated Name",
"email": "updated@hotel.com"
}DELETE /api/managers/MGR_1234567890
Authorization: Bearer <token>This application uses JWT (JSON Web Token) based authentication.
- Login: Manager logs in with username and password
- Token Generation: Server validates credentials and returns JWT token
- Token Usage: Include token in subsequent requests:
Authorization: Bearer <your_jwt_token> - Token Expiry: Tokens expire after 30 minutes
The following operations require authentication:
- ✅ Create Room (
POST /api/rooms) - ✅ Update Room (
PUT /api/rooms/{id}) - ✅ Delete Room (
DELETE /api/rooms/{id}) - ✅ Create Manager (
POST /api/create/manager) - ✅ Update Manager (
PUT /api/managers/{id}) - ✅ Delete Manager (
DELETE /api/managers/{id})
- Passwords are hashed using BCrypt with salt rounds of 12
- Plain text passwords are never stored in the database
- Tokens are signed using HS256 algorithm
- Secret key should be stored in environment variables (not hardcoded)
- Tokens expire after 30 minutes
CREATE TABLE room (
room_number INT PRIMARY KEY,
room_type VARCHAR(50),
price DECIMAL(10,2),
is_available BOOLEAN
);CREATE TABLE reservation (
reservation_id INT PRIMARY KEY AUTO_INCREMENT,
room_number INT,
guest_name VARCHAR(100),
guest_email VARCHAR(100),
guest_phone VARCHAR(20),
check_in DATE,
check_out DATE,
number_of_guests INT,
FOREIGN KEY (room_number) REFERENCES room(room_number)
);CREATE TABLE manager (
id VARCHAR(50) PRIMARY KEY,
username VARCHAR(50) UNIQUE,
password_hash VARCHAR(255),
name VARCHAR(100),
email VARCHAR(100)
);- Abhishek Sahay - CheckInn - abhi5hek001
- Spring Boot Documentation
- JWT.io for JWT insights
- BCrypt for password hashing
- Spring Security team
⭐ If you found this project helpful, please give it a star!