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

NW5 Manchester - Doris Siu - SQL - Week 1 #245

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7363558
Inserting .gitignore form a correctly forked repo
Doris-Siu Feb 8, 2023
f02822c
Level 100 - insert back all the back-up codes
Doris-Siu Feb 8, 2023
147d1e8
Update AddVideo.js
Doris-Siu Feb 8, 2023
cf0dedd
Add Rating component and vote buttons, and respective handler functions
Doris-Siu Feb 8, 2023
97bff6f
Create GUIDs to each added input video
Doris-Siu Feb 8, 2023
1f1d653
Update the remove button
Doris-Siu Feb 8, 2023
f87a366
Level 100- Add layout and simple CSS design
Doris-Siu Feb 9, 2023
714aa75
Complete Level 200 - Week 2 - Back End
Doris-Siu Feb 13, 2023
1c987ef
Complete Level 250 - Week 2 - Connecting Front End and Back End
Doris-Siu Feb 13, 2023
6120538
Complete Level 300 - Setting up Database
Doris-Siu Feb 20, 2023
ba0f114
config .env file & connect to aws rds db
Doris-Siu Mar 2, 2024
1c64edd
minor update to frontend
Doris-Siu Mar 2, 2024
f5276bb
create GitHub Actions workflow yaml file for client
Doris-Siu Mar 2, 2024
06e7f78
fix yaml formatting
Doris-Siu Mar 2, 2024
8fb5f38
update yaml file
Doris-Siu Mar 2, 2024
a7a577e
create GitHub Actions workflow yaml file for server
Doris-Siu Mar 2, 2024
5c8bfc6
Update server.js
Doris-Siu Mar 2, 2024
0322cf2
fix push path
Doris-Siu Mar 2, 2024
405759f
Update App.js
Doris-Siu Mar 2, 2024
6e1bc99
Update server.js
Doris-Siu Mar 2, 2024
a5abeeb
move the yaml file to correct dir
Doris-Siu Mar 2, 2024
aa75071
update server yaml
Doris-Siu Mar 2, 2024
f8c3fd9
server yaml
Doris-Siu Mar 2, 2024
7e633cc
server js
Doris-Siu Mar 3, 2024
6b45626
fix server yaml
Doris-Siu Mar 3, 2024
272475c
write key without remove \r
Doris-Siu Mar 3, 2024
982e98a
update with pem
Doris-Siu Mar 3, 2024
292a5e7
fix yaml bug
Doris-Siu Mar 3, 2024
a663ac9
ignore host key checking
Doris-Siu Mar 3, 2024
bc8b65d
fix dir path bug
Doris-Siu Mar 3, 2024
b5e069d
upload Dockerfile
Doris-Siu Mar 3, 2024
1471ce0
create terraform s3
Doris-Siu Mar 3, 2024
16083f4
create terraform ec2
Doris-Siu Mar 3, 2024
9a14ecb
create terraform rds
Doris-Siu Mar 3, 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.
30 changes: 30 additions & 0 deletions .github/workflows/ frontend-s3-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Frontend deployments to S3
on:
push:
branches:
- main
paths:
- "client/**"
defaults:
run:
working-directory: ./client
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup NodeJS
uses: actions/setup-node@v2
- name: Install Dependencies
run: npm install
- name: Build Frontend
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_KEY}}
aws-region: eu-west-2
- name: Sync build folder to S3 bucket
run: aws s3 sync ./build s3://doris-video-recommendation-app
27 changes: 27 additions & 0 deletions .github/workflows/backend-ec2-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Backend deployments to EC2
on:
push:
branches:
- main
paths:
- "server/**"
defaults:
run:
working-directory: ./server
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Add SSH key to agent
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > backend-ec2.pem
chmod 400 backend-ec2.pem

- name: SSH into EC2 instance and deploy
run: |
cat backend-ec2.pem
ssh -i backend-ec2.pem -o StrictHostKeyChecking=no ec2-user@${{ secrets.EC2_DNS }} "bash -c 'cd server && git pull && npm install && pm2 start server.js'"


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
client/build
Binary file added client/.DS_Store
Binary file not shown.
10,464 changes: 31 additions & 10,433 deletions client/package-lock.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions client/src/AddVideo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useState } from "react";

export default function AddVideo({ addVideo }) {
let [input, setInput] = useState({
title: "",
url: "",
rating: 0,
});

const handleChange = (e) => {
setInput({ ...input, [e.target.name]: e.target.value });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a minor suggestion, would it be possible to destructure name and value from e.target as variables?

};

const onSubmit = (e) => {
e.preventDefault();
input.id = uuidv4();
addVideo(input);
};

function uuidv4() {
Copy link

@Craques Craques Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can use the uuid library for this unless there is a valid reason to build your own random character generator, otherwise this looks great, good stuff

https://www.npmjs.com/package/uuid if you are using npm
https://yarnpkg.com/package/uuidv4 uf you are using yarn

return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
}

return (
<form onSubmit={onSubmit}>
<div>
<h3>Add a video</h3>
<label>Title:</label>
<input
id="title"
type="text"
name="title"
value={input.title}
onChange={handleChange}
required
/>
<label>URL:</label>
<input
id="url"
type="text"
name="url"
value={input.url}
onChange={handleChange}
required
/>
<button type="submit" className="btn btn-primary">
Add
</button>
</div>
</form>
);
}
15 changes: 15 additions & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
.App {
text-align: center;
}

.grid-container {
display: grid;
margin: 20px;
gap: 50px 0px;
grid-template-columns: auto auto auto auto;
}

button, input {
margin: 10px;
}

h3 {
color: red;
}
25 changes: 25 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import "./App.css";
import React, { useState, useEffect } from "react";
import VideoCards from "./VideoCards";
import AddVideo from "./AddVideo";
// import data from "./exampleresponse.json";

function App() {
let [videos, setVideos] = useState([]);

useEffect(function () {
fetch("http://52.56.239.192:5004")
.then((res) => res.json())
.then((data) => {
setVideos(data);
});
}, []);

function addVideo(video) {
setVideos([...videos, video]);
}

function removeVideo(id) {
setVideos(videos.filter((video) => video.id !== id));
}

return (
<div className="App">
<header className="App-header">
<h1>Video Recommendation</h1>
</header>
<AddVideo addVideo={addVideo} />
<VideoCards videoList={videos} removeVideo={removeVideo} />
</div>
);
}

export default App;
//test
24 changes: 24 additions & 0 deletions client/src/Rating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useState } from "react";

export default function Rating({ rating }) {
let [rate, setRate] = useState(rating);
function incrementRate() {
setRate(rate + 1);
}
function decrementRate() {
setRate(rate - 1);
}

return (
<div>
Rating: {rate}
<br />
<button type="button" className="btn btn-primary" onClick={incrementRate}>
Up Vote
</button>
<button type="button" className="btn btn-primary" onClick={decrementRate}>
Down Vote
</button>
</div>
);
}
38 changes: 38 additions & 0 deletions client/src/VideoCards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from "react";
import Rating from "./Rating";

export default function VideoCards({ videoList, removeVideo }) {
return (
<div className="grid-container">
{videoList.map((element, index) => (
<span key={index} className="card">
<iframe
width="560"
height="315"
src={
"https://www.youtube.com/embed/" +
element.url.replace("https://www.youtube.com/watch?v=", "")
}
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>{" "}
<div className="card-body">
<h4>{element.title}</h4>
<Rating rating={element.rating} />
<button
type="button"
className="btn btn-primary"
onClick={() => {
removeVideo(element.id);
}}
>
Remove video
</button>
</div>
</span>
))}
</div>
);
}
File renamed without changes.
Loading
Loading