Skip to content

Commit

Permalink
Merge pull request #490 from AyushSharma72/addshows
Browse files Browse the repository at this point in the history
added add shows api
  • Loading branch information
samyakmaitre authored Nov 5, 2024
2 parents 3761fc4 + 59d1937 commit bc125e6
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 131 deletions.
48 changes: 48 additions & 0 deletions backend/controllers/Shows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const ShowsModal = require("../models/Shows");

const express = require("express");
const router = express.Router();

router.post("/Addshows", async function AddShow(req, resp) {
try {
const { title, description, venue, startDate, endDate, email, website } =
req.body;
if (
!title ||
!description ||
!venue ||
!startDate ||
!endDate ||
!email ||
!website
) {
return resp.status(400).send({
message: "All fields are required",
});
}

const newShow = new ShowsModal({
title,
description,
venue,
startDate,
endDate,
email,
website,
});

const savedShow = await newShow.save();

resp.status(201).send({
message: "Show added successfully",
data: savedShow,
});
} catch (error) {
resp.status(500).send({
message: "An error occurred while adding the show",
error: error.message,
});
}
});

module.exports = router;
21 changes: 12 additions & 9 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const express = require("express");
const app = express();
const userController = require("./controllers/auth");
const AddShow = require("./controllers/Shows");
const database = require("./config/database");
const cookieParser = require("cookie-parser");
const cors = require("cors");
Expand All @@ -22,26 +23,28 @@ app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(
cors({
origin: "*",
credentials: true,
})
cors({
origin: "*",
credentials: true,
})
);

// Setting up routes
app.use("/api/v1/auth", userController);

app.use("/api/v1/shows", AddShow);

// Testing the server
app.get("/", (req, res) => {
return res.json({
success: true,
message: "Your server is up and running ...",
});
return res.json({
success: true,
message: "Your server is up and running ...",
});
});

// Listening to the server
app.listen(PORT, () => {
console.log(`App is listening at ${PORT}`);
console.log(`App is listening at ${PORT}`);
});

// End of code.
36 changes: 36 additions & 0 deletions backend/models/Shows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const mongoose = require("mongoose");

const ShowsSchema = mongoose.Schema(
{
title: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
venue: {
type: String,
required: true,
},
startDate: {
type: Date,
required: true,
},
endDate: {
type: Date,
required: true,
},
email: {
type: String,
required: true,
},
website: {
type: String,
},
},
{ timestamps: true }
);

module.exports = mongoose.model("shows", ShowsSchema);
Loading

0 comments on commit bc125e6

Please sign in to comment.