Skip to content
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
16 changes: 16 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const {
createAdmin,
} = require("./Routes/adminController");

const {createCategory, getCategory, updateCategory, deleteCategory,searchProductAdmin}= require('./Routes/adminController');
const {filterActivity,searchProductTourist}= require('./Routes/touristController');
const {filterActivityGuest}= require('./Routes/guestController');
const {searchProductSeller}= require('./Routes/sellerController');
// Load environment variables from .env file
dotenv.config();

Expand All @@ -22,6 +26,18 @@ const MongoURI = process.env.MONGO_URI;
app.use(express.json());
app.use('/api', advertiserRoutes); // Use advertiser routes under '/api'

app.post("/addCategory",createCategory);
app.get("/viewCategory",getCategory);
app.put("/updateCategory/:categoryId",updateCategory);
app.delete("/deleteCategory/:categoryId",deleteCategory);
app.get("/filterActivity",filterActivity);
app.get("/filterActivityGuest",filterActivityGuest);
app.get("/searchProductTourist",searchProductTourist);
app.get("/searchProductAdmin",searchProductAdmin);
app.get("/searchProductSeller",searchProductSeller);



// MongoDB Connection
mongoose.connect(MongoURI, {
useNewUrlParser: true,
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ const activitySchema = new Schema({
type: String,
required: false // Optional
},
budget: {
type: Number,
required: false // Optional
},
booking_open: {
type: Boolean,
default: true // Default value is true
Expand Down
76 changes: 75 additions & 1 deletion src/Routes/adminController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const TourismGoverner = require("../Models/TourismGoverner");
const Admin = require("../Models/Admin");
const Category = require("../Models/Category");
const Product = require("../Models/Product");

//Tourism Governer
const createTourismGoverner = async (req, res) => {
Expand Down Expand Up @@ -38,4 +40,76 @@ const createAdmin = async (req, res) => {
}
};

module.exports = { createTourismGoverner, createAdmin };

const createCategory = async(req,res) => {

const {name} = req.body;

try{
const category = await Category.create({name});
res.status(200).json(category)
}catch(error){
res.status(400).json({error:error.message})
}

}

const getCategory = async (req, res) => {

try {
const category = await Category.find({});
res.status(200).json(category);
} catch (error) {

res.status(500).json({ message: 'Error retrieving categories', error });
}
}

const updateCategory = async (req, res) => {

try {
const { categoryId } = req.params;
const { name } = req.body;

const updatedCategory = await Category.findByIdAndUpdate(categoryId, {name}, { new: true });

if (!updatedCategory) {
return res.status(404).json({ message: 'Category not found' });
}

res.status(200).json(updatedCategory);
} catch (error) {
res.status(500).json({ message: 'Error updating category', error });
}
}

const deleteCategory = async (req, res) => {
try {

const { categoryId } = req.params;
const deletedCategory = await Category.findByIdAndDelete(categoryId);

if (!deletedCategory) {
return res.status(404).json({ message: 'Category not found' });
}

res.status(200).json(deletedCategory);
} catch (error) {

res.status(500).json({ message: 'Error deleting category', error });
}
}

const searchProductAdmin = async (req, res) => {

const { name } = req.body;
try {
const product = await Product.find({name});
res.status(200).json(product);
} catch (error) {

res.status(500).json({ message: 'Error retrieving product', error });
}
}

module.exports = { createTourismGoverner, createAdmin ,createCategory, getCategory, updateCategory, deleteCategory, searchProductAdmin };
30 changes: 30 additions & 0 deletions src/Routes/guestController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Activity = require("../Models/Activity");

const filterActivityGuest = async (req, res) => {
const { budget, date, category, rating } = req.body;

// Initialize an empty query object
let query = {};

// Add filters to the query object only if they are provided in the request body
if (budget) query.budget = budget;
if (date) query.date = date;
if (category) query.category = category;
if (rating) query.rating = rating;

try {
// Perform the query with dynamic filters
const activity = await Activity.find(query);

if (activity.length === 0) {
return res.status(404).json({ message: 'No activity found' });
}

res.status(200).json(activity);
} catch (error) {
res.status(400).json({ error: error.message });
}
};


module.exports = { filterActivityGuest };
16 changes: 16 additions & 0 deletions src/Routes/sellerController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Product = require("../Models/Product");

const searchProductSeller = async (req, res) => {

const { name } = req.body;
try {
const product = await Product.find({name});
res.status(200).json(product);
} catch (error) {

res.status(500).json({ message: 'Error retrieving product', error });
}
}


module.exports = { searchProductSeller };
45 changes: 45 additions & 0 deletions src/Routes/touristController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const Activity = require("../Models/Activity");
const Product = require("../Models/Product");



const filterActivity = async (req, res) => {
const { budget, date, category, rating } = req.body;

// Initialize an empty query object
let query = {};

// Add filters to the query object only if they are provided in the request body
if (budget) query.budget = budget;
if (date) query.date = date;
if (category) query.category = category;
if (rating) query.rating = rating;

try {
// Perform the query with dynamic filters
const activity = await Activity.find(query);

if (activity.length === 0) {
return res.status(404).json({ message: 'No activity found' });
}

res.status(200).json(activity);
} catch (error) {
res.status(400).json({ error: error.message });
}
};

const searchProductTourist = async (req, res) => {

const { name } = req.body;
try {
const product = await Product.find({name});
res.status(200).json(product);
} catch (error) {

res.status(500).json({ message: 'Error retrieving product', error });
}
}


module.exports = { filterActivity,searchProductTourist };