initial commit: migrated from FossilSCM to git
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
local application = {}
|
||||
|
||||
application.setdb = function(db)
|
||||
application.db = db
|
||||
end
|
||||
|
||||
application.new = function(t)
|
||||
local application_record = {}
|
||||
application_record.type = 'application'
|
||||
application_record.username = t.username
|
||||
application_record.salutation = t.salutation
|
||||
application_record.firstname = t.firstname
|
||||
application_record.lastname = t.lastname
|
||||
application_record.position = t.position
|
||||
application_record.store = t.store
|
||||
application_record.address = t.address
|
||||
application_record.practice_type = t.practice_type
|
||||
application_record.phone_office = t.phone_office
|
||||
application_record.phone_cell = t.phone_cell
|
||||
application_record.email = t.email
|
||||
application_record.submitted_at = os.time()
|
||||
application_record.status = 'open'
|
||||
|
||||
application.db:insertrecord(application_record)
|
||||
|
||||
return application_record
|
||||
end
|
||||
|
||||
return application
|
||||
@@ -0,0 +1,15 @@
|
||||
local cart = {}
|
||||
|
||||
cart.setdb = function(db)
|
||||
cart.db = db
|
||||
end
|
||||
|
||||
cart.newForUser = function(user_record)
|
||||
local cart_record = {['type']='cart', lineitem_ids={}, user_id=user_record.id}
|
||||
cart.db:insertrecord(cart_record)
|
||||
user_record.current_cart_id = cart_record.id
|
||||
user_record:save()
|
||||
return cart_record
|
||||
end
|
||||
|
||||
return cart
|
||||
@@ -0,0 +1,23 @@
|
||||
local customprice = {}
|
||||
|
||||
customprice.setdb = function(db)
|
||||
customprice.db = db
|
||||
end
|
||||
|
||||
customprice.find = function(item_record, user_record, db)
|
||||
return customprice.db:findByStructure({type='custom_price', item_id=item_record.id, user_id=user_record_id})[1]
|
||||
end
|
||||
|
||||
customprice.new = function(t, db)
|
||||
local customprice_record = {}
|
||||
customprice_record.type = 'custom_price'
|
||||
customprice_record.user_id = t.user.id
|
||||
customprice_record.item_id = t.item.id
|
||||
customprice_record.price = t.price
|
||||
|
||||
customprice.db:insertrecord(customprice_record)
|
||||
|
||||
return customprice_record
|
||||
end
|
||||
|
||||
return customprice
|
||||
@@ -0,0 +1,54 @@
|
||||
local basexx = require 'basexx'
|
||||
local uuid = require 'lua_uuid'
|
||||
local vips = require 'vips'
|
||||
local thumbnail = require './models/thumbnail'
|
||||
|
||||
local image = {}
|
||||
|
||||
-- where images are saved:
|
||||
--image.directory = 'thumbnails/'
|
||||
|
||||
image.setdb = function(db)
|
||||
image.db = db
|
||||
end
|
||||
|
||||
image.new = function(img_buffer, original_filename)
|
||||
local image_record = {};
|
||||
image_record['type'] = 'image'
|
||||
image_record.original_filename = original_filename
|
||||
|
||||
local new_filename = uuid()
|
||||
--local vips_image = vips.Image.new_from_buffer(img_buffer, "", {access = "sequential"})
|
||||
local thumbnail_original = vips.Image.new_from_buffer(img_buffer, "") -- don't give `{access = "sequential"}` option as 3rd parameter, since then it won't be able to be read twice: once for 960px thumbnail, and again for the 180px
|
||||
local thumbnail_960 = thumbnail_original:thumbnail_image(960)
|
||||
local thumbnail_180 = thumbnail_original:thumbnail_image(180)
|
||||
|
||||
--[[
|
||||
thumbnail_original:write_to_file(thumbnail_original_path, {compression=9}) -- LMDBTODO: instead of writing to file, store in record; store each thumbnail in individual records (type='thumbnail'), so binser doesn't have to deserialize all the sizes just to get one (small) size
|
||||
thumbnail_960:write_to_file(thumbnail_960_path, {compression=9})
|
||||
thumbnail_180:write_to_file(thumbnail_180_path, {compression=9})
|
||||
]]
|
||||
|
||||
local thumbnail_original_record = thumbnail.newfromvips(thumbnail_original)
|
||||
local thumbnail_960_record = thumbnail.newfromvips(thumbnail_960)
|
||||
local thumbnail_180_record = thumbnail.newfromvips(thumbnail_180)
|
||||
|
||||
-- TODO: close/release vips buffers, unless vips binding does it automatically
|
||||
|
||||
image_record.thumbnail_original_id = thumbnail_original_record.id
|
||||
image_record.thumbnail_960_id = thumbnail_960_record.id
|
||||
image_record.thumbnail_180_id = thumbnail_180_record.id
|
||||
|
||||
if image.db ~= nil then
|
||||
image.db:insertrecord(image_record)
|
||||
end
|
||||
|
||||
return image_record;
|
||||
end
|
||||
|
||||
image.new_from_base64 = function(img_base64, original_filename)
|
||||
local img_buffer = basexx.from_base64(img_base64)
|
||||
return image.new(img_buffer, original_filename);
|
||||
end
|
||||
|
||||
return image;
|
||||
@@ -0,0 +1,44 @@
|
||||
local util = require('./piazza-util')
|
||||
local user = require'./models/user'
|
||||
local customprice = require'./models/customprice'
|
||||
|
||||
local item = {}
|
||||
|
||||
item.setdb = function(db)
|
||||
item.db = db
|
||||
end
|
||||
|
||||
item.defaults = {
|
||||
name = ''
|
||||
}
|
||||
|
||||
item.create = function(t)
|
||||
-- util.setdefaults(t, item.defaults)
|
||||
--if t.name == nil then
|
||||
-- t.name = t.brand .. ' ' .. t.model .. ' (' .. t.color .. ')'
|
||||
--end
|
||||
return t
|
||||
end
|
||||
|
||||
item.new = function(t)
|
||||
t = t or {}
|
||||
local i = item.create(t)
|
||||
i.type = 'item'
|
||||
i.image_ids = {}
|
||||
i.inventory = 0
|
||||
item.db:insertrecord(i)
|
||||
return i
|
||||
end
|
||||
|
||||
item.priceof = function(item_record, user_record)
|
||||
local customprice_record = customprice.find(item_record, user_record)
|
||||
if customprice_record ~= nil then
|
||||
return customprice_record.price
|
||||
end
|
||||
if user.isgold(user_record) then
|
||||
return item_record.price_gold
|
||||
end
|
||||
return item_record.price_silver
|
||||
end
|
||||
|
||||
return item
|
||||
@@ -0,0 +1,25 @@
|
||||
local item = require'./models/item'
|
||||
|
||||
local lineitem = {}
|
||||
|
||||
lineitem.setdb = function(db)
|
||||
lineitem.db = db
|
||||
end
|
||||
|
||||
lineitem.new = function(t)
|
||||
local li = {}
|
||||
li.type = 'lineitem'
|
||||
li.cart_id = t.cart.id
|
||||
li.item_id = t.item.id
|
||||
li.quantity = t.quantity or 1
|
||||
local item_record = t.item
|
||||
local cart_record = t.cart
|
||||
local user_record = lineitem.db:getrecord(cart_record.user_id)
|
||||
li.price = item.priceof(item_record, user_record)
|
||||
lineitem.db:insertrecord(li)
|
||||
table.insert(cart_record.lineitem_ids, li.id)
|
||||
cart_record:save()
|
||||
return li
|
||||
end
|
||||
|
||||
return lineitem
|
||||
@@ -0,0 +1,24 @@
|
||||
local order = {}
|
||||
|
||||
order.setdb = function(db)
|
||||
order.db = db
|
||||
end
|
||||
|
||||
order.new = function(t)
|
||||
local order_record = {}
|
||||
order_record.type = 'order'
|
||||
order_record.cart_id = t.cart.id
|
||||
order_record.user_id = t.cart.user_id
|
||||
order_record.date_ordered = os.time()
|
||||
order_record.status = 'open'
|
||||
order_record.progress = 'ordered'
|
||||
|
||||
order.db:insertrecord(order_record)
|
||||
|
||||
t.cart.order_id = order_record.id
|
||||
t.cart:save()
|
||||
|
||||
return order_record
|
||||
end
|
||||
|
||||
return order
|
||||
@@ -0,0 +1,17 @@
|
||||
local thumbnail = {}
|
||||
|
||||
thumbnail.setdb = function(db)
|
||||
thumbnail.db = db
|
||||
end
|
||||
|
||||
thumbnail.newfromvips = function(vipsimage)
|
||||
local t = {}
|
||||
|
||||
t['type'] = 'thumbnail'
|
||||
t.src = vipsimage:write_to_buffer('.png', {compression=9})
|
||||
|
||||
thumbnail.db:insertrecord(t)
|
||||
return t
|
||||
end
|
||||
|
||||
return thumbnail
|
||||
@@ -0,0 +1,36 @@
|
||||
local hash = require('./piazza-util').hash
|
||||
|
||||
local user = {}
|
||||
|
||||
user.setdb = function(db)
|
||||
user.db = db
|
||||
end
|
||||
|
||||
user.new = function(t)
|
||||
local u = {}
|
||||
u.type = 'user'
|
||||
u.username = t.username
|
||||
u.password_hash = hash(t.password)
|
||||
u.salutation = t.salutation or 'mr'
|
||||
u.firstname = t.firstname or ''
|
||||
u.lastname = t.lastname or ''
|
||||
u.position = t.position or ''
|
||||
u.store = t.store or ''
|
||||
u.address = t.address or ''
|
||||
u.practice_type = t.practice_type or ''
|
||||
u.phone_office = t.phone_office or ''
|
||||
u.phone_cell = t.phone_cell or ''
|
||||
u.email = t.email or ''
|
||||
u.tier = t.tier or 'silver'
|
||||
u.is_admin = t.is_admin or false
|
||||
|
||||
user.db:insertrecord(u)
|
||||
|
||||
return u
|
||||
end
|
||||
|
||||
user.isgold = function(user_record)
|
||||
return user_record.tier == 'gold'
|
||||
end
|
||||
|
||||
return user
|
||||
Reference in New Issue
Block a user