Skip to content

Den1s-coder/Hotel_Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏨 Hotel Management System API

A comprehensive hotel management system with REST API for room booking, user management, and authentication.

πŸ“‹ Table of Contents

🎯 Project Description

Hotel Management System is a web API for hotel management that provides:

  • User registration and authentication
  • Room management (add, edit, delete)
  • Room booking with availability checking
  • Image upload for rooms
  • Search available rooms by dates and parameters
  • Price management by room type

πŸ—οΈ Architecture

The project is built following Clean Architecture principles with separation into three main layers:

  • API Layer (HotelHTTP.API) - controllers, services, requests
  • Domain Layer (HotelHTTP.Domain) - entities, interfaces
  • Infrastructure Layer (HotelHttp.Infrastracture) - repositories, database

πŸ› οΈ Technologies

  • .NET 8.0 - main platform
  • ASP.NET Core Web API - web framework
  • Entity Framework Core - ORM
  • PostgreSQL - database
  • JWT Bearer Authentication - authentication
  • Swagger/OpenAPI - API documentation
  • CORS - cross-domain request support

πŸš€ Installation

Prerequisites

  • .NET 8.0 SDK
  • PostgreSQL
  • Git

Installation Steps

  1. Clone the repository:
git clone <repository-url>
cd Hotel_Server
  1. Install dependencies:
dotnet restore
  1. Configure database:

    • Create PostgreSQL database
    • Update connection string in appsettings.json
  2. Run migrations:

dotnet ef database update --project HotelHttp.Infrastracture --startup-project HotelHTTP.API
  1. Run the project:
dotnet run --project HotelHTTP.API

βš™οΈ Configuration

appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnectionString": "Host=localhost;Database=HotelDB;Username=your_username;Password=your_password"
  },
  "Jwt": {
    "Key": "your-super-secret-key-here",
    "Issuer": "HotelAPI",
    "Audience": "HotelClients"
  }
}

CORS

The API is configured to work with frontend on http://localhost:5173.

πŸ“‘ API Endpoints

Authentication (/api/auth)

Method Endpoint Description Authorization
POST /register User registration ❌
POST /login User login ❌
POST /logout User logout βœ…

Rooms (/api/rooms)

Method Endpoint Description Authorization
GET / Get all rooms ❌
GET /{id} Get room by ID ❌
POST / Create room βœ…
PUT /{id} Update room βœ…
DELETE /{id} Delete room βœ…
GET /available Search available rooms ❌
POST /update-prices Update prices by type βœ…

Bookings (/api/booking)

Method Endpoint Description Authorization
GET / Get all bookings βœ…
GET /user Get current user bookings βœ…
POST / Create booking βœ…
DELETE /{id} Cancel booking βœ…
GET /bookings-per-day Bookings statistics by day βœ…

Users (/api/user)

Method Endpoint Description Authorization
GET /me Get current user info βœ…

πŸ“ Project Structure

Hotel_Server/
β”œβ”€β”€ HotelHTTP.API/                 # API Layer
β”‚   β”œβ”€β”€ Controllers/               # API Controllers
β”‚   β”‚   β”œβ”€β”€ AuthController.cs
β”‚   β”‚   β”œβ”€β”€ BookingController.cs
β”‚   β”‚   β”œβ”€β”€ RoomsController.cs
β”‚   β”‚   └── UserController.cs
β”‚   β”œβ”€β”€ Requests/                  # Request Models
β”‚   β”‚   β”œβ”€β”€ BookingRequest.cs
β”‚   β”‚   β”œβ”€β”€ LoginRequest.cs
β”‚   β”‚   β”œβ”€β”€ RegisterRequest.cs
β”‚   β”‚   β”œβ”€β”€ RoomRequest.cs
β”‚   β”‚   └── UpdatePriceRequest.cs
β”‚   β”œβ”€β”€ Service/                   # Business Logic
β”‚   β”‚   β”œβ”€β”€ AuthService.cs
β”‚   β”‚   β”œβ”€β”€ BookingService.cs
β”‚   β”‚   β”œβ”€β”€ RoomService.cs
β”‚   β”‚   └── TokenService.cs
β”‚   β”œβ”€β”€ wwwroot/images/            # Room Images
β”‚   └── Program.cs
β”œβ”€β”€ HotelHTTP.Domain/              # Domain Layer
β”‚   β”œβ”€β”€ Entities/                  # Entities
β”‚   β”‚   β”œβ”€β”€ User.cs
β”‚   β”‚   β”œβ”€β”€ Room.cs
β”‚   β”‚   └── Booking.cs
β”‚   └── Interfaces/                # Interfaces
β”‚       β”œβ”€β”€ Auth/
β”‚       └── Repo/
└── HotelHttp.Infrastracture/      # Infrastructure Layer
    β”œβ”€β”€ Data/
    β”‚   └── HotelDBContext.cs
    β”œβ”€β”€ Repositories/              # Repositories
    β”‚   β”œβ”€β”€ BookingRepository.cs
    β”‚   β”œβ”€β”€ RoomRepository.cs
    β”‚   └── UserRepository.cs
    β”œβ”€β”€ Migrations/                # Database Migrations
    └── PasswordHasher.cs

πŸ’» Usage

User Registration

POST /api/auth/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123",
  "role": "User"
}

User Login

POST /api/auth/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "password123"
}

Search Available Rooms

GET /api/rooms/available?checkInDate=2024-01-15&checkOutDate=2024-01-20&maxPrice=1000&capacity=2

Create Booking

POST /api/booking
Authorization: Bearer <token>
Content-Type: application/json

{
  "roomId": 1,
  "checkInDate": "2024-01-15T14:00:00Z",
  "checkOutDate": "2024-01-20T12:00:00Z"
}

πŸ” Security

  • JWT tokens stored in HTTP-only cookies
  • Passwords hashed using BCrypt
  • CORS configured for secure frontend communication
  • Input validation for all data

πŸ“ License

This project is distributed under the MIT License. See the LICENSE file for details.

About

Hotel server application stack: C#, .NET WebApi, Postgres, EF, JWT. Client repository: https://github.com/Den1s-coder/Hotel_Client

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages