Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task completed for Internship screening process #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions restaurant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

6 changes: 6 additions & 0 deletions restaurant/README.md
Original file line number Diff line number Diff line change
@@ -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.
158 changes: 158 additions & 0 deletions restaurant/contracts/restaurant.sol
Original file line number Diff line number Diff line change
@@ -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++;
}
}
15 changes: 15 additions & 0 deletions restaurant/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -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}`]
},
},
};

20 changes: 20 additions & 0 deletions restaurant/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
40 changes: 40 additions & 0 deletions restaurant/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -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 <script>`.
//
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
// will compile your contracts, add the Hardhat Runtime Environment's members to the
// global scope, and execute the script.
const hre = require("hardhat");

async function sleep(ms) {
return new Promise((resolve)=>{
setTimeout(() =>{
resolve();
},ms);
});
}
async function main() {

const restaurant = await hre.ethers.getContractFactory("restaurant");
const contract = await restaurant.deploy();
await contract.deployed();



console.log(`Contract deployed to ${contract.address}`);

await sleep(45 * 1000);

await hre.run("verify:verify",{
address: contract.address,
constructorArguments: [],

});
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});