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
-
Clone the repository:
git clone https://github.com/0xt3j4s/supermarket-billing-app.git
-
Navigate to the project directory:
cd supermarket-billing-app
-
Initialize Go Modules:
go mod init
-
Download the project dependencies:
go mod tidy
-
Set up the MongoDB connection by updating the databaseURL
variable in the main.go
file with your MongoDB connection string.
-
Start the application:
go run main.go
-
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:

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

Retrieve a specific bill by ID
Send a GET request to /bills/:id
:
curl -X GET http://localhost:8080/bills/3

Retrieve all bills
Send a GET request to /bills
:
curl -X GET http://localhost:8080/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

Delete a specific bill by ID
Send a DELETE request to /bills/:id
:
curl -X DELETE http://localhost:8080/bills/3

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.