Skip to content

Latest commit

 

History

History
156 lines (125 loc) · 3.76 KB

README.md

File metadata and controls

156 lines (125 loc) · 3.76 KB

Supermarket Billing App

This is a simple Supermarket Billing App implemented using Go (server-side) and MongoDB (database). The application allows you to perform CRUD (Create, Read, Update, Delete) operations on bills, which represent customer purchases at a supermarket.

Table of Contents

Pre-requisites

Before running the application, ensure that you have the following installed:

Getting Started

  1. Clone the repository:

    git clone https://github.com/0xt3j4s/supermarket-billing-app.git
  2. Navigate to the project directory:

    cd supermarket-billing-app
  3. Initialize Go Modules:

    go mod init
  4. Download the project dependencies:

    go mod tidy
  5. Set up the MongoDB connection by updating the databaseURL variable in the main.go file with your MongoDB connection string.

  6. Start the application:

    go run main.go
  7. The application will start running on http://localhost:8080.

API Endpoints

The following are the API endpoints are available:

  • POST /bills: Create a new bill.

  • GET /bills/:id: Retrieve a specific bill by ID.

  • GET /bills: Retrieve all bills.

  • PUT /bills/:id: Update a specific bill by ID.

  • DELETE /bills/:id: Delete a specific bill by ID.

Usage

Initial bill entries in the database: Initial Bill Entries

Create a new bill

Send a POST request to /bills:

curl -X POST -H "Content-Type: application/json" -d '{
  "id": 3,
  "user_name": "William",
  "items": [
    {
      "id": 1,
      "name": "Item 1",
      "quantity": 2,
      "price": 10,
      "added_at": "2023-05-16"
    },
    {
      "id": 2,
      "name": "Item 2",
      "quantity": 3,
      "price": 15,
      "added_at": "2023-05-16"
    }
  ],
  "created_at": "2023-05-16"
}' http://localhost:8080/bills

New Bill Entry

Retrieve a specific bill by ID

Send a GET request to /bills/:id:

curl -X GET http://localhost:8080/bills/3

Retrieve Bill

Retrieve all bills

Send a GET request to /bills:

curl -X GET http://localhost:8080/bills

Retrieve All Bills

Update a specific bill by ID

Send a PUT request to /bills/:id:

curl -X PUT -H "Content-Type: application/json" -d '{
  "id": 1,
  "user_name": "William Smith",
  "items": [
    {
      "id": 1,
      "name": "Updated Item 1",
      "quantity": 5,
      "price": 20,
      "added_at": "2023-05-16"
    },
    {
      "id": 2,
      "name": "Updated Item 2",
      "quantity": 2,
      "price": 10,
      "added_at": "2023-05-16"
    }
  ],
  "created_at": "2023-05-16"
}' http://localhost:8080/bills/3

Update Bill

Delete a specific bill by ID

Send a DELETE request to /bills/:id:

curl -X DELETE http://localhost:8080/bills/3

Delete Bill

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please create an issue or submit a pull request.

License

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