chore: fix bug where entries were not saved, implemented deplete function
This commit is contained in:
22
src/app.py
22
src/app.py
@@ -301,18 +301,19 @@ async def log_request():
|
||||
log.debug(f"Received request data: {data}")
|
||||
item = data.get("item")
|
||||
if item:
|
||||
data = await fetch_requested_data([item])
|
||||
# data = await fetch_requested_data([item])
|
||||
if not data:
|
||||
return jsonify({"status": "failed", "message": "Item not found"}), 404
|
||||
data = data[0]
|
||||
title = data.get("title")
|
||||
image_url = data.get("image")
|
||||
# data = data[0]
|
||||
manga_id = item.get("id")
|
||||
title = item.get("title")
|
||||
image_url = item.get("image")
|
||||
log.debug(
|
||||
f"Logging request for item: {item}, title: {title}, image_url: {image_url}"
|
||||
f"Logging request for item: {item}, title: {title}, image_url: {image_url}, manga_id: {manga_id}"
|
||||
)
|
||||
asynccache = KomCache()
|
||||
asynccache.insert(
|
||||
f"INSERT INTO manga_requests (manga_id, title, image) VALUES ({item}, '{title}', :image)",
|
||||
f"INSERT INTO manga_requests (manga_id, title, image) VALUES ({manga_id}, '{title}', :image)",
|
||||
args={"image": image_url},
|
||||
)
|
||||
return jsonify({"status": "success"})
|
||||
@@ -343,12 +344,13 @@ async def requests_page():
|
||||
async def delete_request():
|
||||
# Delete a request from the database. ID is sent after the /delete endpoint, so: /delete/<id>
|
||||
data = await request.get_json()
|
||||
item_id = data.get("item")
|
||||
log.debug(f"Received delete request data: {data}")
|
||||
|
||||
if item_id:
|
||||
if data:
|
||||
title = data.get("title")
|
||||
asynccache = KomCache()
|
||||
asynccache.query(
|
||||
"DELETE FROM manga_requests WHERE manga_id = :id", args={"id": item_id}
|
||||
asynccache.delete(
|
||||
"DELETE FROM manga_requests WHERE title = :title", args={"title": title}
|
||||
)
|
||||
return jsonify({"status": "success"})
|
||||
return jsonify({"status": "failed"}), 400
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<p>{{ request.title }}</p>
|
||||
<div class="actions">
|
||||
<button onclick="showInfo({{ request | tojson | safe }})" class="info">Info</button>
|
||||
<button onclick="deleteEntry({{ request.id }})" class="delete-button">Delete</button>
|
||||
<button onclick="deleteEntry('{{ request.title | escape }}')" class="delete-button">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
@@ -111,10 +111,11 @@
|
||||
closeModal();
|
||||
}
|
||||
}
|
||||
function deleteEntry(entryId) {
|
||||
function deleteEntry(title) {
|
||||
console.log("Deleting entry with title:", title);
|
||||
fetch(`/delete`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ item: entryId }),
|
||||
body: JSON.stringify({ title: title }), // Send title as part of a JSON object
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user