Skip to content

Commit

Permalink
CSS File generation(65) : Fixed main.css file generation when running…
Browse files Browse the repository at this point in the history
… server
  • Loading branch information
thisiszaida committed Dec 13, 2024
1 parent f1efce1 commit e31b17c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions backend/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const User = sequelize.define('User', {
}
});

// Review model
const Review = sequelize.define("Review", {
review_text: {
type: DataTypes.TEXT,
Expand All @@ -121,6 +122,7 @@ const Review = sequelize.define("Review", {
},
});

// sample events to test posting to db
const sampleEvents = [
{
name: 'Rock Fest 2024',
Expand Down Expand Up @@ -301,7 +303,9 @@ const sampleEvents = [
}
];

//sync database
//This code is used to sync the Sequelize models with the database (by dropping and recreating
// tables), insert sample event data, and fetch and log those events from the database.
// It's mainly used for testing or setting up initial data for development purposes.
(async () => {
try {
//Changed to force: false, so the database won't recreate itself every time
Expand All @@ -311,7 +315,7 @@ const sampleEvents = [
await Event.bulkCreate(sampleEvents); //TEMPORARY TO INSERT SAMPLE EVENTS
console.log('Sample events inserted');

const events = await Event.findAll();
const events = await Event.findAll(); // to see what events are in db
console.log('Events fetched from the database:', JSON.stringify(events, null, 2));
} catch (error) {
console.error('Error creating database and inserting sample data:', error);
Expand Down
12 changes: 8 additions & 4 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,27 +205,31 @@ app.delete("/events/:id", async (req, res) => {
}
});

// API endpoint to post submitted reviews to the database; request object has both content of review
// and the event that is being reviewed
app.post("/api/reviews", async (req, res) => {
console.log("in /api/reviews");
// Handle review submission
const { review_text, event_name } = req.body;
res.status(200).json({ review_text });
res.status(200).json({ review_text }); // send just the textual content of review in response
console.log("Server has received a review: ", review_text);

const newReview = await Review.create({
const newReview = await Review.create({ // create entry in Reviews table
review_text: req.body.review_text,
event_name: req.body.event_name,
});

});

// API endpoint to retrieve submitted reviews from the database; ultimately, these are shown on each individual
// event's page
app.get("/api/reviews", async (req, res) => {
const eventName = req.query.event_name;

try {
const reviews = await Review.findAll({ where: { event_name: eventName } });
const reviews = await Review.findAll({ where: { event_name: eventName } }); // finding reviews for specific event
res.json(reviews);
} catch (error) {
} catch (error) { // error catching
console.error("Error fetching reviews:", error);
res.status(500).json({ error: "Failed to fetch reviews" });
}
Expand Down

0 comments on commit e31b17c

Please sign in to comment.