diff --git a/src/Gemfile b/src/Gemfile index 86c329f..8fb309a 100644 --- a/src/Gemfile +++ b/src/Gemfile @@ -18,3 +18,5 @@ gem "redcarpet" gem "rmagick", "~> 4.2" gem "sinatra-flash", "~> 0.3.0" + +gem "fileutils", "~> 1.6" diff --git a/src/Gemfile.lock b/src/Gemfile.lock index a91e860..1448889 100644 --- a/src/Gemfile.lock +++ b/src/Gemfile.lock @@ -4,6 +4,7 @@ GEM bcrypt (3.1.16) colorize (0.8.1) ffi (1.15.5) + fileutils (1.6.0) multi_json (1.15.0) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) @@ -43,6 +44,7 @@ PLATFORMS DEPENDENCIES bcrypt colorize + fileutils (~> 1.6) redcarpet rmagick (~> 4.2) sassc @@ -53,4 +55,4 @@ DEPENDENCIES sqlite3 BUNDLED WITH - 2.2.28 + 2.3.10 diff --git a/src/TODO.md b/src/TODO.md index 81c9889..fcad8b4 100644 --- a/src/TODO.md +++ b/src/TODO.md @@ -1,5 +1,5 @@ # TODO - - Auction posting (single image) + - Auction posting - Auction views ---------------- - Auction searching at index @@ -10,5 +10,4 @@ - User reviews ## Refactor - - Multiple images for auctions - Funds transfer logic for auctions? diff --git a/src/app.rb b/src/app.rb index cd4bb63..4ed8b11 100755 --- a/src/app.rb +++ b/src/app.rb @@ -13,6 +13,7 @@ require "bcrypt" # password digest # TODO: remove redcarpet dep require "redcarpet" # markdown renderer require "rmagick" # image manipulation +require "fileutils" # file utils require_relative "config" # config stuff require_relative "debug" # debug methods @@ -205,16 +206,21 @@ post "/auctions" do # Create the auction newid, resp = Auction.create user_id, title, description, init_price, delta_time - # Apply categories to auction - category_choices = (params.select { |k, v| k.to_s.match(/^category-\d+/) }).map{ |k, v| v.to_i } - - # Save auction images TODO: literally make this work - images = params[:images] - p "########################" - #image = Magick::Image.from_blob(images.read) - p "########################" - if newid then + # Save auction images + images = params[:images] + images.each_with_index do |img, i| + Image.save img[:tempfile].read, newid, i + end + + # Apply categories to auction + category_choices = (params.select { |k, v| k.to_s.match(/^category-\d+/) }).map{ |k, v| v.to_i } + category_choices.each do |catid| + if Category.exists? catid then + Auction_Category_relation.insert({auction_id: newid, category_id: catid}) + end + end + flash[:success] = "Auction posted!" redirect "/auctions/#{newid}" else diff --git a/src/db_models.rb b/src/db_models.rb index e5375a8..66fb190 100644 --- a/src/db_models.rb +++ b/src/db_models.rb @@ -299,11 +299,6 @@ class Auction < EntityModel end def self.create(user_id, title, description, init_price, delta_time) - # Remove invalid categories -# categories.select! do |id| -# self.exists? id -# end - # Validate the input check, errorstr = self.validate_ah(title, description, init_price, delta_time) return check, errorstr unless check @@ -386,6 +381,8 @@ class Image < EntityModel end def self.save(imgdata, ah_id, order) + FileUtils.mkdir_p "./public/auctions/#{ah_id}" + data = { auction_id: ah_id, image_order: order, diff --git a/src/public/auctions/16/0.png b/src/public/auctions/16/0.png new file mode 100644 index 0000000..e45757b Binary files /dev/null and b/src/public/auctions/16/0.png differ diff --git a/src/public/auctions/16/1.png b/src/public/auctions/16/1.png new file mode 100644 index 0000000..aec44e7 Binary files /dev/null and b/src/public/auctions/16/1.png differ diff --git a/src/public/auctions/16/10.png b/src/public/auctions/16/10.png new file mode 100644 index 0000000..f9e65a5 Binary files /dev/null and b/src/public/auctions/16/10.png differ diff --git a/src/public/auctions/16/2.png b/src/public/auctions/16/2.png new file mode 100644 index 0000000..b1e6772 Binary files /dev/null and b/src/public/auctions/16/2.png differ diff --git a/src/public/auctions/16/3.png b/src/public/auctions/16/3.png new file mode 100644 index 0000000..35a8590 Binary files /dev/null and b/src/public/auctions/16/3.png differ diff --git a/src/public/auctions/16/4.png b/src/public/auctions/16/4.png new file mode 100644 index 0000000..8df9523 Binary files /dev/null and b/src/public/auctions/16/4.png differ diff --git a/src/public/auctions/16/5.png b/src/public/auctions/16/5.png new file mode 100644 index 0000000..e6a5a70 Binary files /dev/null and b/src/public/auctions/16/5.png differ diff --git a/src/public/auctions/16/6.png b/src/public/auctions/16/6.png new file mode 100644 index 0000000..0207b19 Binary files /dev/null and b/src/public/auctions/16/6.png differ diff --git a/src/public/auctions/16/7.png b/src/public/auctions/16/7.png new file mode 100644 index 0000000..d8529f4 Binary files /dev/null and b/src/public/auctions/16/7.png differ diff --git a/src/public/auctions/16/8.png b/src/public/auctions/16/8.png new file mode 100644 index 0000000..f7ae1e2 Binary files /dev/null and b/src/public/auctions/16/8.png differ diff --git a/src/public/auctions/16/9.png b/src/public/auctions/16/9.png new file mode 100644 index 0000000..732d859 Binary files /dev/null and b/src/public/auctions/16/9.png differ diff --git a/src/views/auction/new.slim b/src/views/auction/new.slim index e7f9497..49ae73f 100644 --- a/src/views/auction/new.slim +++ b/src/views/auction/new.slim @@ -3,7 +3,7 @@ .form-container form#auction_new action="/auctions" method="post" enctype="multipart/form-data" label Select images - input type="file" name="images" accept="image" multiple="multiple" + input type="file" name="images[]" accept="image" multiple="multiple" label Title input type="text" name="title" placeholder="Title" pattern="#{TITLE_REGEX_STR}"