Skip to content

elijahmottey/hotel-management-system

Repository files navigation

Hotel Management System

A comprehensive hotel management system built with Spring Boot and Jakarta EE, featuring room management, booking capabilities, and cloud storage integration.

🏨 Features

  • Room Management: Create, update, delete, and view hotel rooms
  • Booking System: Handle room reservations and availability tracking
  • Image Storage: AWS S3 integration for room photos
  • User Management: Multi-user support with personalized room views
  • Advanced Search: Filter rooms by type, price, and availability dates
  • RESTful API: Clean REST endpoints for all operations

πŸ› οΈ Technology Stack

  • Backend: Spring Boot 3.x with Spring MVC
  • Database: Spring Data JPA with Jakarta Persistence
  • Cloud Storage: AWS S3 for image management
  • Code Simplification: Lombok for reduced boilerplate
  • Java Version: JDK 21
  • Build Tool: Maven
  • Architecture: Service-Repository pattern

πŸ“ Project Structure

hotel-management-system/
β”œβ”€β”€ src/main/java/com/LIVTech/hotel_management_system/
β”‚   β”œβ”€β”€ controller/          # REST controllers
β”‚   β”œβ”€β”€ service/             # Business logic layer
β”‚   β”‚   └── impl/           # Service implementations
β”‚   β”œβ”€β”€ repository/          # Data access layer
β”‚   β”œβ”€β”€ entity/             # JPA entities
β”‚   β”œβ”€β”€ dto/                # Data transfer objects
β”‚   └── config/             # Configuration classes
β”œβ”€β”€ src/main/resources/
β”‚   β”œβ”€β”€ application.yml     # Application configuration
β”‚   └── static/             # Static resources
└── pom.xml                # Maven dependencies

πŸš€ Getting Started

Prerequisites

  • Java 21 or higher
  • Maven 3.6+
  • AWS Account (for S3 storage)
  • Database (H2/MySQL/PostgreSQL)

Installation

  1. Clone the repository
git clone https://github.com/yourusername/hotel-management-system.git
   cd hotel-management-system
  1. Configure application properties
# src/main/resources/application.yml
   spring:
     datasource:
       url: jdbc:h2:mem:hoteldb
       username: sa
       password: password
     jpa:
       hibernate:
         ddl-auto: update
   
   aws:
     s3:
       bucket-name: your-hotel-images-bucket
       region: us-east-1
  1. Set up AWS credentials
# Option 1: Environment variables
   export AWS_ACCESS_KEY_ID=your-access-key
   export AWS_SECRET_ACCESS_KEY=your-secret-key
   
   # Option 2: AWS credentials file (~/.aws/credentials)
   [default]
   aws_access_key_id = your-access-key
   aws_secret_access_key = your-secret-key
  1. Build and run
mvn clean install
   mvn spring-boot:run

Or using Maven wrapper:

./mvnw clean install
   ./mvnw spring-boot:run

πŸ“‹ API Endpoints

Room Management

Method Endpoint Description
GET /api/rooms Get all rooms
POST /api/rooms Create new room (with optional photo upload)
GET /api/rooms/{id} Get room by ID
PUT /api/rooms/{id} Update room (with optional photo upload)
DELETE /api/rooms/{id} Delete room
GET /api/rooms/types Get all room types
GET /api/rooms/available Get all available rooms

Advanced Search & Filtering

Method Endpoint Description
GET /api/rooms/user/{userId} Get rooms by user
GET /api/rooms/user/{userId}/price/{maxPrice} Filter by user and max price
GET /api/rooms/available/{checkIn}/{checkOut}/{roomType} Search available rooms by date range and type

Request/Response Examples

Create Room with Photo:

curl -X POST "http://localhost:8080/api/rooms" \
  -H "Content-Type: multipart/form-data" \
  -F "room={\"roomType\":\"Deluxe\",\"roomDescription\":\"Spacious room with city view\",\"roomPrice\":150.00};type=application/json" \
  -F "photo=@room-image.jpg"

Search Available Rooms:

curl -X GET "http://localhost:8080/api/rooms/available/2024-12-01/2024-12-05/Deluxe"

πŸ’‘ Core Features

RoomService Implementation

The RoomServiceImpl provides comprehensive room management:

  • βœ… Smart Image Handling:

    • Upload new photos to S3
    • Preserve existing photos when no new upload
    • Handle both creation and updates seamlessly
  • πŸ” Advanced Search Capabilities:

    • Filter by user preferences
    • Price range filtering
    • Date-based availability checking
    • Room type categorization
  • πŸ›‘οΈ Robust Operations:

    • Transactional updates for data consistency
    • Input validation and error handling
    • Partial updates for room modifications

Key Methods

// Core CRUD operations
getAllRooms()                    // Fetch all rooms
createNewRoom(room, photo)       // Create with optional photo
updateRoom(id, room, photo)      // Update with optional photo
deleteRoom(id)                   // Remove room
getRoomById(id)                  // Find specific room

// Advanced queries  
getAllRoomsByUser(user)                           // User-specific rooms
getAllRoomsByUserAndPrice(user, maxPrice)         // Price filtering
getAvailableRoomByDateAndRoomType(start, end, type) // Availability search
getAllAvailableRooms()                            // All available rooms
getAllRoomTypes()                                 // Room type enumeration

πŸ”§ Configuration

Database Setup

H2 (Development):

spring:
  datasource:
    url: jdbc:h2:mem:hoteldb
    username: sa
    password: password
  h2:
    console:
      enabled: true
      path: /h2-console

MySQL (Production):

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/hotel_management
    username: ${DB_USERNAME:admin}
    password: ${DB_PASSWORD:password}
    driver-class-name: com.mysql.cj.jdbc.Driver

AWS S3 Configuration

aws:
  s3:
    bucket-name: ${AWS_S3_BUCKET_NAME:hotel-images-bucket}
    region: ${AWS_REGION:us-east-1}

Application Profiles

Development (application-dev.yml):

spring:
  jpa:
    show-sql: true
    hibernate:
      ddl-auto: create-drop
logging:
  level:
    com.LIVTech.hotel_management_system: DEBUG

Production (application-prod.yml):

spring:
  jpa:
    hibernate:
      ddl-auto: validate
logging:
  level:
    root: WARN
    com.LIVTech.hotel_management_system: INFO

🐳 Docker Support

Dockerfile:

FROM openjdk:21-jdk-slim

WORKDIR /app

COPY target/*.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]

Docker Compose:

version: '3.8'
services:
  hotel-app:
    build: .
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=prod
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
      - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
    depends_on:
      - db
  
  db:
    image: mysql:8.0
    environment:
      MYSQL_DATABASE: hotel_management
      MYSQL_USER: admin
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: rootpassword
    ports:
      - "3306:3306"

πŸ§ͺ Testing

Run tests:

mvn test

Run with coverage:

mvn clean test jacoco:report

πŸ“¦ Dependencies

Key dependencies in pom.xml:

<dependencies>
    <!-- Spring Boot Starters -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    <!-- Jakarta EE -->
    <dependency>
        <groupId>jakarta.persistence</groupId>
        <artifactId>jakarta.persistence-api</artifactId>
    </dependency>
    
    <!-- Lombok -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    
    <!-- AWS S3 -->
    <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>s3</artifactId>
    </dependency>
</dependencies>

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Controller    │────│    Service       │────│   Repository    β”‚
β”‚     Layer       β”‚    β”‚     Layer        β”‚    β”‚     Layer       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                        β”‚                        β”‚
         β”‚                        β”‚                        β”‚
         β–Ό                        β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   REST API      β”‚    β”‚  Business Logic  β”‚    β”‚    Database     β”‚
β”‚   Endpoints     β”‚    β”‚  Transactions    β”‚    β”‚   Operations    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β”‚
                                β–Ό
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚     AWS S3       β”‚
                      β”‚  Image Storage   β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Deployment

GitHub Actions CI/CD

Create .github/workflows/ci.yml:

name: CI/CD Pipeline

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 21
      uses: actions/setup-java@v3
      with:
        java-version: '21'
        distribution: 'temurin'
    - name: Cache Maven packages
      uses: actions/cache@v3
      with:
        path: ~/.m2
        key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
    - name: Run tests
      run: mvn clean test

🀝 Contributing

We welcome contributions! Please follow these steps:

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

Code Style Guidelines

  • Follow Java naming conventions
  • Use Lombok annotations to reduce boilerplate
  • Write meaningful commit messages
  • Add unit tests for new features
  • Update documentation as needed

πŸ“ License

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

πŸ› Issues & Support

πŸ“Š Project Status

Build Status License Java Version Spring Boot

πŸ‘¨β€πŸ’» Author

LIVTech Solutions

🌟 Acknowledgments

  • Spring Boot team for the excellent framework
  • AWS for reliable cloud infrastructure
  • Lombok project for reducing boilerplate code
  • Jakarta EE for enterprise standards
  • Open source community for inspiration

⭐ If this project helped you, please consider giving it a star!

Built with ❀️ using Spring Boot, Jakarta EE, and modern Java technologies

About

🏨 Hotel Management System A full-featured, modular Hotel Management System built using modern Java technologies. This application provides robust capabilities for managing hotel operations, including room bookings, customer check-ins/check-outs, billing, employee management, and more.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors