Skip to content

Commit

Permalink
added profile page + api handlers
Browse files Browse the repository at this point in the history
Co-authored-by: Cy <[email protected]>
Co-authored-by: Chloe <[email protected]>
Co-authored-by: Trisha Reddy <[email protected]>
Co-authored-by: rebekah-wang <[email protected]>
Co-authored-by: anusha <[email protected]>
  • Loading branch information
6 people committed Jul 20, 2023
1 parent abb4c69 commit 3cf7db9
Show file tree
Hide file tree
Showing 12 changed files with 489 additions and 70 deletions.
81 changes: 80 additions & 1 deletion client/src/api/abi.js
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
// TODO
import { base, showError } from "./util.js";

async function createABI(name, abi) {
let object = {
name: name,
abi: abi,
};

let res = await fetch(base + `/api/abi`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(object),
});

if (res.status >= 400) {
if (showError) {
console.log(res);
}
}

let data = await res.json();

let abi = await data["abi"];

return abi;
}

async function getABI(id) {
let res = await fetch(base + `/api/abi/` + id);

if (res.status >= 400) {
if (showError) {
console.log(res);
}
return null;
}

let object = await res.json();
let abis = await object["abis"];
return abis[0];
}

async function updateABI(id, name, abi) {
let obj = {
name: name,
abi: abi,
};

let res = await fetch(base + `/api/abi/` + id, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(obj),
});

if (res.status == 400) {
alert("You must change your name or abi!");
}

let data = await res.json();
let retABI = await data["abi"];
return retABI;
}

async function deleteABI(id) {
let res = await fetch(base + `/api/abi/` + id, {
method: "DELETE",
});

if (res.status == 400) {
alert("You must change your name or abi!");
return false;
}
return true;
}

export { createABI, getABI, updateABI, deleteABI };
68 changes: 49 additions & 19 deletions client/src/api/dataset.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { base, showError } from "./util.js";

async function createDataset(username, password) {
async function createDataset(name, description, address) {
let object = {
username: username,
password: password,
name: name,
description: description,
address: address,
};

let res = await fetch(base + `/api/dataset`, {
Expand All @@ -22,37 +23,66 @@ async function createDataset(username, password) {

let data = await res.json();

let user = await data["user"];
let dataset = await data["dataset"];

return user;
return dataset;
}

async function getDataset(id) {
const response = await fetch(base + `/api/dataset/` + id, {
let res = await fetch(base + `/api/dataset/` + id);

if (res.status >= 400) {
if (showError) {
console.log(res);
}
return null;
}

let object = await res.json();
let dataset = await object["dataset"];
return dataset;
}

async function changeDataset(id, name, description, address) {
let obj = {
name: name,
description: description,
address: address,
};

let res = await fetch(base + `/api/dataset/` + id, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(obj),
});

if (!response.ok) {
const message = `An error has occurred`;
window.alert(message);
return;
if (res.status == 400) {
alert("You must change your name or description or address!");
return null;
}

const object = await response.json();
const dataset = object.address; // correct?
let data = await res.json();

let dataset = await data["dataset"];

return dataset;
}

async function changeDataset(username, password) {
/* TODO: implement this thing! */
return;
}
async function deleteDataset(id) {
let res = await fetch(base + `/api/dataset/` + id, {
method: "DELETE",
});

if (res.status >= 400) {
if (showError) {
console.log(res);
}
return false;
}

async function deleteDataset(username, password) {
/* TODO: implement this thing! */
return;
return true;
}

export { createDataset, getDataset, changeDataset, deleteDataset };
64 changes: 49 additions & 15 deletions client/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,65 @@ async function createUser(username, password) {
}

async function getUser(id) {
const response = await fetch(base + `/api/user/` + id, {
let res = await fetch(base + `/api/user/` + id);

if (res.status >= 400) {
if (showError) {
console.log(res);
}
return null;
}

let object = await res.json();
let users = await object["users"];
return users[0];
}

async function updateUser(id, username, password) {
let obj = {
username: username,
password: password,
};

let res = await fetch(base + `/api/user/` + id, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(obj),
});

if (!response.ok) {
const message = `An error has occurred`;
window.alert(message);
return;
if (res.status == 400) {
alert("You must change your username or password!");
}

const object = await response.json();
const user = object.user;
if (res.status >= 400) {
if (showError) {
console.log(res);
}
return null;
}

let object = await res.json();

let user = await object["user"];

return user;
}

async function changeUser(username, password) {
/* TODO: implement this thing! */
return;
}
async function deleteUser(id) {
let res = await fetch(base + `/api/user/` + id, {
method: "DELETE",
});

if (res.status >= 400) {
if (showError) {
console.log(res);
}
return false;
}

async function deleteUser(username, password) {
/* TODO: implement this thing! */
return;
return true;
}

export { createUser, getUser, changeUser, deleteUser };
export { createUser, getUser, updateUser, deleteUser };
Binary file added client/src/assets/profile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion client/src/components/DataProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const DataProvider = ({ children }) => {
console.log(err);
});
}
}, [updateData]);
}, []);

useEffect(() => {
const fetchWallet = async () => {
Expand Down
Loading

0 comments on commit 3cf7db9

Please sign in to comment.