This commit is contained in:
Aritra Banik 2024-03-10 15:05:19 +05:30
parent 927a5a5e96
commit c24f4c6fe6
5 changed files with 76 additions and 60 deletions

Binary file not shown.

BIN
src/a3

Binary file not shown.

View File

@ -4,9 +4,9 @@ import
os,
nimja/parser,
strutils,
./a3pkg/[models, mics, htmx],
./a3c/[products, users, cart],
./[admin, cart, about, index, checkout, validation]
./a3pkg/[models, mics],
./a3c/[users],
./[admin, cart, about, index, checkout, validation, contact, shop]
"/" -> [get, post]: ctx.index()
@ -29,64 +29,10 @@ import
"/validation/phone" -> post: ctx.validationPhone()
"/validation/country" -> post: ctx.validationCountry()
"/contact" -> get:
"/contact" -> get: ctx.contact()
var
db = newDatabase()
products: seq[Products]
cookies = ctx.cookies
email = cookies.getOrDefault("email", "")
password = cookies.getOrDefault("password", "")
if email != "" and password != "":
var
userId = db.getUserId(email, password)
cart = db.getUserCart(userId)
for c, d in cart:
var product = db.getProductById(d.productId)
products.add(product)
compileTemplateFile(getScriptDir() / "a3a" / "contact.nimja")
"/shop" -> get:
var
db = newDatabase()
availableProducts = db.availableProducts()
products: seq[Products]
cookies = ctx.cookies
email = cookies.getOrDefault("email", "")
password = cookies.getOrDefault("password", "")
if email != "" and password != "":
products = micsGetProducts(email, password)
compileTemplateFile(getScriptDir() / "a3a" / "shop.nimja")
"/shop-single" -> get:
var
db = newDatabase()
productName = ctx.queryParams["prod"]
product = db.getProductByName(productName)
products: seq[Products]
cookies = ctx.cookies
email = cookies.getOrDefault("email", "")
password = cookies.getOrDefault("password", "")
if email != "" and password != "":
products = micsGetProducts(email, password)
compileTemplateFile(getScriptDir() / "a3a" / "shop-single.nimja")
"/shop" -> get: ctx.shop()
"/shop-single" -> get: ctx.shopSingle()
"/login" -> get:
var

28
src/contact.nim Normal file
View File

@ -0,0 +1,28 @@
import
mike,
segfaults,
os,
nimja/parser,
./a3pkg/[models, mics],
./a3c/[products, users, cart]
proc contact*(ctx: Context): string=
var
db = newDatabase()
products: seq[Products]
cookies = ctx.cookies
email = cookies.getOrDefault("email", "")
password = cookies.getOrDefault("password", "")
if email != "" and password != "":
var
userId = db.getUserId(email, password)
cart = db.getUserCart(userId)
for c, d in cart:
var product = db.getProductById(d.productId)
products.add(product)
compileTemplateFile(getScriptDir() / "a3a" / "contact.nimja")

42
src/shop.nim Normal file
View File

@ -0,0 +1,42 @@
import
mike,
segfaults,
os,
nimja/parser,
./a3pkg/[models, mics],
./a3c/[products]
proc shop*(ctx: Context): string=
var
db = newDatabase()
availableProducts = db.availableProducts()
products: seq[Products]
cookies = ctx.cookies
email = cookies.getOrDefault("email", "")
password = cookies.getOrDefault("password", "")
if email != "" and password != "":
products = micsGetProducts(email, password)
compileTemplateFile(getScriptDir() / "a3a" / "shop.nimja")
proc shopSingle*(ctx: Context): string=
var
db = newDatabase()
productName = ctx.queryParams["prod"]
product = db.getProductByName(productName)
products: seq[Products]
cookies = ctx.cookies
email = cookies.getOrDefault("email", "")
password = cookies.getOrDefault("password", "")
if email != "" and password != "":
products = micsGetProducts(email, password)
compileTemplateFile(getScriptDir() / "a3a" / "shop-single.nimja")