1
0

Changed API endpoints. Implemented edit_entry().

This commit is contained in:
Alexander Andreev 2023-05-06 23:14:36 +04:00
parent 34765f9e47
commit 2ff097c058
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -5,6 +5,11 @@ function get_entry_id(button) {
// EDIT ENTRY
function edit_entry(e) {
let data = new URLSearchParams();
data.append("message", e.target.form[1].value);
fetch(`/api/guestbook/${e.target.form[0].value}`, {method: "PATCH", body: data})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
for (const edit_entry_button of document.getElementsByName("edit-entry"))
@ -13,7 +18,7 @@ for (const edit_entry_button of document.getElementsByName("edit-entry"))
// DELETE ENTRY
function delete_entry(e) {
fetch("/guestbook/admin/entry/"+get_entry_id(e.target), {method:"DELETE"})
fetch(`/api/guestbook/${e.target.form[0].value}`, {method:"DELETE"})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
@ -25,9 +30,8 @@ for (const delete_entry_button of document.getElementsByName("delete-entry"))
function edit_reply(e) {
let data = new URLSearchParams();
data.append("entry_id", e.target.form[0].value);
data.append("message", e.target.form[1].value);
fetch("/guestbook/admin/reply/?update", {method: "POST", body: data})
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method: "PATCH", body: data})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
@ -38,7 +42,7 @@ for (const edit_reply_button of document.getElementsByName("edit-reply"))
// DELETE REPLY
function delete_reply(e) {
fetch("/guestbook/admin/reply/"+get_entry_id(e.target), {method:"DELETE"})
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method:"DELETE"})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
@ -50,9 +54,8 @@ for (const delete_reply_button of document.getElementsByName("delete-reply"))
function send_reply(e) {
let data = new URLSearchParams();
data.append("entry_id", e.target.form[0].value);
data.append("message", e.target.form[1].value);
fetch("/guestbook/admin/reply/", {method: "POST", body: data})
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method: "PATCH", body: data})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}