Auction posting

master
E. Almqvist 3 years ago
parent 8d1aadfa75
commit 7140b7206b
  1. 2
      src/Gemfile
  2. 4
      src/Gemfile.lock
  3. 3
      src/TODO.md
  4. 24
      src/app.rb
  5. 7
      src/db_models.rb
  6. BIN
      src/public/auctions/16/0.png
  7. BIN
      src/public/auctions/16/1.png
  8. BIN
      src/public/auctions/16/10.png
  9. BIN
      src/public/auctions/16/2.png
  10. BIN
      src/public/auctions/16/3.png
  11. BIN
      src/public/auctions/16/4.png
  12. BIN
      src/public/auctions/16/5.png
  13. BIN
      src/public/auctions/16/6.png
  14. BIN
      src/public/auctions/16/7.png
  15. BIN
      src/public/auctions/16/8.png
  16. BIN
      src/public/auctions/16/9.png
  17. 2
      src/views/auction/new.slim

@ -18,3 +18,5 @@ gem "redcarpet"
gem "rmagick", "~> 4.2"
gem "sinatra-flash", "~> 0.3.0"
gem "fileutils", "~> 1.6"

@ -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

@ -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?

@ -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

@ -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,

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

@ -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}"

Loading…
Cancel
Save