Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bistro Restaurant Chain API

A complete restaurant management backend built with Go, Gin, MongoDB, and JWT authentication.

Features

  • 🔐 JWT Authentication & Authorization
  • 👥 User Management (Admin & Regular Users)
  • 🍔 Food Items Management
  • 📋 Menu Management
  • 🪑 Table Management
  • 📝 Order Management
  • 🧾 Invoice Management
  • 🔒 Role-based Access Control

Tech Stack

  • Language: Go
  • Web Framework: Gin
  • Database: MongoDB
  • Authentication: JWT
  • Password Hashing: bcrypt
  • Environment Variables: godotenv

Prerequisites

  • Go 1.20 or higher
  • MongoDB (local or Atlas)

Installation

  1. Clone the repository
  2. Install dependencies:
go mod tidy
  1. Create a .env file in the root directory:
PORT=8080
MONGODB_URI=mongodb://localhost:27017
DATABASE_NAME=restaurant
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production

Running the Application

go run main.go

The server will start on http://localhost:8080

API Endpoints

Authentication

  • POST /auth/signup - Register a new user
  • POST /auth/login - Login user
  • GET /auth/user - Get current user (requires authentication)

Swagger UI

  • GET /swagger/index.html - Open the interactive API documentation (Swagger UI).

After you run the server, open the URL below in your browser to explore and try your API endpoints:

http://localhost:8080/swagger/index.html

Notes:

  • The Swagger docs are generated by swag and written to the docs/ directory.
  • Do NOT edit docs/docs.go, docs/swagger.json, or docs/swagger.yaml directly — they are generated and will be overwritten.

To regenerate the Swagger documentation after changing annotations or models, run:

swag init

If you want to override runtime metadata (title, host, schemes) without editing generated files, set docs.SwaggerInfo in main.go after importing the generated docs package:

import (
    _ "restroBackend/docs"
    docs "restroBackend/docs"
)

func main() {
    docs.SwaggerInfo.Title = "Restaurant Management API"
    docs.SwaggerInfo.Version = "1.0"
    docs.SwaggerInfo.Host = "localhost:8080"
    docs.SwaggerInfo.BasePath = "/"
    docs.SwaggerInfo.Schemes = []string{"http", "https"}

    // ...rest of your setup
}

Foods

  • GET /foods - Get all foods
  • GET /foods/:id - Get food by ID
  • POST /foods - Create food (Admin only)
  • PUT /foods/:id - Update food (Admin only)
  • DELETE /foods/:id - Delete food (Admin only)

Menus

  • GET /menus - Get all menus
  • GET /menus/:id - Get menu by ID
  • POST /menus - Create menu (Admin only)
  • PUT /menus/:id - Update menu (Admin only)
  • DELETE /menus/:id - Delete menu (Admin only)

Tables

  • GET /tables - Get all tables
  • GET /tables/:id - Get table by ID
  • POST /tables - Create table (Admin only)
  • PUT /tables/:id - Update table (Admin only)
  • DELETE /tables/:id - Delete table (Admin only)

Orders

  • GET /orders - Get all orders (authenticated)
  • GET /orders/:id - Get order by ID (authenticated)
  • POST /orders - Create order (authenticated)
  • PUT /orders/:id - Update order (authenticated)

Invoices

  • GET /invoices - Get all invoices (authenticated)
  • GET /invoices/:id - Get invoice by ID (authenticated)
  • POST /invoices - Create invoice (authenticated)
  • PUT /invoices/:id - Update invoice (Admin only)

Authentication

Include the JWT token in the request header:

token: your_jwt_token_here

User Types

  • ADMIN - Full access to all administrative resources, maps, and menus
  • STAFF - Access to floor maps, active kitchen ticket board, and billing/invoice verification
  • USER - Guest customer access (can create orders, view menus, and manage reservations)