Skip to content

Commit

Permalink
Remove cards from your wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
nfoert committed Aug 21, 2024
1 parent 3df151b commit 24b439f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cardie/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
path("deletecard", views.delete_card, name="deletecard"),
path("renamecard", views.rename_card, name="renamecard"),
path("savetowallet", views.save_to_wallet, name="savetowallet"),
path("getwallet", views.get_wallet, name="getwallet")
path("getwallet", views.get_wallet, name="getwallet"),
path("removefromwallet", views.remove_from_wallet, name="removefromwallet")
]
20 changes: 19 additions & 1 deletion cardie/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,28 @@ def get_wallet(request):

wallet.append(wallet_item)

return JsonResponse(wallet, safe=False)
return JsonResponse(wallet, safe=False)

except KeyError:
return HttpResponse("Not signed in")

else:
return HttpResponse("Request is not a POST request")

@csrf_exempt
def remove_from_wallet(request):
if request.method == "POST":
try:
me = User.objects.filter(username=request.session["username"])[0]

card_to_remove = me.wallet.filter(uuid=request.headers["uuid"])
print(card_to_remove)
me.wallet.remove(card_to_remove[0])

return HttpResponse("Success")

except KeyError:
return HttpResponse("Not signed in")

else:
return HttpResponse("Request is not a POST request")
24 changes: 24 additions & 0 deletions cardie/static/main/scripts/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,31 @@ function home_wallet_view(event) {
}

async function home_wallet_remove(event) {
const response = await fetch(server_ip + "/removefromwallet", {
method: "POST",
headers: {
"uuid": event.target.closest(".home_card").querySelector(":scope > .home_card_text > .home_card_text_uuid").innerText
}
});

response.text().then(function (text) {
if (text == "Request is not a POST request") {
create_notification("There was a problem removing that card from your wallet", text, "warning");
log("WARNING", text);

} else if (text == "Not signed in") {
create_notification("There was a problem removing that card from your wallet", text, "warning");
log("WARNING", text);

} else if (text == "Success") {
create_notification("Card removed from wallet", "The card has been removed from your wallet", "check-circle");
window.location.reload();

} else {
create_notification("There was a problem removing that card from your wallet", "There was an unknown issue", "warning");
log("WARNING", "There was an unknown issue: " + text);
}
});
}

async function list_cards() {
Expand Down
24 changes: 24 additions & 0 deletions cardie/staticfiles/main/scripts/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,31 @@ function home_wallet_view(event) {
}

async function home_wallet_remove(event) {
const response = await fetch(server_ip + "/removefromwallet", {
method: "POST",
headers: {
"uuid": event.target.closest(".home_card").querySelector(":scope > .home_card_text > .home_card_text_uuid").innerText
}
});

response.text().then(function (text) {
if (text == "Request is not a POST request") {
create_notification("There was a problem removing that card from your wallet", text, "warning");
log("WARNING", text);

} else if (text == "Not signed in") {
create_notification("There was a problem removing that card from your wallet", text, "warning");
log("WARNING", text);

} else if (text == "Success") {
create_notification("Card removed from wallet", "The card has been removed from your wallet", "check-circle");
window.location.reload();

} else {
create_notification("There was a problem removing that card from your wallet", "There was an unknown issue", "warning");
log("WARNING", "There was an unknown issue: " + text);
}
});
}

async function list_cards() {
Expand Down

0 comments on commit 24b439f

Please sign in to comment.