diff --git a/src/TODO.md b/src/TODO.md index 92bb456..36407ab 100644 --- a/src/TODO.md +++ b/src/TODO.md @@ -1,5 +1,5 @@ # TODO - - Auction views + - Auction views 80% ---------------- - Auction searching at index - Bidding diff --git a/src/lib/db_models.rb b/src/lib/db_models.rb index 45d6d31..726e92a 100644 --- a/src/lib/db_models.rb +++ b/src/lib/db_models.rb @@ -286,7 +286,7 @@ class Auction < EntityModel @user_id = data["user_id"].to_i @title = data["title"] @description = data["description"] - @init_price = data["init_price"].to_i + @init_price = data["price"].to_i @start_time = data["start_time"].to_i @end_time = data["end_time"].to_i end @@ -320,22 +320,23 @@ class Auction < EntityModel self.insert data end - def self.compose_query_filters(title=nil, categories=nil, price_rng=nil, isopen=nil) + def self.compose_query_filters(title=nil, categories=nil, price_rng=nil, expired=nil) querystr = "SELECT * FROM Auction " - querystr += "WHERE " if title or categories or price_rng or isopen + querystr += "WHERE " if title or categories or price_rng or expired 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? + filters << "end_time < #{Time.now.to_i}" if !expired.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 + def self.search(title=nil, categories=nil, price_rng=nil, expired=nil) + q = self.compose_query_filters title, categories, price_rng, expired + data = self.query(q) or [] + data.map! {|dat| self.new(dat)} end def self.expired?(id) diff --git a/src/routes/auction.rb b/src/routes/auction.rb index 7dd11e5..8133ad7 100644 --- a/src/routes/auction.rb +++ b/src/routes/auction.rb @@ -3,9 +3,12 @@ get "/auctions" do title = params[:title] #categories = (params[:categories].split ",").map {|id| id.to_i} #price_rng = (params[:price_rng].split "-").map {|p| p.to_i} - isopen = params[:isopen] + expired = params[:expired] + p "#####" + p expired + p "#####" - auctions = Auction.search title #, categories, price_rng, isopen + auctions = Auction.search title #, categories, price_rng, expired serve :"auction/index", {auctions: auctions} end diff --git a/src/views/auction/index.slim b/src/views/auction/index.slim index c8ac553..3b6e3e9 100644 --- a/src/views/auction/index.slim +++ b/src/views/auction/index.slim @@ -11,8 +11,8 @@ input type="range" name="price_rng" .checkbox-container - input type="checkbox" name="isopen" value="1" - label Is Open? + input type="checkbox" name="expired" + label Expired? input type="submit" value="Search" article @@ -21,5 +21,8 @@ ul - auctions.each do |auction| li - a href="/auctions/#{auction["id"]}" - | #{auction["title"]} + a href="/auctions/#{auction.id}" + | #{auction.title} + - if auction.end_time and auction.end_time - Time.now.to_i <= 0 + span.red + | [Expired]