From 2ff097c0589bd995d0b749e577a2e789a47ef06c Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 6 May 2023 23:14:36 +0400 Subject: [PATCH] Changed API endpoints. Implemented edit_entry(). --- web/assets/js/guestbook_admin.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web/assets/js/guestbook_admin.js b/web/assets/js/guestbook_admin.js index 92ca5c3..fd22c74 100644 --- a/web/assets/js/guestbook_admin.js +++ b/web/assets/js/guestbook_admin.js @@ -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"); }