Skip to content

Commit

Permalink
add new url
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeidlershenk committed Apr 15, 2024
1 parent 62d1011 commit 3a1c4c8
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ function App() {
const [minYear, setMinYear] = useState("");
const [maxYear, setMaxYear] = useState("");

function addUser(user) {
async function addUser(user) {
if (user === "") return;
let validUrl;
fetch("/verifyUser?user=" + user)
.then((res) => res.json())
.then((data) => {
validUrl = data.response;
if (!validUrl) return;
const newUsers = [...users, user];
setUsers(newUsers);
}, []);
console.log("fetching");
let response = await fetch(
"https://cinect-api-run-6bhdfkg7yq-ul.a.run.app/verifyUser?user=" + user,
{
headers: {
"ngrok-skip-browser-warning": "true",
"Access-Control-Allow-Origin": "*",
},
}
);
console.log(response);
let json = await response.json();
validUrl = json.response;
if (!validUrl) return;
const newUsers = [...users, user];
setUsers(newUsers);
}

function addGenre(genre) {
Expand All @@ -48,15 +56,28 @@ function App() {
setMaxYear(newMax);
}

function getRecommendation() {
async function getRecommendation() {
const dict = {
users: users,
genres: genres,
start_year: minYear,
end_year: maxYear,
};
console.log(JSON.stringify(dict));
fetch("/getRecommendation?data=" + JSON.stringify(dict))
let response = await fetch(
"https://cinect-api-run-6bhdfkg7yq-ul.a.run.app/getRecommendation?data=" + JSON.stringify(dict),
{
headers: {
"ngrok-skip-browser-warning": "true",
"Access-Control-Allow-Origin": "*",
},
}
)
console.log(response);
let json = await response.json();
const recommendations = json.response;
const bestRec = recommendations[0];
fetch(`https://www.omdbapi.com/?t=${bestRec}&apikey=f9a2d5c8`)
.then((res) => res.json())
.then((data) => {
const recommendations = data.response;
Expand Down

0 comments on commit 3a1c4c8

Please sign in to comment.