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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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?
+
+
+
+
+
+
+
+
+
+
Answer the Question
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.html b/index.html
index 56838b5..090a213 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.
+
+
+
+
@@ -1516,8 +1522,14 @@ Sentence: