├── frontend ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt └── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── components │ ├── orders.components.js │ └── single-order.component.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js └── server ├── .env ├── configs ├── env.go └── setup.go ├── controllers └── order_controller.go ├── go.mod ├── go.sum ├── main.go ├── models └── order_model.go ├── responses └── order_response.go └── routes └── order_route.go /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.4", 7 | "@testing-library/react": "^13.2.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "autoprefixer": "^10.4.7", 10 | "axios": "^0.27.2", 11 | "bootstrap": "^5.1.3", 12 | "react": "^18.1.0", 13 | "react-bootstrap": "^2.4.0", 14 | "react-dom": "^18.1.0", 15 | "react-scripts": "5.0.1", 16 | "web-vitals": "^2.1.4" 17 | }, 18 | "scripts": { 19 | "start": "react-scripts start", 20 | "build": "react-scripts build", 21 | "test": "react-scripts test", 22 | "eject": "react-scripts eject" 23 | }, 24 | "eslintConfig": { 25 | "extends": [ 26 | "react-app", 27 | "react-app/jest" 28 | ] 29 | }, 30 | "browserslist": { 31 | "production": [ 32 | ">0.2%", 33 | "not dead", 34 | "not op_mini all" 35 | ], 36 | "development": [ 37 | "last 1 chrome version", 38 | "last 1 firefox version", 39 | "last 1 safari version" 40 | ] 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Go-React-Order/3aaafefd27d2197aab4d52e27b37395e6ed431fd/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Go-React-Order/3aaafefd27d2197aab4d52e27b37395e6ed431fd/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Go-React-Order/3aaafefd27d2197aab4d52e27b37395e6ed431fd/frontend/public/logo512.png -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import 'bootstrap/dist/css/bootstrap.css'; 4 | 5 | import Orders from './components/orders.components'; 6 | 7 | function App() { 8 | return ( 9 |
10 | 11 |
12 | ); 13 | } 14 | 15 | export default App; 16 | -------------------------------------------------------------------------------- /frontend/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /frontend/src/components/orders.components.js: -------------------------------------------------------------------------------- 1 | import React, {useState, useEffect} from 'react'; 2 | import axios from 'axios'; 3 | import {Button, Form, Container, Modal} from 'react-bootstrap'; 4 | import Order from './single-order.component'; 5 | 6 | const Orders = () => { 7 | 8 | const [orders, setOrders] = useState([]); 9 | const [refreshData, setRefreshData] = useState(false); 10 | 11 | const [changeOrder, setChangeOrder] = useState({"change": false, "id": 0}); 12 | const [changeWaiter, setChangeWaiter] = useState({"change": false, "id": 0}); 13 | const [newWaiterName, setNewWaiterName] = useState("") 14 | 15 | const [addNewOrder, setAddNewOrder] = useState(false); 16 | const [newOrder, setNewOrder] = useState({"dish": "", "server": "", "table": 0, "price": 0}); 17 | 18 | // gets run at initial loadup 19 | useEffect(() => { 20 | getAllOrders(); 21 | }, []) 22 | 23 | // refreshes the page 24 | if (refreshData) { 25 | setRefreshData(false); 26 | getAllOrders(); 27 | } 28 | 29 | return ( 30 |
31 | 32 | {/* add new order button */} 33 | 34 | 35 | 36 | 37 | {/* list all current orders */} 38 | 39 | {orders != null && orders.map((order, i) => ( 40 | 41 | ))} 42 | 43 | 44 | {/* popup for adding a new order */} 45 | setAddNewOrder(false)} centered> 46 | 47 | Add order 48 | 49 | 50 | 51 | 52 | dish 53 | {newOrder.dish = event.target.value}} /> 54 | server 55 | {newOrder.server = event.target.value}} /> 56 | table 57 | {newOrder.table = event.target.value}} /> 58 | price 59 | {newOrder.price = event.target.value}} /> 60 | 61 | 62 | 63 | 64 | 65 | 66 | {/* popup for changing a waiter */} 67 | setChangeWaiter({"change": false, "id": 0})} centered> 68 | 69 | Change Waiter 70 | 71 | 72 | 73 | 74 | new waiter 75 | {setNewWaiterName(event.target.value)}}/> 76 | 77 | 78 | 79 | 80 | 81 | 82 | {/* popup for changing an order */} 83 | setChangeOrder({"change": false, "id": 0})} centered> 84 | 85 | Change Order 86 | 87 | 88 | 89 | 90 | dish 91 | {newOrder.dish = event.target.value}}/> 92 | waiter 93 | {newOrder.server = event.target.value}}/> 94 | table 95 | {newOrder.table = event.target.value}}/> 96 | price 97 | {newOrder.price = parseFloat(event.target.value)}}/> 98 | 99 | 100 | 101 | 102 | 103 |
104 | ) 105 | 106 | // changes the waiter 107 | function changeWaiterForOrder() { 108 | changeWaiter.change = false; 109 | let url = "http://localhost:5000/waiter/update/" + changeWaiter.id; 110 | axios.put(url, { 111 | "server": newWaiterName 112 | }).then(response => { 113 | console.log(response.status) 114 | if (response.status === 200) { 115 | setRefreshData(true); 116 | } 117 | }) 118 | } 119 | 120 | // changes the order 121 | function changeSingleOrder() { 122 | changeOrder.change = false; 123 | let url = "http://localhost:5000/order/update/" + changeOrder.id; 124 | axios.put(url, newOrder) 125 | .then(response => { 126 | if (response.status === 200) { 127 | setRefreshData(true); 128 | } 129 | }) 130 | } 131 | 132 | // creates a new order 133 | function addSingleOrder() { 134 | setAddNewOrder(false); 135 | var url = "http://localhost:5000/order/create"; 136 | axios.post(url, { 137 | "server": newOrder.server, 138 | "dish": newOrder.dish, 139 | "price": parseFloat(newOrder.price), 140 | "table": newOrder.table 141 | }).then(response => { 142 | if (response.status === 200) { 143 | setRefreshData(true); 144 | } 145 | }) 146 | } 147 | 148 | // get all orders 149 | function getAllOrders() { 150 | let url = "http://localhost:5000/orders"; 151 | axios.get(url, { 152 | responseType: 'json' 153 | }).then(response => { 154 | if (response.status === 200) { 155 | setOrders(response.data) 156 | } 157 | }) 158 | } 159 | 160 | // delete a single order 161 | function deleteSingleOrder(id) { 162 | var url = "http://localhost:5000/order/delete/" + id; 163 | axios.delete(url, {}).then(response => { 164 | if (response.status === 200) { 165 | setRefreshData(true); 166 | } 167 | }) 168 | } 169 | } 170 | 171 | export default Orders; -------------------------------------------------------------------------------- /frontend/src/components/single-order.component.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import 'bootstrap/dist/css/bootstrap.css'; 3 | 4 | import {Button, Card, Row, Col} from 'react-bootstrap'; 5 | 6 | const Order = ({orderData, setChangeWaiter, deleteSingleOrder, setChangeOrder}) => { 7 | 8 | return ( 9 | 10 | 11 | Dish:{ orderData !== undefined && orderData.dish } 12 | Server:{ orderData !== undefined && orderData.server } 13 | Table:{ orderData !== undefined && orderData.table } 14 | Price:{ orderData !== undefined && orderData.price } 15 | 16 | 17 | 18 | 19 | 20 | ) 21 | 22 | function changeWaiter() { 23 | setChangeWaiter( 24 | { 25 | "change": true, 26 | "id": orderData.ID 27 | } 28 | ) 29 | } 30 | 31 | function changeOrder() { 32 | setChangeOrder( 33 | { 34 | "change": true, 35 | "id": orderData.ID 36 | } 37 | ) 38 | } 39 | } 40 | 41 | export default Order; -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /frontend/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /frontend/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /server/.env: -------------------------------------------------------------------------------- 1 | PORT=5000 2 | MONGODB_URL=mongodb://localhost:27017/Standalone -------------------------------------------------------------------------------- /server/configs/env.go: -------------------------------------------------------------------------------- 1 | package configs 2 | 3 | import ( 4 | "log" 5 | "os" 6 | 7 | "github.com/joho/godotenv" 8 | ) 9 | 10 | func EnvMongoURI() string { 11 | err := godotenv.Load() 12 | if err != nil { 13 | log.Fatal("Error loading .env file") 14 | } 15 | 16 | return os.Getenv("MONGODB_URL") 17 | } 18 | -------------------------------------------------------------------------------- /server/configs/setup.go: -------------------------------------------------------------------------------- 1 | package configs 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "time" 8 | 9 | "go.mongodb.org/mongo-driver/mongo" 10 | "go.mongodb.org/mongo-driver/mongo/options" 11 | ) 12 | 13 | func ConnectDB() *mongo.Client { 14 | client, err := mongo.NewClient(options.Client().ApplyURI(EnvMongoURI())) 15 | if err != nil { 16 | log.Fatal(err) 17 | } 18 | 19 | ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) 20 | err = client.Connect(ctx) 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | 25 | // ping the database 26 | err = client.Ping(ctx, nil) 27 | if err != nil { 28 | log.Fatal(err) 29 | } 30 | fmt.Println("Connected to MongoDB") 31 | return client 32 | } 33 | 34 | // Client Instance 35 | var DB *mongo.Client = ConnectDB() 36 | 37 | // getting database collections 38 | func GetCollection(client *mongo.Client, collectionName string) *mongo.Collection { 39 | collection := client.Database("restaurant").Collection(collectionName) 40 | return collection 41 | } 42 | -------------------------------------------------------------------------------- /server/controllers/order_controller.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "server/configs" 7 | "server/models" 8 | "server/responses" 9 | "time" 10 | 11 | "github.com/gin-gonic/gin" 12 | "github.com/go-playground/validator/v10" 13 | "go.mongodb.org/mongo-driver/bson" 14 | "go.mongodb.org/mongo-driver/bson/primitive" 15 | "go.mongodb.org/mongo-driver/mongo" 16 | ) 17 | 18 | var orderCollection *mongo.Collection = configs.GetCollection(configs.DB, "orders") 19 | var validate = validator.New() 20 | 21 | func AddOrder() gin.HandlerFunc { 22 | return func(c *gin.Context) { 23 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 24 | var order models.Order 25 | defer cancel() 26 | 27 | // validate the request body 28 | if err := c.BindJSON(&order); err != nil { 29 | c.JSON(http.StatusBadRequest, responses.OrderResponse{ 30 | Status: http.StatusBadRequest, 31 | Message: "error", 32 | Data: map[string]interface{}{ 33 | "data": err.Error(), 34 | }, 35 | }) 36 | return 37 | } 38 | 39 | // use the validate library to validate fields 40 | if validationErr := validate.Struct(&order); validationErr != nil { 41 | c.JSON(http.StatusBadRequest, responses.OrderResponse{ 42 | Status: http.StatusBadRequest, 43 | Message: "error", 44 | Data: map[string]interface{}{ 45 | "data": validationErr.Error(), 46 | }, 47 | }) 48 | return 49 | } 50 | 51 | newOrder := models.Order{ 52 | ID: primitive.NewObjectID(), 53 | Dish: order.Dish, 54 | Price: order.Price, 55 | Server: order.Server, 56 | Table: order.Table, 57 | } 58 | 59 | result, err := orderCollection.InsertOne(ctx, newOrder) 60 | if err != nil { 61 | c.JSON(http.StatusBadRequest, responses.OrderResponse{ 62 | Status: http.StatusBadRequest, 63 | Message: "error", 64 | Data: map[string]interface{}{ 65 | "data": err.Error(), 66 | }, 67 | }) 68 | return 69 | } 70 | 71 | c.JSON(http.StatusOK, responses.OrderResponse{ 72 | Status: http.StatusOK, 73 | Message: "success", 74 | Data: map[string]interface{}{ 75 | "data": result, 76 | }, 77 | }) 78 | } 79 | } 80 | 81 | func GetAllOrders() gin.HandlerFunc { 82 | return func(c *gin.Context) { 83 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 84 | var orders []models.Order 85 | defer cancel() 86 | 87 | results, err := orderCollection.Find(ctx, bson.M{}) 88 | if err != nil { 89 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 90 | Status: http.StatusInternalServerError, 91 | Message: "error", 92 | Data: map[string]interface{}{ 93 | "data": err.Error(), 94 | }, 95 | }) 96 | return 97 | } 98 | 99 | // reading from the db in an optimal way 100 | defer results.Close(ctx) 101 | for results.Next(ctx) { 102 | var singleOrder models.Order 103 | if err := results.Decode(&singleOrder); err != nil { 104 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 105 | Status: http.StatusInternalServerError, 106 | Message: "error", 107 | Data: map[string]interface{}{ 108 | "data": err.Error(), 109 | }, 110 | }) 111 | } 112 | orders = append(orders, singleOrder) 113 | } 114 | 115 | c.JSON(http.StatusOK, orders) 116 | } 117 | } 118 | 119 | func GetOrderById() gin.HandlerFunc { 120 | return func(c *gin.Context) { 121 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 122 | orderId := c.Param("orderId") 123 | var order models.Order 124 | defer cancel() 125 | 126 | objId, _ := primitive.ObjectIDFromHex(orderId) 127 | 128 | err := orderCollection.FindOne(ctx, bson.M{"_id": objId}).Decode(&order) 129 | if err != nil { 130 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 131 | Status: http.StatusInternalServerError, 132 | Message: "error", 133 | Data: map[string]interface{}{ 134 | "data": err.Error(), 135 | }, 136 | }) 137 | return 138 | } 139 | 140 | c.JSON(http.StatusOK, responses.OrderResponse{ 141 | Status: http.StatusOK, 142 | Message: "success", 143 | Data: map[string]interface{}{ 144 | "data": order, 145 | }, 146 | }) 147 | } 148 | } 149 | 150 | func GetOrderByWaiter() gin.HandlerFunc { 151 | return func(c *gin.Context) { 152 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 153 | waiter := c.Param("waiter") 154 | var orders []models.Order 155 | defer cancel() 156 | 157 | result, err := orderCollection.Find(ctx, bson.M{"server": waiter}) 158 | if err != nil { 159 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 160 | Status: http.StatusInternalServerError, 161 | Message: "error", 162 | Data: map[string]interface{}{ 163 | "data": err.Error(), 164 | }, 165 | }) 166 | return 167 | } 168 | 169 | defer result.Close(ctx) 170 | for result.Next(ctx) { 171 | var singleOrder models.Order 172 | if err := result.Decode(&singleOrder); err != nil { 173 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 174 | Status: http.StatusInternalServerError, 175 | Message: "error", 176 | Data: map[string]interface{}{ 177 | "data": err.Error(), 178 | }, 179 | }) 180 | } 181 | orders = append(orders, singleOrder) 182 | } 183 | 184 | c.JSON(http.StatusOK, responses.OrderResponse{ 185 | Status: http.StatusOK, 186 | Message: "success", 187 | Data: map[string]interface{}{ 188 | "data": orders, 189 | }, 190 | }) 191 | } 192 | } 193 | 194 | func UpdateWaiter() gin.HandlerFunc { 195 | return func(c *gin.Context) { 196 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 197 | orderId := c.Param("orderId") 198 | defer cancel() 199 | 200 | type Waiter struct { 201 | Server *string `json:"server"` 202 | } 203 | var waiter Waiter 204 | 205 | objId, _ := primitive.ObjectIDFromHex(orderId) 206 | 207 | // validate the request body 208 | if err := c.BindJSON(&waiter); err != nil { 209 | c.JSON(http.StatusBadRequest, responses.OrderResponse{ 210 | Status: http.StatusBadRequest, 211 | Message: "error", 212 | Data: map[string]interface{}{ 213 | "data": err.Error(), 214 | }, 215 | }) 216 | return 217 | } 218 | 219 | // user the validator library to validate fields 220 | if validationErr := validate.Struct(&waiter); validationErr != nil { 221 | c.JSON(http.StatusBadRequest, responses.OrderResponse{ 222 | Status: http.StatusBadRequest, 223 | Message: "error", 224 | Data: map[string]interface{}{ 225 | "data": validationErr.Error(), 226 | }, 227 | }) 228 | return 229 | } 230 | 231 | result, err := orderCollection.UpdateOne(ctx, 232 | bson.M{"_id": objId}, 233 | bson.D{ 234 | {"$set", bson.D{{"server", waiter.Server}}}, 235 | }, 236 | ) 237 | if err != nil { 238 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 239 | Status: http.StatusInternalServerError, 240 | Message: "error", 241 | Data: map[string]interface{}{ 242 | "data": err.Error(), 243 | }, 244 | }) 245 | return 246 | } 247 | 248 | // get updated order details 249 | var updatedOrder models.Order 250 | if result.MatchedCount == 1 { 251 | err := orderCollection.FindOne(ctx, bson.M{"_id": objId}).Decode(&updatedOrder) 252 | if err != nil { 253 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 254 | Status: http.StatusInternalServerError, 255 | Message: "error", 256 | Data: map[string]interface{}{ 257 | "data": err.Error(), 258 | }, 259 | }) 260 | return 261 | } 262 | } 263 | 264 | c.JSON(http.StatusOK, responses.OrderResponse{ 265 | Status: http.StatusOK, 266 | Message: "success", 267 | Data: map[string]interface{}{ 268 | "data": updatedOrder, 269 | }, 270 | }) 271 | } 272 | } 273 | 274 | func UpdateOrder() gin.HandlerFunc { 275 | return func(c *gin.Context) { 276 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 277 | orderId := c.Param("orderId") 278 | var order models.Order 279 | defer cancel() 280 | 281 | objId, _ := primitive.ObjectIDFromHex(orderId) 282 | 283 | // validate the request body 284 | if err := c.BindJSON(&order); err != nil { 285 | c.JSON(http.StatusBadRequest, responses.OrderResponse{ 286 | Status: http.StatusBadRequest, 287 | Message: "error", 288 | Data: map[string]interface{}{ 289 | "data": err.Error(), 290 | }, 291 | }) 292 | return 293 | } 294 | 295 | // user the validator library to validate fields 296 | if validationErr := validate.Struct(&order); validationErr != nil { 297 | c.JSON(http.StatusBadRequest, responses.OrderResponse{ 298 | Status: http.StatusBadRequest, 299 | Message: "error", 300 | Data: map[string]interface{}{ 301 | "data": validationErr.Error(), 302 | }, 303 | }) 304 | return 305 | } 306 | 307 | result, err := orderCollection.ReplaceOne(ctx, 308 | bson.M{"_id": objId}, 309 | bson.M{ 310 | "dish": order.Dish, 311 | "price": order.Price, 312 | "server": order.Server, 313 | "table": order.Table, 314 | }, 315 | ) 316 | if err != nil { 317 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 318 | Status: http.StatusInternalServerError, 319 | Message: "error", 320 | Data: map[string]interface{}{ 321 | "data": err.Error(), 322 | }, 323 | }) 324 | return 325 | } 326 | 327 | // get updated order details 328 | var updatedOrder models.Order 329 | if result.MatchedCount == 1 { 330 | err := orderCollection.FindOne(ctx, bson.M{"_id": objId}).Decode(&updatedOrder) 331 | if err != nil { 332 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 333 | Status: http.StatusInternalServerError, 334 | Message: "error", 335 | Data: map[string]interface{}{ 336 | "data": err.Error(), 337 | }, 338 | }) 339 | return 340 | } 341 | } 342 | 343 | c.JSON(http.StatusOK, responses.OrderResponse{ 344 | Status: http.StatusOK, 345 | Message: "success", 346 | Data: map[string]interface{}{ 347 | "data": updatedOrder, 348 | }, 349 | }) 350 | } 351 | } 352 | 353 | func DeleteOrder() gin.HandlerFunc { 354 | return func(c *gin.Context) { 355 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 356 | orderId := c.Param("orderId") 357 | defer cancel() 358 | 359 | objId, _ := primitive.ObjectIDFromHex(orderId) 360 | 361 | result, err := orderCollection.DeleteOne(ctx, bson.M{"_id": objId}) 362 | if err != nil { 363 | c.JSON(http.StatusInternalServerError, responses.OrderResponse{ 364 | Status: http.StatusInternalServerError, 365 | Message: "error", 366 | Data: map[string]interface{}{ 367 | "data": err.Error(), 368 | }, 369 | }) 370 | return 371 | } 372 | 373 | if result.DeletedCount < 1 { 374 | c.JSON(http.StatusNotFound, responses.OrderResponse{ 375 | Status: http.StatusNotFound, 376 | Message: "error", 377 | Data: map[string]interface{}{ 378 | "data": "Order with specified ID not found.", 379 | }, 380 | }) 381 | return 382 | } 383 | 384 | c.JSON(http.StatusOK, responses.OrderResponse{ 385 | Status: http.StatusOK, 386 | Message: "success", 387 | Data: map[string]interface{}{ 388 | "data": "Order successfully deleted.", 389 | }, 390 | }) 391 | } 392 | } 393 | -------------------------------------------------------------------------------- /server/go.mod: -------------------------------------------------------------------------------- 1 | module server 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-contrib/cors v1.3.1 // indirect 7 | github.com/gin-contrib/sse v0.1.0 // indirect 8 | github.com/gin-gonic/gin v1.7.7 // indirect 9 | github.com/go-playground/locales v0.14.0 // indirect 10 | github.com/go-playground/universal-translator v0.18.0 // indirect 11 | github.com/go-playground/validator/v10 v10.11.0 // indirect 12 | github.com/go-stack/stack v1.8.0 // indirect 13 | github.com/golang/protobuf v1.5.2 // indirect 14 | github.com/golang/snappy v0.0.1 // indirect 15 | github.com/joho/godotenv v1.4.0 // indirect 16 | github.com/json-iterator/go v1.1.12 // indirect 17 | github.com/klauspost/compress v1.13.6 // indirect 18 | github.com/leodido/go-urn v1.2.1 // indirect 19 | github.com/mattn/go-isatty v0.0.14 // indirect 20 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 21 | github.com/modern-go/reflect2 v1.0.2 // indirect 22 | github.com/pkg/errors v0.9.1 // indirect 23 | github.com/ugorji/go/codec v1.2.7 // indirect 24 | github.com/xdg-go/pbkdf2 v1.0.0 // indirect 25 | github.com/xdg-go/scram v1.0.2 // indirect 26 | github.com/xdg-go/stringprep v1.0.2 // indirect 27 | github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect 28 | go.mongodb.org/mongo-driver v1.9.1 // indirect 29 | golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 // indirect 30 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect 31 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect 32 | golang.org/x/text v0.3.7 // indirect 33 | google.golang.org/protobuf v1.28.0 // indirect 34 | gopkg.in/yaml.v2 v2.4.0 // indirect 35 | ) 36 | -------------------------------------------------------------------------------- /server/go.sum: -------------------------------------------------------------------------------- 1 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA= 5 | github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk= 6 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 7 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 8 | github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= 9 | github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= 10 | github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= 11 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 12 | github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= 13 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 14 | github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= 15 | github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= 16 | github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= 17 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 18 | github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= 19 | github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= 20 | github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= 21 | github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw= 22 | github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= 23 | github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= 24 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 25 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 26 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 27 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 28 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 29 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 30 | github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= 31 | github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 32 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 33 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 34 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 35 | github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= 36 | github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= 37 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 38 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 39 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 40 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 41 | github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= 42 | github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= 43 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 44 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 45 | github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= 46 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 47 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 48 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 49 | github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= 50 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 51 | github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= 52 | github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= 53 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= 54 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 55 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 56 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 57 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 58 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 59 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 60 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 61 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 62 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 63 | github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= 64 | github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= 65 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 66 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 67 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 68 | github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= 69 | github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= 70 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 71 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 72 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 73 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 74 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 75 | github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= 76 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 77 | github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= 78 | github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= 79 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 80 | github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= 81 | github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= 82 | github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= 83 | github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= 84 | github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w= 85 | github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= 86 | github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc= 87 | github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= 88 | github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= 89 | github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= 90 | go.mongodb.org/mongo-driver v1.9.1 h1:m078y9v7sBItkt1aaoe2YlvWEXcD263e1a4E1fBrJ1c= 91 | go.mongodb.org/mongo-driver v1.9.1/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= 92 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 93 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 94 | golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 95 | golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 96 | golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 h1:SLP7Q4Di66FONjDJbCYrCRrh97focO6sLogHO7/g8F0= 97 | golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 98 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 99 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 100 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 101 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 102 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= 103 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 104 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 105 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 106 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 107 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 108 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 109 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 110 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 111 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 112 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 113 | golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 114 | golang.org/x/sys v0.0.0-20220519141025-dcacdad47464 h1:MpIuURY70f0iKp/oooEFtB2oENcHITo/z1b6u41pKCw= 115 | golang.org/x/sys v0.0.0-20220519141025-dcacdad47464/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 116 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= 117 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 118 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 119 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 120 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 121 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 122 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 123 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 124 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= 125 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 126 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 127 | golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 128 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 129 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 130 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 131 | google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= 132 | google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 133 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 134 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 135 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 136 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 137 | gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= 138 | gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= 139 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 140 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 141 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 142 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 143 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 144 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 145 | -------------------------------------------------------------------------------- /server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "server/routes" 6 | 7 | "github.com/gin-contrib/cors" 8 | "github.com/gin-gonic/gin" 9 | ) 10 | 11 | func main() { 12 | port := os.Getenv("PORT") 13 | if port == "" { 14 | port = "8000" 15 | } 16 | 17 | router := gin.New() 18 | router.Use(gin.Logger()) 19 | router.Use(cors.Default()) 20 | 21 | routes.OrderRoute(router) 22 | 23 | router.Run(":" + port) 24 | } 25 | -------------------------------------------------------------------------------- /server/models/order_model.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "go.mongodb.org/mongo-driver/bson/primitive" 4 | 5 | type Order struct { 6 | ID primitive.ObjectID `bson:"_id"` 7 | Dish *string `json:"dish"` 8 | Price *float64 `json:"price"` 9 | Server *string `json:"server"` 10 | Table *string `json:"table"` 11 | } 12 | -------------------------------------------------------------------------------- /server/responses/order_response.go: -------------------------------------------------------------------------------- 1 | package responses 2 | 3 | type OrderResponse struct { 4 | Status int `json:"status"` 5 | Message string `json:"message"` 6 | Data map[string]interface{} `json:"data"` 7 | } 8 | -------------------------------------------------------------------------------- /server/routes/order_route.go: -------------------------------------------------------------------------------- 1 | package routes 2 | 3 | import ( 4 | "server/controllers" 5 | 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | func OrderRoute(router *gin.Engine) { 10 | // All order routes come here. 11 | router.POST("/order/create", controllers.AddOrder()) 12 | router.GET("/orders", controllers.GetAllOrders()) 13 | router.GET("/order/:orderId", controllers.GetOrderById()) 14 | router.GET("/waiter/:waiter", controllers.GetOrderByWaiter()) 15 | 16 | router.PUT("/waiter/update/:orderId", controllers.UpdateWaiter()) 17 | router.PUT("/order/update/:orderId", controllers.UpdateOrder()) 18 | 19 | router.DELETE("/order/delete/:orderId", controllers.DeleteOrder()) 20 | } 21 | --------------------------------------------------------------------------------