Skip to content

A backend API for hotel reservations using JWT for user authentication, MongoDB for data storage, and the Fiber framework.

Notifications You must be signed in to change notification settings

unsuman/hotel-reservation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏨 Hotel Reservation Backend API

This is a backend API for a hotel reservation system built in Go. The API allows users to manage hotels, rooms, and bookings. It also includes user authentication and authorization.

Packages Used

  • Fiber: Web framework for building REST APIs.
  • JWT: User authentication and authorization using JWT.
  • GoDotEnv: Loads environment variables from a .env file.
  • MongoDB Go Driver: MongoDB driver for Go.

Architecture Diagram

Architecture Diagram

Endpoint Flow

Endpoint Flow Diagram

Endpoints

Authentication

  • POST /api/auth: Authenticates a user and returns a JWT token.
    • Handler: HandleAuthentication
    • Implementation: Validates user credentials and generates a JWT token using CreateTokenFromUser

User Management

  • POST /api/v1/user: Creates a new user.

    • Handler: HandlePostUser
    • Implementation: Parses user data, validates it, and stores it in the database.
  • GET /api/v1/users: Retrieves all users.

    • Handler: HandleGetUsers
    • Implementation: Fetches all users from the database.
  • GET /api/v1/user/:id: Retrieves a user by ID.

    • Handler: HandleGetUser
    • Implementation: Fetches a user by ID from the database.
  • PUT /api/v1/user/:id: Updates a user by ID.

    • Handler: HandleUpdateUser
    • Implementation: Updates user data in the database.
  • DELETE /api/v1/user/:id: Deletes a user by ID.

    • Handler: HandleDeleteUser
    • Implementation: Deletes a user from the database.

Hotel Management

  • GET /api/v1/hotels: Retrieves all hotels.

    • Handler: GetHotels
    • Implementation: Fetches all hotels from the database.
  • GET /api/v1/hotel/:id: Retrieves a hotel by ID.

    • Handler: GetHotel
    • Implementation: Fetches a hotel by ID from the database.
  • GET /api/v1/hotel/:id/rooms: Retrieves all rooms for a hotel.

    • Handler: GetRooms
    • Implementation: Fetches all rooms for a specific hotel from the database.

Room Management

  • POST /api/v1/room/:id/book: Books a room.
    • Handler: HandleBookRoom
    • Implementation: Validates booking data, checks room availability, and stores the booking in the database.

Booking Management

  • GET /api/v1/booking/:id: Retrieves a booking by ID.

    • Handler: HandleGetBooking
    • Implementation: Fetches a booking by ID from the database.
  • GET /api/v1/bookings: Retrieves all bookings.

    • Handler: HandleGetBookings
    • Implementation: Fetches all bookings from the database.
  • GET /api/v1/booking/:id/cancel: Cancels a booking by ID.

    • Handler: HandleCancelBooking
    • Implementation: Cancels a booking by ID in the database.

Admin Endpoints

  • GET /api/v1/admin/bookings: Retrieves all bookings (admin only).
    • Handler: HandleGetBookings
    • Implementation: Fetches all bookings from the database.

Getting Started

  1. Clone the repository:

    git clone https://github.com/yourusername/hotel-reservation.git
    cd hotel-reservation
  2. Install dependencies:

    go mod tidy
  3. Set up environment variables: Create a .env file in the root directory and add the following variables:

    JWT_SECRET=your_jwt_secret
    DB_URI=your_mongodb_uri
    DB_NAME=your_database_name
    
  4. Use Make:

  • Build the application:

    make build
  • Run the application:

    make run
  • Seed the database:

    make seed
  • Run tests:

    make test

About

A backend API for hotel reservations using JWT for user authentication, MongoDB for data storage, and the Fiber framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •