From 5a09673a19624d352d4f6cdef5da0c2d7e5c3e4d Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Sat, 1 Jun 2024 15:51:53 +0100 Subject: [PATCH 1/3] create table videos --- db/initdb.sql | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/db/initdb.sql b/db/initdb.sql index 7e5ceb1659..3747934279 100644 --- a/db/initdb.sql +++ b/db/initdb.sql @@ -3,9 +3,21 @@ DROP TABLE IF EXISTS videos CASCADE; CREATE TABLE videos ( + id serial primary key, title VARCHAR, src VARCHAR ); -INSERT INTO videos (]],src) VALUES ('Never Gonna Give You Up','https://www.youtube.com/watch?v=dQw4w9WgXcQ'); +INSERT INTO videos (title,src) VALUES ('Never Gonna Give You Up','https://www.youtube.com/watch?v=dQw4w9WgXcQ'); +INSERT INTO videos (title,src) VALUES ('The Coding Train','https://www.youtube.com/watch?v=HerCR8bw_GE'); +INSERT INTO videos (title,src) VALUES ('Mac & Cheese | Basics with Babish','https://www.youtube.com/watch?v=FUeyrEN14Rk'); +INSERT INTO videos (title,src) VALUES ('Videos for Cats to Watch - 8 Hour Bird Bonanza','https://www.youtube.com/watch?v=xbs7FT7dXYc'); +INSERT INTO videos (title,src) VALUES ('The Complete London 2012 Opening Ceremony | London 2012 Olympic Games','https://www.youtube.com/watch?v=4As0e4de-rI'); +INSERT INTO videos (title,src) VALUES ('Learn Unity - Beginner''s Game Development Course','https://www.youtube.com/watch?v=gB1F9G0JXOo'); +INSERT INTO videos (title,src) VALUES ('Cracking Enigma in 2021 - Computerphile','https://www.youtube.com/watch?v=RzWB5jL5RX0'); +INSERT INTO videos (title,src) VALUES ('Coding Adventure: Chess AI','https://www.youtube.com/watch?v=U4ogK0MIzqk'); +INSERT INTO videos (title,src) VALUES ('Coding Adventure: Ant and Slime Simulations','https://www.youtube.com/watch?v=X-iSQQgOd1A'); +INSERT INTO videos (title,src) VALUES ('Why the Tour de France is so brutal','https://www.youtube.com/watch?v=ZacOS8NBK6U'); + + -- you can insert more rows using example data from the example_data.csv file \ No newline at end of file From 596fb7df4f521a614d553e67e799026f9276395e Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Sat, 8 Jun 2024 11:14:59 +0100 Subject: [PATCH 2/3] add get all video endpoint --- server/server.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/server.js b/server/server.js index d3b334cbfd..9fbcd40e36 100644 --- a/server/server.js +++ b/server/server.js @@ -9,6 +9,11 @@ import app from "./app.js"; const server = http.createServer(app); const port = parseInt(process.env.PORT ?? "3000", 10); +//GET ALL VIDEOS +app.get("/videos", (request, response) => { + db.query("SELECT * FROM videos") + + server.on("listening", () => { const addr = server.address(); const bind = typeof addr === "string" ? `pipe ${addr}` : `port ${addr.port}`; From 829ab2169a5e0d64ed49f70286289d65be659d21 Mon Sep 17 00:00:00 2001 From: aishaathmanlali Date: Sat, 8 Jun 2024 11:16:04 +0100 Subject: [PATCH 3/3] add get video endpoint --- server/server.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/server.js b/server/server.js index 9fbcd40e36..3192a67cc5 100644 --- a/server/server.js +++ b/server/server.js @@ -12,6 +12,13 @@ const port = parseInt(process.env.PORT ?? "3000", 10); //GET ALL VIDEOS app.get("/videos", (request, response) => { db.query("SELECT * FROM videos") + .then((result) => { + response.status(200).json({ videos: result.rows }); + }) + .catch((err) => { + console.log(err); + }); +}); server.on("listening", () => {