@ -198,14 +198,14 @@ class Auction < EntityModel
@end_time = data [ " end_time " ]
end
def validate_ah ( title , description , init_price , delta_time )
def self . 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 )
def self . 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
@ -219,13 +219,31 @@ class Auction < EntityModel
user_id : user_id ,
title : title ,
description : description ,
init_ price: init_price ,
price : init_price ,
start_time : start_time ,
end_time : end_time
}
self . insert data
end
def self . compose_query_filters ( title = nil , categories = nil , price_rng = nil , isopen = nil )
querystr = " SELECT * FROM Auction "
querystr += " WHERE " if title or categories or price_rng or time_left
filters = [ ]
filters << " LIKE '% #{ title } %' " if title
filters << " price BETWEEN #{ price_rng [ 0 ] } AND #{ price_rng [ 1 ] } " if price_rng && price_rng . length == 2
filters << " end_time > #{ Time . now . to_i } " if ! isopen . nil?
querystr += filters . join " AND "
return querystr
end
def self . search ( title = nil , categories = nil , price_rng = nil , isopen = nil )
q = self . compose_query_filters title , categories , price_rng , isopen
self . query q
end
end