Auction validation

master
E. Almqvist 3 years ago
parent a18086d26f
commit ae082394ce
  1. 3
      src/config.rb
  2. 2
      src/const.rb
  3. 15
      src/db_models.rb

@ -33,7 +33,8 @@ LOGIN_ERRORS = {
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}!"
initprice: "The initial price must be at least #{MIN_INIT_PRICE}!",
deltatime: "Time span is too short! Must be at least one day!"
}
# Auction stuff

@ -24,6 +24,8 @@ MAX_TITLE_LEN = 32
MIN_DESC_LEN = 0
MAX_DESC_LEN = 512
MIN_DELTA_TIME = 60 * 60 * 24 # 1 day
# User constants
AVATAR_SIZE = 1024 # width & height

@ -198,7 +198,18 @@ class Auction < EntityModel
@end_time = data["end_time"]
end
def validate_ah(title, description, init_price, delta_time)
return false, AUCTION_ERRORS[:titlelen] unless title.length.between?(MIN_TITLE_LEN, MAX_TITLE_LEN)
return false, AUCTION_ERRORS[:initprice] unless init_price >= MIN_INIT_PRICE
return false, AUCTION_ERRORS[:deltatime] unless delta_time >= MIN_DELTA_TIME
return true, ""
end
def create(user_id, title, description, init_price, delta_time)
# Validate the input
check, errorstr = self.validate_ah(title, description, init_price, delta_time)
return errorstr unless check
# Get current UNIX time
start_time = Time.now.to_i
end_time = start_time + delta_time
@ -215,10 +226,6 @@ class Auction < EntityModel
self.insert data
end
def post(user_id, title, description, init_price, delta_time)
# validate input
end
end

Loading…
Cancel
Save