From cb0d828f044f6fccc4fce50de0d4de88a6902efd Mon Sep 17 00:00:00 2001 From: Shivansh Date: Sat, 9 Nov 2024 01:32:18 +0530 Subject: [PATCH 1/4] Added backend for forum --- backend/app.js | 3 ++ backend/controllers/faqController.js | 80 ++++++++++++++++++++++++++++ backend/models/answers.js | 12 +++++ backend/models/question.js | 21 ++++++++ backend/routes/faqRoutes.js | 10 ++++ 5 files changed, 126 insertions(+) create mode 100644 backend/controllers/faqController.js create mode 100644 backend/models/answers.js create mode 100644 backend/models/question.js create mode 100644 backend/routes/faqRoutes.js diff --git a/backend/app.js b/backend/app.js index 4f42f81..1b30621 100644 --- a/backend/app.js +++ b/backend/app.js @@ -10,6 +10,8 @@ import getInTouch from "./routes/getInTouchRoutes.js"; import addBlog from "./routes/addBlogRoutes.js"; import subscribe from "./routes/subscribeRoutes.js"; import discussion from "./routes/discussionRoutes.js"; +import faqRoutes from "./routes/faqRoutes.js"; + import cors from "cors"; import path from "path"; // Import path module import { fileURLToPath } from "url"; // Import fileURLToPath @@ -39,6 +41,7 @@ app.use("/api/getInTouch", getInTouch); app.use("/api/addBlog", addBlog); app.use("/api/newsletter", subscribe); app.use("/api/discussion", discussion); +app.use("/api/faq", faqRoutes); const PORT = process.env.PORT || 5000; app.listen(PORT, () => { diff --git a/backend/controllers/faqController.js b/backend/controllers/faqController.js new file mode 100644 index 0000000..5dbacd8 --- /dev/null +++ b/backend/controllers/faqController.js @@ -0,0 +1,80 @@ +import QuestionModel from "../models/question.js"; +import Answer from "../models/answers.js"; +export const createQuestion = async (req, res) => { + try { + const { content } = req.body; + + // Check if the question already exists + const existingQuestion = await QuestionModel.findOne({ content }); + if (existingQuestion) { + return res.status(400).json({ message: "Question already exists" }); + } + + // Create the new question + const newQuestion = new QuestionModel({ content }); + await newQuestion.save(); + + res.status(201).json(newQuestion); + } catch (error) { + res.status(500).json({ message: error.message }); + } + }; + +// Route to fetch questions based on 'answered' or 'unanswered' query +export const getQuestions = async (req, res) => { + try { + const question = req.query.question; + + let query; + if (question === "answered") { + // Fetch questions with at least one answer, and include the answers + query = QuestionModel.find({ answered: true }).populate("answers"); + + } else if (question === "unanswered") { + // Fetch questions with no answers + query = QuestionModel.find({ answered: false }).populate("answers"); + } else { + // If no specific filter is provided, fetch all questions + query = QuestionModel.find(); + } + + const questions = await query.exec(); + if(!question){ + res.status(200).json({message:"No response"}) + } + res.status(200).json(questions); + } catch (error) { + res.status(500).json({ message: error.message }); + } +}; + +// Example route to create a new question with an optional answer + +export const answerQuestion = async (req, res) => { + try { + const { questionId } = req.body; // The ID of the question to answer + const { content } = req.body; + + // Check if the question exists + const existingQuestion = await QuestionModel.findById(questionId); + if (!existingQuestion) { + return res.status(404).json({ message: "Question not found" }); + } + + // Create a new answer linked to the question + const newAnswer = new Answer({ + content, + question: questionId, + }); + await newAnswer.save(); + + // Add the answer ID to the question's answers array + existingQuestion.answers.push(newAnswer._id); + existingQuestion.answered=true; + await existingQuestion.save(); + + res.status(201).json({ message: "Answer added successfully", answer: newAnswer }); + } catch (error) { + res.status(500).json({ message: error.message }); + } + }; \ No newline at end of file diff --git a/backend/models/answers.js b/backend/models/answers.js new file mode 100644 index 0000000..c4806d7 --- /dev/null +++ b/backend/models/answers.js @@ -0,0 +1,12 @@ +import mongoose from "mongoose"; +import QuestionModel from './question.js'; + +const answerSchema = new mongoose.Schema({ + content:{ + type:String + }, + +}); + +const answer = mongoose.model("Answer", answerSchema); +export default answer; \ No newline at end of file diff --git a/backend/models/question.js b/backend/models/question.js new file mode 100644 index 0000000..59b08b8 --- /dev/null +++ b/backend/models/question.js @@ -0,0 +1,21 @@ +import mongoose, { Mongoose } from "mongoose"; +import answer from "./answers.js" +// import answer from "./answers.js"; +const questionSchema = new mongoose.Schema({ + content:{ + type:String + }, + answers:[ + { + type:mongoose.Schema.Types.ObjectId, + ref:answer + } + ], + answered:{ + type:Boolean, + default: false + }, + +}); +export default mongoose.models.Question || mongoose.model('Question', questionSchema); + diff --git a/backend/routes/faqRoutes.js b/backend/routes/faqRoutes.js new file mode 100644 index 0000000..68e81d3 --- /dev/null +++ b/backend/routes/faqRoutes.js @@ -0,0 +1,10 @@ +import express from "express"; +const router = express.Router(); +// import { getContact, saveContact } from "../controllers/contactController.js"; +import {createQuestion, getQuestions,answerQuestion} from "../controllers/faqController.js" + +router.post("/createquestion", createQuestion); +router.get("/getquestions",getQuestions); +router.post("/answerquestion",answerQuestion); + +export default router; \ No newline at end of file From e51278586def4f3b9ddc50ecaf08dcd8d30baf46 Mon Sep 17 00:00:00 2001 From: Shivansh Date: Sat, 9 Nov 2024 03:11:31 +0530 Subject: [PATCH 2/4] added FE for faq forum --- forum.html | 936 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 6 + 2 files changed, 942 insertions(+) create mode 100644 forum.html diff --git a/forum.html b/forum.html new file mode 100644 index 0000000..60f8717 --- /dev/null +++ b/forum.html @@ -0,0 +1,936 @@ + + + + + + WordWise - FAQs Forum + + + + + + + + + + + + + + + + + + + + + + +
+
+
+

FAQs Forum

+ + + + +
+
+ + +
+

Answered Questions

+
+ +
+

Q: What is the capital of France?

+
+

A: The capital of France is Paris.

+
+
+
+

Q: What is the largest ocean in the world?

+
+

A: The Pacific Ocean is the largest ocean in the world.

+
+
+
+
+ + +
+

Unanswered Questions

+
+ +
+

Q: What is the square root of 64?

+ +
+
+

Q: What is the chemical symbol for gold?

+ +
+
+
+
+ + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.html b/index.html index 56838b5..e8e5b0a 100644 --- a/index.html +++ b/index.html @@ -1491,6 +1491,12 @@

How can I stay updated with new blog posts?

subscribe to newsletters or enable notifications for real-time updates.

+ + +
+ +
+ From 63d4f6f8db572cd86bb956bcc6ccf77fbcf58b8d Mon Sep 17 00:00:00 2001 From: Prityanshu Singh Date: Sat, 9 Nov 2024 03:21:20 +0530 Subject: [PATCH 3/4] Fixed Save and Cancel Button --- profile.html | 8 ++++---- testp.css | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/profile.html b/profile.html index ac61e95..3302041 100644 --- a/profile.html +++ b/profile.html @@ -71,14 +71,14 @@

Recent Activity

- main - - +
+ + +
-edit

Notifications

diff --git a/testp.css b/testp.css index f18cc51..d2cbe4e 100644 --- a/testp.css +++ b/testp.css @@ -204,7 +204,34 @@ body { } +.button-container { + display: flex; + justify-content: right; + gap: 15px; + margin-top: 15px; + +} + +#saveButton, #cancelButton { + + background: rgb(51 51 51); + color: white; + border: none; + padding: 10px 20px; + cursor: pointer; + border-radius: 5px; + transition: background 0.3s, transform 0.3s; + position: relative; + height: 40px; +} + +#saveButton:hover, #cancelButton:hover { + + background-color: #000000; + transform: scale(1.05); + +} /* Media Queries for Responsiveness */ @media (max-width: 768px) { From 179ad1ea3199a5060f17e9ca120a9b0bb56d0f30 Mon Sep 17 00:00:00 2001 From: ilma Date: Sat, 9 Nov 2024 12:17:04 +0530 Subject: [PATCH 4/4] Update index.html and style.css --- index.html | 8 +++++++- style.css | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index d5b1871..5a80069 100644 --- a/index.html +++ b/index.html @@ -1407,8 +1407,14 @@

Sentence: