Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added add shows api #490

Merged
merged 1 commit into from
Nov 5, 2024
Merged
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
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