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

Feature delete endpoint #507

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2e6cf62
set up local development environment
aishaathmanlali May 20, 2024
8b3bbda
setup local database
aishaathmanlali May 20, 2024
25b09fc
format and lint code
aishaathmanlali May 20, 2024
05c492f
Merge pull request #1 from aishaathmanlali/feature-codequality
LauraSantiag0 May 20, 2024
e9ec6f7
complete, receiving response 200 ok
LauraSantiag0 May 20, 2024
7e00902
Merge pull request #2 from LauraSantiag0/check-frontend-deployment
aishaathmanlali May 20, 2024
5c92e0b
deploy database on supabase
aishaathmanlali May 20, 2024
5a09673
create table videos
aishaathmanlali Jun 1, 2024
2a09144
create table videos
aishaathmanlali Jun 1, 2024
4879db5
Merge branch 'CodeYourFuture:main' into main
LauraSantiag0 Jun 8, 2024
596fb7d
add get all video endpoint
aishaathmanlali Jun 8, 2024
829ab21
add get video endpoint
aishaathmanlali Jun 8, 2024
4e8d8e1
fixing_folders
LauraSantiag0 Jun 8, 2024
10a3e78
fixing
LauraSantiag0 Jun 8, 2024
a4ea45a
Merge pull request #3 from LauraSantiag0/error-handling-for-get-videos
LauraSantiag0 Jun 8, 2024
7872fac
I finished the ticket and the error is now working
LauraSantiag0 Jun 8, 2024
88dc08f
Merge pull request #5 from LauraSantiag0/error-handling-for-get-videos
LauraSantiag0 Jun 8, 2024
8d7833e
create table videos
aishaathmanlali Jun 1, 2024
7c0bb46
add get all video endpoint
aishaathmanlali Jun 8, 2024
8a7a29a
add get video endpoint
aishaathmanlali Jun 8, 2024
e994ec6
modifies end point to get all videos
aishaathmanlali Jun 8, 2024
5708951
Resolved merge conflict in server.js
aishaathmanlali Jun 8, 2024
d78b5ec
Merge pull request #33 from aishaathmanlali/feature-videos-endpoint
LauraSantiag0 Jun 8, 2024
831396d
Merge pull request #34 from aishaathmanlali/feature-supabase
LauraSantiag0 Jun 8, 2024
425b1f7
fix a conflict on server.js
aishaathmanlali Jun 8, 2024
7e6da9f
Merge pull request #35 from aishaathmanlali/feature-videos-endpoint
aishaathmanlali Jun 8, 2024
97a35ef
list video recommendation complete with link working
LauraSantiag0 Jun 8, 2024
e134105
Merge pull request #36 from LauraSantiag0/list-video-rec
aishaathmanlali Jun 8, 2024
68ca503
A form to add neu videos
LauraSantiag0 Jun 10, 2024
293122e
Merge pull request #37 from LauraSantiag0/New-video-form
aishaathmanlali Jun 10, 2024
b57a9b8
delete button
LauraSantiag0 Jun 10, 2024
1d02ac3
Merge pull request #38 from LauraSantiag0/delete-video
aishaathmanlali Jun 10, 2024
f299a59
delete endpoint
aishaathmanlali Jun 11, 2024
cae383a
test delete endpoint
aishaathmanlali Jun 11, 2024
f0297e3
update delete endpoint and working
aishaathmanlali Jun 11, 2024
b798816
modify client side to delete the video using the delete endpoint
aishaathmanlali Jun 11, 2024
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
Binary file added .DS_Store
Binary file not shown.
File renamed without changes.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ While you are free to use this codebase for your future projects we recommend ag

For launch projects and future portfolio pieces, look at the [Code Your Future Starter Kit](https://github.com/CodeYourFuture/cyf-final-project-starter-kit). This assessment project is a simplified version of the starter kit, with a lot of the features removed to keep it light and more understandable. In fact, some of the challenges in this project are to re-add these features yourself, like support for linting.

Since these features will already be present in the starter kit, it will be a much better starting point. And since it uses the same libraries and setup that you will learn here, you should feel immediately familiar with it.
Since these features will already be present in the starter kit, it will be a much better starting point. And since it uses the same libraries and setup that you will learn here, you should feel immediately familiar with it.
Binary file added client/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<body>
<div id="root"></div>
<script type="module" src="/src/index.jsx"></script>

</body>
</html>
5 changes: 5 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import VideoForm from "./components/VideoForm";
import Videos from "./components/Videos";

const App = () => {
return (
<>
<h1>Video Recommendations</h1>
<Videos />

</>
);
};
Expand Down
44 changes: 44 additions & 0 deletions client/src/components/VideoForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// components/VideoForm.js
import { useState } from 'react';

const VideoForm = ({ addVideo }) => {
const [title, setTitle] = useState('');
const [url, setUrl] = useState('');

const handleSubmit = (e) => {
e.preventDefault();
if (title && url) {
addVideo({ title, src: url });
setTitle('');
setUrl('');
}
};

return (
<form onSubmit={handleSubmit}>
<div>
<label>Title:</label>
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="Type your video"
required
/>
</div>
<div>
<label>YouTube URL:</label>
<input
type="url"
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder="URL"
required
/>
</div>
<button type="submit">Add New Video</button>
</form>
);
};

export default VideoForm;
65 changes: 65 additions & 0 deletions client/src/components/Videos.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useEffect, useState } from "react";
import VideoForm from "./VideoForm";

const Videos = () => {
const [videos, setVideos] = useState([]);

useEffect(() => {
const fetchVideos = async () => {
try {
const response = await fetch("/api/videos");
const data = await response.json();
setVideos(data.videos);
console.log(data);
} catch (error) {
console.error("Error fetching videos:", error);
}
};

fetchVideos();
}, []);

const addVideo = (video) => {
setVideos((prevVideos) => [...prevVideos, video]);
};

const deleteVideo = async (id) => {
try {
const response = await fetch(`/api/videos/${id}`, {
method: "DELETE",
});

if (response.status === 204) {
setVideos((prevVideos) =>
prevVideos.filter((video) => video.id !== id)
);
} else if (response.status === 404) {
console.error("Video not found");
} else {
console.error("Failed to delete video");
}
} catch (error) {
console.error("Error deleting video:", error);
}
};

return (
<div>
<h2>Video List</h2>
<VideoForm addVideo={addVideo} />

<ul>
{videos.map((video) => (
<li key={video.id}>
<a href={video.src} target="_blank" rel="noopener noreferrer">
{video.title}
</a>
<button onClick={() => deleteVideo(video.id)}>Delete</button>
</li>
))}
</ul>
</div>
);
};

export default Videos;
1 change: 1 addition & 0 deletions data/example_data.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"title","src"
"Never Gonna Give You Up","https://www.youtube.com/watch?v=dQw4w9WgXcQ"
"The Coding Train","https://www.youtube.com/watch?v=HerCR8bw_GE"
"Mac & Cheese | Basics with Babish","https://www.youtube.com/watch?v=FUeyrEN14Rk"
Expand Down
12 changes: 12 additions & 0 deletions db/initdb.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
DROP TABLE IF EXISTS videos CASCADE;

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/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
Binary file added e2e/.DS_Store
Binary file not shown.
Loading
Loading