This commit is contained in:
Aritra Banik 2024-03-09 15:55:17 +05:30
parent 4e8692df0c
commit 61e0dc1c9c
4 changed files with 15 additions and 10 deletions

BIN
src/a3

Binary file not shown.

View File

@ -144,12 +144,10 @@ import
ctx.redirect("/cart") ctx.redirect("/cart")
"/checkout" -> get: "/checkout" -> [get, post]:
echo "get"
var var
db = newDatabase() db = newDatabase()
cart: seq[Cart] cart: seq[Cart] = newSeq[Cart]() # Initialize empty cart
products: seq[Products] products: seq[Products]
productCount = 0 productCount = 0
ch = "" ch = ""
@ -164,11 +162,18 @@ import
if email != "": if email != "":
productCount = micsCartProductCount(email, password) productCount = micsCartProductCount(email, password)
# var
# userId = db.getUserId(email, password)
# if userId != 0: # Check if user ID is valid (not 0)
# cart = db.getUserCart(userId)
# for c, d in cart:
# var product = db.getProductById(d.productId)
# products.add(product)
if productName == "" and email == "": if productName == "" and email == "":
ctx.redirect("/login") ctx.redirect("/login")
elif productName != "": if productName != "":
var var
product: Products product: Products
ca: Cart ca: Cart
@ -182,6 +187,7 @@ import
ch = "d" ch = "d"
else: else:
# ctx.redirect("/login")
var var
userId = db.getUserId(email, password) userId = db.getUserId(email, password)
cart = db.getUserCart(userId) cart = db.getUserCart(userId)
@ -192,7 +198,7 @@ import
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
"/checkout" -> post: "/validation/checkout" -> post:
echo "post" echo "post"
var var
db = newDatabase() db = newDatabase()
@ -504,8 +510,7 @@ import
ctx &= initCookie("password", password) ctx &= initCookie("password", password)
if quantity != 0: if quantity != 0:
# ctx.redirect("/checkout?prod=" & productName & "&quantity=" & $quantity) ctx.redirect("/checkout?prod=" & productName & "&quantity=" & $quantity)
ctx.redirect(fmt"/checkout?prod={productName}&quantity={quantity}")
else: else:
ctx.redirect("/") ctx.redirect("/")

View File

@ -79,7 +79,7 @@
</div> </div>
<form <form
hx-trigger="submit" hx-trigger="submit"
hx-post="/checkout" hx-post="/validation/checkout"
hx-target="#change" hx-target="#change"
class="row" class="row"
> >

View File

@ -141,7 +141,7 @@ proc sendCheckOut*(val: Table[string, Validity], total: string): string =
</div> </div>
<form <form
hx-trigger="submit" hx-trigger="submit"
hx-post="/checkout" hx-post="/validation/checkout"
hx-target="#change" hx-target="#change"
class="row" class="row"
> >