Skip to content

An architecture design for a management system using Golang as Backend development

License

Notifications You must be signed in to change notification settings

Nhathuy1305/AdminGo

Repository files navigation

Restaurant Management Logo

RESTAURANT MANAGEMENT BACKEND

This backend service is designed for a restaurant management system built with Golang. It provides APIs to manage various aspects of the restaurant, including menu items, orders, invoices, table management, and user authentication.

Table of Contents

Features

  • JWT-based authentication and authorization
  • RESTful API with Gin framework
  • Input validation using go-playground/validator
  • MongoDB for database operations

Installation

Prerequisites

Before you begin, ensure you have the following installed on your machine:

Clone the Repository

git clone https://github.com/Nhathuy1305/AdminGo.git
cd AdminGo

Install Dependencies

This project uses Go modules to manage dependencies. You can install the required dependencies using the following command:

go mod tidy

Environment Variables

Change .env-example to .env file in the root directory and configure the following environment variables:

PORT=8000 #Optional
MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
MONGO_HOST=
MONGO_PORT=

Run the Application

Option 1: Run by Docker Compose

Run the Docker Compose to start using the application:

docker-compose up -d

Option 2: Run separately by Docker and Go command

Create the Docker Images with these commands:

docker run -d --name mongo-demo \
-e MONGO_INITDB_ROOT_USERNAME=your-username \
-e MONGO_INITDB_ROOT_PASSWORD=your-password \
-p 27018:27017 \
mongo:6.0
  • Remember to change mongo-demo, your-username and your-password with your image, root username and password of your database.

Run the application by the following command:

go run main.go

The backend service will start on http://localhost:8000.

Usage

Building the Application

To build the application, run the following command:

go build -o admingo

Running the Built Application

./admingo

Database Management

  1. Access the MongoDB Image using this command:
docker exec -it mongo-demo /bin/bash
  1. Access the MongoDB shell:
mongosh -u your-username -p your-password
  1. List all databases:
show dbs
  1. Access a specific database:
use your_database_name
  1. List all collections (tables) in the database:
show collections
  1. Show data in a specific collection:
db.your_collection_name.find().pretty()

For example:

docker exec -it mongo-demo /bin/bash

mongosh -u mongotest -p 123456

show dbs

use restaurant

show collections

db.user.find().pretty()

API Endpoints

Users

  • GET /users - Retrieve a list of users.
  • GET /users/:user_id - Retrieve a specific user by ID.
  • POST /users/signup - Register a new user.
  • POST /users/login - Authenticate a user and obtain a JWT token.

Foods

  • GET /foods - Retrieve a list of food items.
  • GET /foods/:food_id - Retrieve a specific food item by ID.
  • POST /foods - Add a new food item.
  • PATCH /foods/:food_id - Update an existing food item.

Menus

  • GET /menus - Retrieve a list of menus.
  • GET /menus/:menu_id - Retrieve a specific menu by ID.
  • POST /menus - Add a new menu.
  • PATCH /menus/:menu_id - Update an existing menu.

Tables

  • GET /tables - Retrieve a list of tables.
  • GET /tables/:table_id - Retrieve a specific table by ID.
  • POST /tables - Add a new table.
  • PATCH /tables/:table_id - Update an existing table.

Orders

  • GET /orders - Retrieve a list of orders.
  • GET /orders/:order_id - Retrieve a specific order by ID.
  • POST /orders - Place a new order.
  • PATCH /orders/:order_id - Update an existing order.

Order Items

  • GET /orderItems - Retrieve a list of order items.
  • GET /orderItems/:orderItem_id - Retrieve a specific order item by ID.
  • GET /orderItems-order/:order_id - Retrieve order items by order ID.
  • POST /orderItems - Add a new order item.
  • PATCH /orderItems/:orderItem_id - Update an existing order item.

Invoices

  • GET /invoices - Retrieve a list of invoices.
  • GET /invoices/:invoice_id - Retrieve a specific invoice by ID.
  • POST /invoices - Create a new invoice.
  • PATCH /invoices/:invoice_id - Update an existing invoice.

Dependencies

This project uses the following Go packages:

Contact

License

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

About

An architecture design for a management system using Golang as Backend development

Resources

License

Stars

Watchers

Forks