diff --git a/backend/controllers/Customer.controller.js b/backend/controllers/Customer.controller.js deleted file mode 100644 index 93c76d8..0000000 --- a/backend/controllers/Customer.controller.js +++ /dev/null @@ -1,72 +0,0 @@ -import client from "../db.js" -export const startQuiz = async (req, res) => { - const { User_id,Quiz_id } = req.body; - let exists; - try { - exists = await client.query( - "Select * from Questions where Questions.Quiz_id=$1;", - [Quiz_id] - ); - } catch (err) { - console.log(err); - } - if (exists.rowCount == 1) { - res.status(200).send( - exists - ); - } - else { - res.status(500).send("Wrong Quiz_id"); - } -}; - -export const seeLeaderboard = async (req, res) => { - const { Quiz_id } = req.body; - let exists; - try { - exists = await client.query( - "SELECT Fname || ' ' || Lname , correct_answers FROM User_data ,Marks where Marks.User_id = User_data.User_id and Marks.Quiz_id = $1", - [Quiz_id] - ); - } catch (err) { - console.log(err); - } - if (exists.rowCount != 0) { - res.status(200).send( - exists - ); - } - else { - res.status(500).send("NO result Found for this Quiz Id"); - } -}; - -export const endQuiz= async (req, res) => { - const { User_id, Quiz_id, selected } = req.body; - let exists; - console.log("wwd"); - try { - exists = await client.query( - "select correct_options from Questions where Quiz_id= $1", - [Quiz_id] - ); - } catch (err) { - console.log(err); - } - console.log("wwd"); - let count=0; - for(let i=0;i { + + let exists; + try { + exists = await client.query("select * from Mess "); + } catch (err) { + console.log(err); + } + console.log(exists.rows); + res.status(200).send(exists.rows); + }; + + + export const Subscribe_mess = async (req, res) => { + const { User_id, Mess_id, tokens } = req.body; + // INSERT INTO TableName (DateColumn) VALUES (CURRENT_DATE); + let exists; + try { + exists = await client.query("INSERT INTO Subscription(User_id,Mess_id,tokens,Daily_tokens,Subscription_date) VALUES($1,$2,$3,1,CURRENT_DATE);", [ + User_id, Mess_id, tokens + ]); + } catch (err) { + console.log(err); + } + // console.log(exists.rows); + res.status(200).send("Successfully Subscribed!"); + }; + + // use to alert user that subscription is about to end + export const Remaining_Daily_tokens = async (req,res) => { + const {User_id,Mess_id} = req.body; + + let exists; + + try { + exists = await client.query("Select Daily_tokens from Subscriptions where Mess_id=$1 and User_id = $2", + [ + Mess_id,User_id + ]) + }catch(err) { + console.log(err); + } + + res.status(200).send(exists.rowCount); + } + + // when user changes number of tiffins per day + export const Change_daily_tokens = async (req, res) => { + const { User_id,Mess_id,Daily_tokens} = req.body; + let exists; + try { + exists = await client.query("UPDATE Subscription SET Daily_tokens=$3 where User_id=$1 and Mess_id=$2", + [ + User_id,Mess_id,Daily_tokens + ]); + } catch (err) { + console.log(err); + } + // console.log(exists.rows); + res.status(200).send("Successfully Updated Daily Tokens!"); + }; + + export const Rate_Mess = async(req,res) => { + + const {User_id,Mess_id,Rating} = req.body; + + let exists; + try { + exists = await client.query("Select * from Ratings where User_id = $1 and Mess_id = $2", + [ + User_id,Mess_id + ]); + } catch (err) { + console.log(err); + } + + if(exists.rowCount!=0) + { + res.status(500).send("Cannot Rate the same Mess multiple times"); + }else + { + try { + exists = await client.query("Insert into Ratings(User_id,Mess_id,Rating) Values($1,$2,$3)", + [ + User_id,Mess_id,Rating + ]); + } catch (err) { + console.log(err); + } + } + res.status(200).send("Successfully Rated"); + } + + export const Update_profile = async (req, res) => { + + const {User_id,Fname, Lname, Phone_num, Password, User_address} = req.body; + + let exists; + try { + exists = await client.query("UPDATE Users SET Fname=$1, Lname=$2, Phone_num=$3, Password=$4, User_address=$5 where User_id=$6", + [ + Fname, Lname, Phone_num, Password, User_address,User_id + ]); + } catch (err) { + console.log(err); + } + // console.log(exists.rows); + res.status(200).send("Successfully Updated Profile!"); + }; + + export const filter_mess = async(req,res) => { + + const {Filter_rating} = req.body; + let exists; + + try{ + exists = await client.query("select * from Mess where Mess_id in (Select Mess_id from Ratings group by Mess_id having avg(Rating)>$1)",[Filter_rating]); + }catch(err){ + + console.log(err); + } + res.status(200).send(exists.body); + } + + export const Make_payment = async(req,res) => { + + } + + // daily tokens in subscription + // seperate rating table user id mess id rating + \ No newline at end of file diff --git a/backend/controllers/Delivery_boy.controller.js b/backend/controllers/Delivery_boy.controller.js deleted file mode 100644 index 691f412..0000000 --- a/backend/controllers/Delivery_boy.controller.js +++ /dev/null @@ -1,110 +0,0 @@ -import client from "../db.js"; -export const createQuiz = async (req, res) => { - const { user_id, question_count, name, duration } = req.body; - console.log(user_id); - console.log(question_count); - console.log(name); - console.log(duration); - let exists; - try { - await client.query( - "INSERT INTO Quiz(Creater_id,Name,questions_count,duration) VALUES($1,$2,$3,$4);", - [user_id, name, question_count, duration] - ); - } catch (err) { - console.log(err); - } - - try { - exists = await client.query("select max(Quiz_id) from Quiz"); - } catch (err) { - console.log(err); - } - - console.log(exists.rows[0]); - res.status(200).send(exists.rows[0]); -}; - -export const addQuestion = async (req, res) => { - const { - quiz_id, - question, - option_1, - option_2, - option_3, - option_4, - correct_answer, - } = req.body; - let exists; - try { - exists = await client.query( - "INSERT INTO Questions(Quiz_id,Ques_text,Option_1,Option_2,Option_3,Option_4,Correct_Option) VALUES($1,$2,$3,$4,$5,$6,$7);", - [ - quiz_id, - question, - option_1, - option_2, - option_3, - option_4, - correct_answer, - ] - ); - } catch (err) { - console.log(err); - } - res.status(200).send("question added sucessfully"); -}; - -export const viewQuestions = async (req, res) => { - const { quiz_id } = req.body; - let exists; - try { - exists = await client.query("select * from questions where Quiz_id=$1", [ - quiz_id, - ]); - } catch (err) { - console.log(err); - } - console.log(exists.rows); - res.status(200).send(exists.rows); -}; - -export const viewQuizzes = async (req, res) => { - const { user_id } = req.body; - let exists; - try { - exists = await client.query("select * from quiz where Creater_id=$1", [ - user_id, - ]); - } catch (err) { - console.log(err); - } - console.log(exists.rows); - res.status(200).send(exists.rows); -}; - -export const deleteQuiz = async (req, res) => { - const { user_id, quiz_id } = req.body; - let exists; - - try { - exists = await client.query( - "select * from Quiz where Quiz_id=$1 and Creater_id=$2", - [quiz_id, user_id] - ); - } catch (err) { - console.log(err); - } - - if (exists.rowCount === 0) res.status(500).send("Cannot delete Quiz"); - else { - try { - await client.query("delete from Marks where Quiz_id=$1", [quiz_id]); - await client.query("delete from Questions where Quiz_id=$1", [quiz_id]); - await client.query("delete from Quiz where Quiz_id=$1", [quiz_id]); - } catch (err) { - console.log(err); - } - res.status(200).send("Deleted"); - } -}; diff --git a/backend/controllers/Mess_owner.controller.js b/backend/controllers/Delivery_controller.js similarity index 100% rename from backend/controllers/Mess_owner.controller.js rename to backend/controllers/Delivery_controller.js diff --git a/backend/routes/Mess_owner.js b/backend/controllers/Mess_owner_controller.js similarity index 100% rename from backend/routes/Mess_owner.js rename to backend/controllers/Mess_owner_controller.js diff --git a/backend/controllers/Sign_controller.js b/backend/controllers/Sign_controller.js new file mode 100644 index 0000000..1154a16 --- /dev/null +++ b/backend/controllers/Sign_controller.js @@ -0,0 +1,48 @@ +import client from "../db.js"; +export const createUser = async (req, res) => { + const { Fname, Lname, Phone_num, Email, Password, User_address, User_type} = req.body; + let exists; + try { + exists = await client.query( + "Select * from Users where Users.email=$1 and Users.type=$2;", + [Email,User_type] + ); + } catch (err) { + console.log(err); + } + + if (exists.rowCount != 0) { + res.status(500).send("User already Existed. Try Sign in instead "); + } else { + let newUser; + try { + newUser = await client.query( + "INSERT INTO Users(Fname, Lname, Phone_num, Email, Password, User_address, User_type) VALUES ($1,$2,$3,$4,$5,$6,$7);", + [Fname, Lname, Phone_num, Email, Password, User_address, User_type] + ); + res.status(200).send("User has been created"); + } catch (err) { + console.log(err); + } + } +}; + +export const logInUser = async (req, res) => { + console.log("Email"); + const { Email, Password, User_type} = req.body; + + let userExists; + try { + userExists = await client.query( + "select User_id from Users WHERE Email=$1 and Password=$2 and User_type=$3;", + [Email, Password, User_type] + ); + } catch (err) { + console.log(err); + } + if (userExists.rowCount == 1) { + res.status(200).send(userExists.rows[0]); + } else { + res.status(500).send("User does not Exists"); + } +}; diff --git a/backend/controllers/signUp.controller.js b/backend/controllers/signUp.controller.js deleted file mode 100644 index ea3dfb1..0000000 --- a/backend/controllers/signUp.controller.js +++ /dev/null @@ -1,49 +0,0 @@ -import client from "../db.js" -// import query from "../query.js" -export const createUser = async (req, res) => { - const { Fname, Lname, email, password } = req.body; - let exists; - try { - exists = await client.query( - "Select * from User_data where User_data.email=$1", - [email] - ); - } catch (err) { - console.log(err); - } - if (exists.rowCount != 0) { - res.status(500).send( - "Email is already under use . Try Sign in instead " - ); - } else { - let newUser; - try { - newUser = await client.query( - "INSERT INTO User_data(Fname, Lname, Email, Password) VALUES ($1,$2,$3,$4);", - [Fname, Lname, email, password] - ); - res.status(200).send("User has been created"); - } catch (err) { - console.log(err); - } - } -}; - -export const logInUser = async (req, res) => { - const { email, password } = req.body; - let userExists; - try { - userExists = await client.query( - "select User_data.User_id from User_data WHERE Email=$1 and Password=$2;", - [email, password] - ); - } catch (err) { - console.log(err); - } - if (userExists.rowCount == 1) { - console.log(userExists.rows); - res.status(200).send(userExists.rows[0]); - } else { - res.status(500).send("user not exist"); - } -}; diff --git a/backend/db.js b/backend/db.js index 56143b5..14a4da5 100644 --- a/backend/db.js +++ b/backend/db.js @@ -1,6 +1,6 @@ import pg from 'pg'; var conString = - "postgres://btneohyg:DK6Bkm0ePKGblH86-DJmFFQ-TLfCGlzH@trumpet.db.elephantsql.com/btneohyg"; + "postgres://qqaqecoz:gmSfPJuIGEELe4n1MxZjB9fRN9I2Dszp@trumpet.db.elephantsql.com/qqaqecoz"; var client = new pg.Client(conString); client.connect(function (err) { if (err) { diff --git a/backend/package.json b/backend/package.json index 8a3b3f1..86cae06 100644 --- a/backend/package.json +++ b/backend/package.json @@ -2,6 +2,7 @@ "name": "backend", "version": "1.0.0", "description": "", + "type": "module", "main": "db.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", @@ -15,4 +16,5 @@ "express": "^4.18.2", "pg": "^8.11.1" } + } diff --git a/backend/routes/Customer.js b/backend/routes/Customer.js deleted file mode 100644 index 0848510..0000000 --- a/backend/routes/Customer.js +++ /dev/null @@ -1,18 +0,0 @@ -import express from "express"; -import { - createQuiz, - addQuestion, - viewQuestions, - viewQuizzes, - deleteQuiz, -} from "../controllers/quizAdmin.controller.js"; - -const router = express.Router(); - -router.post("/createquiz", createQuiz); -router.post("/addquestion", addQuestion); -router.post("/viewquestions", viewQuestions); // testing purpose -router.post("/viewquizzes", viewQuizzes); -router.post("/deletequiz", deleteQuiz); - -export default router; diff --git a/backend/routes/Customer_route.js b/backend/routes/Customer_route.js new file mode 100644 index 0000000..981ba64 --- /dev/null +++ b/backend/routes/Customer_route.js @@ -0,0 +1,5 @@ +import express from "express"; +const router = express.Router(); + + +export default router \ No newline at end of file diff --git a/backend/routes/Delivery_boy.js b/backend/routes/Delivery_boy.js deleted file mode 100644 index b1756b6..0000000 --- a/backend/routes/Delivery_boy.js +++ /dev/null @@ -1,10 +0,0 @@ -import express from "express"; -import { startQuiz,seeLeaderboard,endQuiz } from "../controllers/attemptQuiz.controller.js"; - -const router = express.Router(); - -router.post("/startQuiz", startQuiz); -router.post("/seeLeaderboard", seeLeaderboard); -router.post("/endQuiz", endQuiz); - -export default router; \ No newline at end of file diff --git a/backend/routes/Delivery_route.js b/backend/routes/Delivery_route.js new file mode 100644 index 0000000..981ba64 --- /dev/null +++ b/backend/routes/Delivery_route.js @@ -0,0 +1,5 @@ +import express from "express"; +const router = express.Router(); + + +export default router \ No newline at end of file diff --git a/backend/routes/Mess_owner_route.js b/backend/routes/Mess_owner_route.js new file mode 100644 index 0000000..981ba64 --- /dev/null +++ b/backend/routes/Mess_owner_route.js @@ -0,0 +1,5 @@ +import express from "express"; +const router = express.Router(); + + +export default router \ No newline at end of file diff --git a/backend/routes/Sign_routes.js b/backend/routes/Sign_routes.js new file mode 100644 index 0000000..5b40717 --- /dev/null +++ b/backend/routes/Sign_routes.js @@ -0,0 +1,9 @@ +import express from "express"; +import { createUser, logInUser } from "../controllers/Sign_controller.js"; + +const router = express.Router(); + +router.post("/signUp", createUser); +router.post("/login", logInUser); + +export default router; diff --git a/backend/routes/signUp.js b/backend/routes/signUp.js deleted file mode 100644 index f32552b..0000000 --- a/backend/routes/signUp.js +++ /dev/null @@ -1,9 +0,0 @@ -import express from "express"; -import { createUser, logInUser } from "../controllers/signUp.controller.js"; -//const {createUser, logInUser} = require('../controllers/signUp.controller.js'); -const router = express.Router(); - -router.post("/signUp", createUser); -router.post("/login", logInUser); - -export default router; \ No newline at end of file diff --git a/backend/server.js b/backend/server.js index 796fc01..7507156 100644 --- a/backend/server.js +++ b/backend/server.js @@ -2,8 +2,10 @@ import express from "express"; import bodyParser from "body-parser"; import cors from "cors"; -// import from "./routes/.js"; -// import from "./routes/.js"; +import Sign_routes from "./routes/Sign_routes.js" +import Customer_route from "./routes/Customer_route.js" +import Delivery_route from "./routes/Delivery_route.js" +import Mess_owner_route from "./routes/Mess_owner_route.js" const app = express(); @@ -18,8 +20,12 @@ app.use( }) ); -app.use("/auth", signUpRoutes); -app.use("/quizAdmin", quizAdminRoutes); +app.use("/auth", Sign_routes); +app.use("/Customer", Customer_route); +app.use("/Mess_owner",Mess_owner_route) +app.use("/Delivery_boy", Delivery_route); +// app.use("/test", (req,res)=>{console.log(665);res.send("hellppppp")}); + const port = 5000; app.listen(port, () => { console.log(`Server is listening on port ${port}`); diff --git a/frontend/src/App.js b/frontend/src/App.js index d32dbf0..e96deac 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -4,13 +4,11 @@ import Login from "./Components/Login"; import { Routes, BrowserRouter, Route } from "react-router-dom"; import SignUp from "./Components/SignUp"; import MessOwnerDashboard from "./Components/MessOwnerDashboard"; -// import Subscriber from "./Components/Subscriber" import Profile from "./Components/Profile"; function App() { return (
- } /> @@ -20,7 +18,8 @@ function App() { }/> -
- ); + + ) } -export default App; + +export default App diff --git a/models/design.css b/models/design.css new file mode 100644 index 0000000..2704f78 --- /dev/null +++ b/models/design.css @@ -0,0 +1,77 @@ + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + + +body { + font-family: Arial, sans-serif; + background-color: #f5f5f5; +} + +header { + background-color: #333; + color: #fff; + padding: 20px; +} + +header h1 { + font-size: 24px; +} + + +nav ul { + list-style: none; +} + +nav ul li { + display: inline; + margin-right: 20px; +} + +nav ul li a { + text-decoration: none; + color: #333; + font-weight: bold; +} + + +main { + max-width: 800px; + margin: 0 auto; + padding: 20px; + background-color: #fff; +} + + +footer { + text-align: center; + padding: 10px; + background-color: #333; + color: #fff; +} + + +@media (max-width: 768px) { + header { + padding: 10px; + } + + header h1 { + font-size: 20px; + } + + nav ul li { + margin-right: 10px; + } + + main { + padding: 10px; + } + + footer { + padding: 5px; + } +}