Auction: backend post & began validation

master
E. Almqvist 3 years ago
parent 7d0b3acca0
commit a18086d26f
  1. 16
      src/app.rb
  2. 5
      src/config.rb
  3. 15
      src/const.rb
  4. 25
      src/db_models.rb
  5. 4
      src/sql/tables/Auction.sql
  6. 2
      src/views/index.slim

@ -151,15 +151,21 @@ post "/user/update" do
end
# Auction stuff
get "/auction" do
get "/auctions" do
serve :"auction/index"
end
get "/auction/view/:id" do
get "/auction/new" do
serve :"auction/new"
end
post "/auctions" do
user_id = session[:userid]
title = params[:title]
end
get "/auctions/:id" do
id = params[:id].to_i
serve :"auction/view"
end
get "/auction/post" do
serve :"auction/new"
end

@ -31,5 +31,10 @@ LOGIN_ERRORS = {
fail: "Wrong password and/or email"
}
AUCTION_ERRORS = {
titlelen: "Title length must be between #{MIN_TITLE_LEN} and #{MAX_TITLE_LEN} characters!",
initprice: "The initial price must be at least #{MIN_INIT_PRICE}!"
}
# Auction stuff
AH_BUYOUT_FACTOR = 1.8

@ -6,14 +6,23 @@ MIN_REP = -100
MAX_REP = 100
PERM_LEVELS = {
post: 0, # allows the user to post auctions
rmpost: 1, # allows the user to remove other peoples auctions
roleman: 2 # allows the user to manage other peoples roles
banned: 2**0, # denies the user everything
rmpost: 2**1, # allows the user to remove other peoples auctions
roleman: 2**2, # allows the user to manage other peoples roles
cateman: 2**3, # allows the user to manage categories
}
# DB stuff
DB_PATH = "db/main.db"
# Auction constants
MIN_INIT_PRICE = 1
MIN_TITLE_LEN = 2
MAX_TITLE_LEN = 32
MIN_DESC_LEN = 0
MAX_DESC_LEN = 512
# User constants
AVATAR_SIZE = 1024 # width & height

@ -197,8 +197,31 @@ class Auction < EntityModel
@start_time = data["start_time"]
@end_time = data["end_time"]
end
def create(user_id, title, description, init_price, delta_time)
# Get current UNIX time
start_time = Time.now.to_i
end_time = start_time + delta_time
# Prep the payload
data = {
user_id: user_id,
title: title,
description: description,
init_price: init_price,
start_time: start_time,
end_time: end_time
}
self.insert data
end
def post(user_id, title, description, init_price, delta_time)
# validate input
end
end
class Category < EntityModel
attr_reader :name, :color
def initialize(data)
@ -216,6 +239,7 @@ class Category < EntityModel
end
end
class Image < EntityModel
attr_reader :auction_id, :image_order, :url
def initialize(data)
@ -226,6 +250,7 @@ class Image < EntityModel
end
end
class Auction_Category_relation < EntityModel
attr_reader :auction_id, :category_id
def initialize(data)

@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS "Auction" (
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"init_price" INTEGER NOT NULL DEFAULT 1,
"start_time" DATE NOT NULL,
"end_time" DATE NOT NULL,
"start_time" INTEGER NOT NULL,
"end_time" INTEGER NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT)
);

@ -6,7 +6,7 @@ article.index
li.em
a.button href="/auction" = "Browse Auctions"
li
a.button href="/auction/post" = "Post Auction"
a.button href="/auction/new" = "Post Auction"
article.index
h1.tcenter.title

Loading…
Cancel
Save