Skip to content

Commit

Permalink
Merge pull request #26 from A-Bahadory/feature/post_video_endpoint
Browse files Browse the repository at this point in the history
Completed adding post video endpoint
  • Loading branch information
A-Bahadory authored Apr 25, 2024
2 parents e8a3af3 + 86db249 commit 498a32c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion db/initdb.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
DROP TABLE IF EXISTS videos CASCADE;

CREATE TABLE videos (title VARCHAR, src VARCHAR);
CREATE TABLE videos (
id SERIAL PRIMARY KEY,
title VARCHAR,
src VARCHAR);

INSERT INTO videos (title,src) VALUES ('Never Gonna Give You Up','https://www.youtube.com/embed/dQw4w9WgXcQ?si=sdvqEritjOTwN2Af');
INSERT INTO videos (title,src) VALUES ('The Coding Train','https://www.youtube.com/embed/HerCR8bw_GE?si=5Xfqx9K1JMB_QCBh');
Expand Down
11 changes: 11 additions & 0 deletions server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ router.get("/videos", async (_, res) => {
.send({ success: "false", error: "Could not connect to database" });
});

router.post("/videos", async (req, res) => {
const newVideo = await db.query(
`INSERT INTO videos (title, src) VALUES ('${req.body.title}', '${req.body.src}')`
);
res.send(
newVideo
? res.send({ success: "Video added successfully" })
: res.send({ error: "Video could not be added" })
);
});

export default router;

0 comments on commit 498a32c

Please sign in to comment.