From 9e3544ed2dfcf75c2cc0a2c30e1290112545ad97 Mon Sep 17 00:00:00 2001 From: Jayaprakash Sahoo Date: Mon, 25 Sep 2023 18:03:14 +0530 Subject: [PATCH] added restaurant folder --- restaurant/.gitignore | 11 ++ restaurant/README.md | 6 ++ restaurant/contracts/restaurant.sol | 158 ++++++++++++++++++++++++++++ restaurant/hardhat.config.js | 15 +++ restaurant/package.json | 20 ++++ restaurant/scripts/deploy.js | 40 +++++++ 6 files changed, 250 insertions(+) create mode 100644 restaurant/.gitignore create mode 100644 restaurant/README.md create mode 100644 restaurant/contracts/restaurant.sol create mode 100644 restaurant/hardhat.config.js create mode 100644 restaurant/package.json create mode 100644 restaurant/scripts/deploy.js diff --git a/restaurant/.gitignore b/restaurant/.gitignore new file mode 100644 index 00000000..00dad773 --- /dev/null +++ b/restaurant/.gitignore @@ -0,0 +1,11 @@ +node_modules +.env +coverage +coverage.json +typechain +typechain-types + +# Hardhat files +cache +artifacts + diff --git a/restaurant/README.md b/restaurant/README.md new file mode 100644 index 00000000..95566d25 --- /dev/null +++ b/restaurant/README.md @@ -0,0 +1,6 @@ +# Restaurant ordering system + +I referred to the hotelBooking folder here and have created this folder, where the owner can set thalis. +a user can order a specific thali by paying the respective price of the thali. +the user will be given a order ID. +the user can review the thali by entering the order ID and the rating. \ No newline at end of file diff --git a/restaurant/contracts/restaurant.sol b/restaurant/contracts/restaurant.sol new file mode 100644 index 00000000..a013860f --- /dev/null +++ b/restaurant/contracts/restaurant.sol @@ -0,0 +1,158 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.8.14; + + +contract restaurant{ + + struct foodThali{ + uint id; + string thaliName; + uint price; + uint stock; + uint review; + uint reviewNo; + } + + struct order{ + uint orderId; + uint thaliId; + string thaliName; + address customerAddr; + } + + struct customer{ + string name; + string addre; + uint custIdNo; + } + + uint private custCount; + address public owner; + uint private orderCount; + + modifier onlyowner{ + require(msg.sender == owner , "Only owner has the rights to add rooms"); + _; + } + + mapping(uint=>foodThali) public foodThaliDetails; + mapping(uint=>order) public orderDetails; + mapping(address=>customer) public customerDetails; + + constructor(){ + owner = msg.sender; + setfoodThali(1, "Veg Thali", 79, 200, 0); + setfoodThali(2, "Egg Thali", 89, 100, 0); + setfoodThali(3, "Fish Thali", 99, 120, 0); + setfoodThali(4, "Paneer Thali", 109, 80, 0); + setfoodThali(5, "Chicken Thali", 119, 150, 0); + setfoodThali(6, "Prawn Thali", 129, 50, 0); + } + + function setfoodThali(uint _id, string memory _thaliName, uint _price, uint _stock, uint _review ) public onlyowner{ + foodThaliDetails[_id].thaliName = _thaliName; + foodThaliDetails[_id].price = _price; + foodThaliDetails[_id].stock = _stock; + foodThaliDetails[_id].review = _review; + } + + function setcust(address _addr , string memory _name ,string memory _addre) public { + customerDetails[_addr].name = _name; + customerDetails[_addr].addre = _addre; + customerDetails[_addr].custIdNo = custCount; + custCount++ ; + } + + + function payToOrder() public payable { + if(msg.value==79){ + orderVegThali(); + } + else if(msg.value==89){ + orderEggThali(); + } + else if(msg.value==99){ + orderFishThali(); + } + else if(msg.value==109){ + orderPaneerThali(); + } + else if(msg.value==119){ + orderChickenThali(); + } + else if(msg.value==129){ + orderPrawnThali(); + } + else{ + revert(); + } + } + + + function orderVegThali() internal { + require(foodThaliDetails[1].stock > 0 , "No more stock available."); + foodThaliDetails[1].stock-- ; + orderDetails[orderCount].orderId = orderCount; + orderDetails[orderCount].thaliId = 1; + orderDetails[orderCount].thaliName = foodThaliDetails[1].thaliName; + orderDetails[orderCount].customerAddr = msg.sender; + orderCount++; + } + + function orderEggThali() internal { + require(foodThaliDetails[2].stock > 0 , "No more stock available."); + foodThaliDetails[2].stock-- ; + orderDetails[orderCount].orderId = orderCount; + orderDetails[orderCount].thaliId = 2; + orderDetails[orderCount].thaliName = foodThaliDetails[2].thaliName; + orderDetails[orderCount].customerAddr = msg.sender; + orderCount++; + } + + function orderFishThali() internal { + require(foodThaliDetails[3].stock > 0 , "No more stock available."); + foodThaliDetails[3].stock-- ; + orderDetails[orderCount].orderId = orderCount; + orderDetails[orderCount].thaliId = 3; + orderDetails[orderCount].thaliName = foodThaliDetails[3].thaliName; + orderDetails[orderCount].customerAddr = msg.sender; + orderCount++; + } + + function orderPaneerThali() internal { + require(foodThaliDetails[4].stock > 0 , "No more stock available."); + foodThaliDetails[4].stock-- ; + orderDetails[orderCount].orderId = orderCount; + orderDetails[orderCount].thaliId = 4; + orderDetails[orderCount].thaliName = foodThaliDetails[4].thaliName; + orderDetails[orderCount].customerAddr = msg.sender; + orderCount++; + } + + function orderChickenThali() internal { + require(foodThaliDetails[5].stock > 0 , "No more stock available."); + foodThaliDetails[5].stock-- ; + orderDetails[orderCount].orderId = orderCount; + orderDetails[orderCount].thaliId = 5; + orderDetails[orderCount].thaliName = foodThaliDetails[5].thaliName; + orderDetails[orderCount].customerAddr = msg.sender; + orderCount++; + } + + function orderPrawnThali() internal { + require(foodThaliDetails[6].stock > 0 , "No more stock available."); + foodThaliDetails[6].stock-- ; + orderDetails[orderCount].orderId = orderCount; + orderDetails[orderCount].thaliId = 6; + orderDetails[orderCount].thaliName = foodThaliDetails[6].thaliName; + orderDetails[orderCount].customerAddr = msg.sender; + orderCount++; + } + + function rateOrder(uint _orderId, uint _rating) external { + require(orderDetails[_orderId].customerAddr == msg.sender, "The order Number is wrong."); + uint locThaliId = orderDetails[_orderId].thaliId; + foodThaliDetails[locThaliId].review = (_rating + (foodThaliDetails[locThaliId].review*foodThaliDetails[locThaliId].reviewNo)) / (foodThaliDetails[locThaliId].reviewNo + 1) ; + foodThaliDetails[locThaliId].reviewNo++; + } +} \ No newline at end of file diff --git a/restaurant/hardhat.config.js b/restaurant/hardhat.config.js new file mode 100644 index 00000000..32252f14 --- /dev/null +++ b/restaurant/hardhat.config.js @@ -0,0 +1,15 @@ +require("dotenv").config(); +require("@nomiclabs/hardhat-ethers"); + +const { RPC_URL, PRIVATE_KEY } = process.env; +/** @type import('hardhat/config').HardhatUserConfig */ +module.exports = { + solidity: "0.8.19", + networks: { + buildbear: { + url: RPC_URL, + accounts: [`0x${PRIVATE_KEY}`] + }, + }, +}; + diff --git a/restaurant/package.json b/restaurant/package.json new file mode 100644 index 00000000..f5565504 --- /dev/null +++ b/restaurant/package.json @@ -0,0 +1,20 @@ +{ + "name": "restaurant", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@nomiclabs/hardhat-ethers": "^2.2.3", + "ethers": "^5.0.0", + "hardhat": "^2.17.3" + }, + "dependencies": { + "dotenv": "^16.3.1" + } +} diff --git a/restaurant/scripts/deploy.js b/restaurant/scripts/deploy.js new file mode 100644 index 00000000..89e25726 --- /dev/null +++ b/restaurant/scripts/deploy.js @@ -0,0 +1,40 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node