diff --git a/.gitignore b/.gitignore index 6db3c9a5bc..ca77b76fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,11 +5,19 @@ # git config --global core.excludesfile '~/.gitignore_global' # Ignore bundler config. + + +.DS_Store + +coverage + /.bundle +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + # Ignore all logfiles and tempfiles. /log/* !/log/.keep -/tmp - -.DS_Store +/tmp \ No newline at end of file diff --git a/Gemfile b/Gemfile index fc06e5713d..8cea3c1192 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,8 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.1.0' + +gem 'bootstrap-sass' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby @@ -24,7 +26,7 @@ gem 'jbuilder', '~> 2.0' gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' +gem 'bcrypt', '~> 3.1.7' # Use Unicorn as the app server # gem 'unicorn' @@ -35,6 +37,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'simplecov' + gem 'rails-erd' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index a9da33c60c..487de96f64 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,10 +37,17 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + autoprefixer-rails (6.3.6) + execjs + bcrypt (3.1.11) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootstrap-sass (3.3.6) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.2) byebug (8.2.5) + choice (0.2.0) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -50,6 +57,7 @@ GEM coffee-script-source (1.10.0) concurrent-ruby (1.0.1) debug_inspector (0.0.2) + docile (1.1.5) erubis (2.7.0) execjs (2.6.0) globalid (0.3.6) @@ -96,6 +104,11 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) + rails-erd (1.4.7) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.3) loofah (~> 2.0) railties (4.2.6) @@ -106,6 +119,7 @@ GEM rake (11.1.2) rdoc (4.2.2) json (~> 1.4) + ruby-graphviz (1.2.2) sass (3.4.22) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -116,6 +130,11 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simplecov (0.11.2) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) spring (1.7.1) sprockets (3.6.0) concurrent-ruby (~> 1.0) @@ -143,18 +162,25 @@ PLATFORMS ruby DEPENDENCIES + bcrypt (~> 3.1.7) + bootstrap-sass byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails pg (~> 0.15) rails (= 4.2.6) + rails-erd sass-rails (~> 5.0) sdoc (~> 0.4.0) + simplecov spring turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) +RUBY VERSION + ruby 2.3.0p0 + BUNDLED WITH 1.12.1 diff --git a/app/assets/images/ditzy_icon.png b/app/assets/images/ditzy_icon.png new file mode 100644 index 0000000000..12a61fae5e Binary files /dev/null and b/app/assets/images/ditzy_icon.png differ diff --git a/app/assets/images/ditzy_logo_final.png b/app/assets/images/ditzy_logo_final.png new file mode 100644 index 0000000000..162453d152 Binary files /dev/null and b/app/assets/images/ditzy_logo_final.png differ diff --git a/app/assets/images/products/1.png b/app/assets/images/products/1.png new file mode 100644 index 0000000000..3260b1df39 Binary files /dev/null and b/app/assets/images/products/1.png differ diff --git a/app/assets/images/products/2.jpg b/app/assets/images/products/2.jpg new file mode 100644 index 0000000000..101b27f9c4 Binary files /dev/null and b/app/assets/images/products/2.jpg differ diff --git a/app/assets/javascripts/categories.coffee b/app/assets/javascripts/categories.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/categories.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/order_item.coffee b/app/assets/javascripts/order_item.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/order_item.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/orders.coffee b/app/assets/javascripts/orders.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/orders.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/products.coffee b/app/assets/javascripts/products.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/products.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/reviews.coffee b/app/assets/javascripts/reviews.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/reviews.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/users.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css deleted file mode 100644 index f9cd5b3483..0000000000 --- a/app/assets/stylesheets/application.css +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any styles - * defined in the other CSS/SCSS files in this directory. It is generally better to create a new - * file per style scope. - * - *= require_tree . - *= require_self - */ diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss new file mode 100644 index 0000000000..dd4376369a --- /dev/null +++ b/app/assets/stylesheets/application.css.scss @@ -0,0 +1,106 @@ +/** MAIN STYLING **/ + +@import "bootstrap-sprockets"; +@import "bootstrap"; + +* { + box-sizing: border-box; +} + +html { + font-family: 'Palanquin', sans-serif; + font-size: 1rem; +} + +main { + padding: 1rem; +} + +h1 { + color: #42bad3; /* ditzy bright blue */ + font-weight: lighter; + font-size: 2.5rem; + padding: 1rem; + margin: 0rem; +} + +h2 { + color: #d8563d; /* ditzy red */ + font-size: 1.5rem; + padding: 1rem; +} + +h3 { + color: #42bad3; /* ditzy bright blue */ + font-size: 1.5rem; + padding: 1rem; +} + +h4 { + + color: #3f52b8; /* ditzy dark blue */ + font-size: 1.5rem; + padding: 1rem; + +} + +span { + color: #3f52b8; /* ditzy dark blue */ +} + +a { + color: #3f52b8; /* ditzy dark blue */ +} + +p { + color: #3f52b8; /* ditzy dark blue */ + font-size: 1rem; + padding: 1rem; +} + +li { + color: #42bad3; /* ditzy bright blue */ + list-style-type: circle; + } + + +hr.dark-blue { + border: 0.1rem solid #3f52b8; + padding: 0rem; + margin: 0rem; +} + +hr.bright-blue { + border: 0.1rem solid #42bad3; + padding: 0rem; + margin: 0rem; +} + +.thumnbnail { + display: inline-block; + margin-left: auto; + margin-right: auto; +} + +.caption { + display: inline-block; + margin-left: auto; + margin-right: auto; +} + +.caption p { + font-size: 0.8rem; + margin: 0; +} + +.btn { + margin-left: 0.5rem; +} + +/** FONT AWESOME **/ + +.fa { + color: #3f52b8; /* ditzy dark blue */ + font-size: 3rem !important; +} + diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..ef1657f8c9 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/order_item.scss b/app/assets/stylesheets/order_item.scss new file mode 100644 index 0000000000..0f35cbeb67 --- /dev/null +++ b/app/assets/stylesheets/order_item.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrderItem controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..3b0428a94e --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..89e2e8db07 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..6ea2454d26 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..7bef9cf826 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..1efc835ccd --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e1b9..a769690606 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,18 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception -end + helper_method :current_user + + def current_user + @user ||= User.find_by(id: session[:user_id]) + end + + def index + redirect_to products_path + end + + # def logged_in? + # current_user != nil + # end + +end \ No newline at end of file diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..9b9dc8dfae --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,50 @@ +class CategoriesController < ApplicationController + + # we could use this to run a clickable list of categories that will enable folks to see what all the categories are. + def index + end + + def show_by_category + @merchant = User.find(params[:id]) + @products = Product.where(user_id: @merchant.id) + + render :categories_products + end + # if merchant && merchant.authenticate(params[:password]) + # merchant_session[:merchant_id] = merchant.id + # redirect_to root_url, :notice => "Merchanthas been logged in" + # else + # flash.now[:error] = "Invalid username or password." + # @title = "Merchant Signin" + # render "new" + # end + def new + @category = Category.new + end + + def create + # if category_create_params[:category][:name] == "" + # flash.now[:error] = "Please Enter a Catagory Name" + # raise + # end + @category = Category.new(category_create_params[:category]) + if @category.save + redirect_to dashboard_path(current_user.id) + else + # this sucks - place holder for the moment + render :bad_route + + # redirect_to dashboard_path(current_user.id) + end + end + + private + def category_create_params + # if category_create_params[:category][:name] == "" + # flash.now[:error] = "Please Enter a Catagory Name" + # raise + # end + params.permit(category: [:name]) + end +end + diff --git a/app/controllers/order_item_controller.rb b/app/controllers/order_item_controller.rb new file mode 100644 index 0000000000..69bf391454 --- /dev/null +++ b/app/controllers/order_item_controller.rb @@ -0,0 +1,39 @@ + +class OrderItemController < ApplicationController + + # route for /cart + def index + @order = Order.find(session[:order_id]) + @order_items = OrderItem.where(order_id: session[:order_id]).order("created_at asc") + + end + + def create + # quantity 1 is default, params[:format] is where the product id comes from + @order_item = OrderItem.new(order_id: session[:order_id], quantity: 1, product_id: params[:format]) + if @order_item.save + redirect_to cart_path + else + redirect_to products_path + end + end + + def update + @order_item = OrderItem.find(params[:id]) + @order_item.update(quantity: params[:order_item][:quantity]) + + redirect_to cart_path + end + + def destroy + @order_item = OrderItem.find(params[:id]) + @order_item.destroy + redirect_to cart_path + end + + def show + @order_item = OrderItem.find(params[:id]) + @order_product = Product.find(@order_item.product_id) + end + +end \ No newline at end of file diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..e0918d4edb --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,62 @@ +class OrdersController < ApplicationController + # confirmation page + def show + @order = Order.find(session[:order_id]) + @order_items = OrderItem.where(order_id: session[:order_id]).order("created_at asc") + render :show + end + + def create + @order = Order.find(session[:order_id]) + @order.expiration_on_cc = "#{params[:orders][:month]}-#{params[:orders][:year]}" + # @order.expiration_on_cc = params[:orders][:month] + + @order.status = "complete" + @order.name_on_cc = params[:orders][:name_on_cc] + @order.address = params[:orders][:address] + @order.security_on_cc = params[:orders][:security_on_cc] + # @order.expiration_on_cc = Date.strptime(params[:orders][:expiration_on_cc], '%m-%y') + @order.email = params[:orders][:email] + @order.zip = params[:orders][:zip] + @order.updated_at = Time.now + + # Send to the confirmation page aka orders#show + check_inventory(@order) + if @order.save + reduce_inventory(@order) + redirect_to complete_order_path + else + render :new + end + end + + def check_inventory(order) + order.order_items.each do |item| + if item.product.quantity < 0 + flash[:error] = "Sorry, this is out of stock!" + redirect_to product_path(params[:product_id]) + end + end + end + + def reduce_inventory(order) + order.order_items.each do |item| + item.product.quantity -= item.quantity + item.product.save + end + end + + # def complete_order + # # locate the order and "complete it" + # @order_details = OrderItem.where(session[:order_id]) + # clear_cart + + # #this is the confirmation page + # redirect_to :show + # end + + # def clear_cart + # OrderItem.destroy(@order_details) + # end +end + diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..477d5e9bb9 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,75 @@ +class ProductsController < ApplicationController + def index + @new_products = Product.where(visible: true).last(3) + @products = Product.where(visible: true).order(id: :asc) + @categories = Category.all + render :index + end + + def show + # controller action: if @user_id (show "list" view for user)/if category (show "list" view by category) + @product = Product.where(visible: true).find(params[:id]) + @reviews = Review.where(product_id: @product.id) + @merchant = User.joins(:products).where("products.id": params[:id]) + render :product_details + end + + def show_by_merchant + @merchant = User.find(params[:user_id]) + @products = Product.where(visible: true).where(user_id: @merchant.id) + + render :users_products + end + + def show_by_category + @category = Category.find(params[:category_id]) + @products = Category.find(params[:category_id]).products.where(visible: true) + render :categories_products + end + + def new + # user = curent user here. + @user = User.find(params[:id]) + @product = Product.new + render :create_product + end + + def create + @product = Product.create(product_create_params[:product]) + redirect_to dashboard_path(current_user.id) + end + + def edit + @product = Product.find(params[:product_id]) + # @categories = Product.find(params[:product_id]).categories + @categories = Category.all + render :edit + end + + def update + @product = Product.find(params[:id]) + @product.update(product_update_params[:product]) + redirect_to dashboard_path(current_user.id) + end + + def destroy + killed_record = Product.destroy(params[:id]) + if params[:id] = true + redirect_to products_show_path(@current_user.id) + end + end + + def show_merchant_store + @merchant = User.find(params[:id]) + @merchant_products = Product.where(user_id: @merchant.id) + end + + private + def product_create_params + params.permit(product: [:name, :user_id, :price_in_dollars, :visible, :quantity, :description, :image_url, :category_ids => []]) + end + + def product_update_params + params.permit(product: [:name, :user_id, :price_in_dollars, :visible, :quantity, :description, :image_url, :category_ids => []]) + end +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..78af4305f2 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,49 @@ +class ReviewsController < ApplicationController + #might only need index show delete + def index #show all + #@review = Review.where(product_id: params[:product_id]).first + + end + + def show # show one all display a view that has already been created + @review = Review.all.where(params[:product_id]) + render :new + end + + def new + @review = Review.new + @product = Product.find(params[:product_id]) + render :new + end + + def create + @reviewparams = review_params + @review = Review.new(review_params) + if @review.save + redirect_to product_path(@review.product_id) + else + @review = Review.new + @product = Product.find(params[:product_id]) + render :new + end + + end + + def edit + @review = Reviews.find(params[:id]) + render :new + end + + def update + end + + def delete + end +end + + +private + + def review_params + params.require(:review).permit(:review_text, :rating, :product_id) + end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..32fad17edb --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,32 @@ +class SessionsController < ApplicationController + + + # login for registered users + def create + current_user = User.log_in(params[:session_data][:email], params[:session_data][:password]) + if current_user + session[:user_id] = current_user.id + @order = Order.create + @order.status = "pending" + session[:order_id] = @order.id + redirect_to products_path + else + redirect_to products_path + end + end + + #login for guest users + def create_order + # brand new cart object + @order = Order.create + # this is the cart object + session[:order_id] = @order.id + redirect_to products_path + end + + def destroy + session.delete(:user_id) + redirect_to products_path + end + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..90b25c0068 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,64 @@ +class UsersController < ApplicationController + # commenting this out because it breaks things and Rowan is not here to explain it + # before_action :require_login, except: [:new, :create, :bad_route] + + def new + @new_user = User.new + end + + def create + @new_user = User.new(user_create_params[:user]) + + if @new_user.save + redirect_to new_session_path + else + render :new + end + end + + def show_merchant + @merchant_order_items = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).order(order_id: :asc) + @total_revenue = OrderItem.joins(:product).where("products.user_id": params[:id]).sum("products.price_in_dollars") + @completed_orders = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "complete").count() + @pending_orders = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "pending").count() + @completed_orders_subtotal = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "complete").sum("products.price_in_dollars") + @pending_orders_subtotal = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "pending").sum("products.price_in_dollars") + end + + def show + @merchant = User.find(params[:id]) + @products = Product.where(user_id: @merchant.id) + @category ||= Category.new + @categories = Category.all + @product = Product.new + + render "users/merchant" + end + + def update_order_item + @item = OrderItem.find(params[:id]) + @item.update(update_order_item_params[:order_item]) + redirect_to orders_dashboard_path(current_user.id) + end + + + def show_merchant_order + @order = Order.find(params[:id]) + end + + private + + def require_login + unless current_user && current_user.id == params[:id].to_i + render :bad_route + end + end + + def user_create_params + params.permit(user: [:user_name, :email, :password, :password_confirmation]) + end + + def update_order_item_params + params.permit(order_item: [:shipped]) + end +end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000000..e06f31554c --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/helpers/order_item_helper.rb b/app/helpers/order_item_helper.rb new file mode 100644 index 0000000000..1b37f3b1bb --- /dev/null +++ b/app/helpers/order_item_helper.rb @@ -0,0 +1,2 @@ +module OrderItemHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000000..2310a240d7 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..74ebfdff08 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,8 @@ +class Category < ActiveRecord::Base + + has_and_belongs_to_many :products + + validates :name, presence: true + validates :name, uniqueness: true + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..606ceaa9e5 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,3 @@ +class Order < ActiveRecord::Base + has_many :order_items +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..d9ab6b790c --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,5 @@ +class OrderItem < ActiveRecord::Base + belongs_to :order + belongs_to :product + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..7d9951a831 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,10 @@ +class Product < ActiveRecord::Base + belongs_to :user + has_many :reviews + has_and_belongs_to_many :categories + + validates :name, presence: true + validates_numericality_of :quantity, :only_integer => true, :greater_than_or_equal_to => 1 + validates_numericality_of :price_in_dollars, :greater_than_or_equal_to => 1 + +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..05a8803e65 --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,6 @@ +class Review < ActiveRecord::Base + belongs_to :product + + validates :review_text, presence: true + validates :rating, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..d04ffd9c8d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,18 @@ +class User < ActiveRecord::Base + + # attr_accessor :user_name, :password, :password_confirmation + has_many :products + has_many :orders + has_many :reviews , :through => :product + has_many :order_items , :through => :order + + validates :user_name, presence: true + validates :email, presence: true, uniqueness: true + + has_secure_password + + def self.log_in(email, password) + somebody = find_by(email: email) + somebody && somebody.authenticate(password) + end +end diff --git a/app/views/categories/bad_route.html.erb b/app/views/categories/bad_route.html.erb new file mode 100644 index 0000000000..3bf412e37e --- /dev/null +++ b/app/views/categories/bad_route.html.erb @@ -0,0 +1,9 @@ +<% if @category.errors.any? %> +
Total: <%= number_to_currency(@total) %>
+ +<%= link_to"Give Us Money!", checkout_path, :class => "btn btn-primary btn-md" %> + + +<%= link_to "Shop Some More", products_path, :class => "btn btn-primary btn-md" %> diff --git a/app/views/order_item/show.html.erb b/app/views/order_item/show.html.erb new file mode 100644 index 0000000000..c2973b1880 --- /dev/null +++ b/app/views/order_item/show.html.erb @@ -0,0 +1,17 @@ +Order ID | +Product | +Quantity | +Shipping Status | +
---|---|---|---|
<%= @order_item.order_id %> | +<%= @order_product.name %> | +<%= @order_item.quantity %> | +<%= @order_item.shipped %> | +
+ Name on credit card: <%= f.text_field :name_on_cc %>
+ Credit Card Number: <%= f.text_field :credit_card_number %>
+ Address: <%= f.text_field :address %>
+ Zip: <%= f.text_field :zip %>
+ Security Code: <%= f.text_field :security_on_cc %>
+ Expiration:
+ <%= f.select :month, 1..12 %>
+ <%= f.select :year, Date.today.year.. 8.years.from_now.year %>
+ Email: <%= f.text_field :email %>
+ <% status = "pending" %>
+ <% f.hidden_field :status => status %>
+ <%= button_tag(type: 'submit', class: "btn btn-primary btn-md", action: "create") do %>
+ Submit
+ <% end %>
+
+ Total Charges: <%= number_to_currency(@total) %> +
\ No newline at end of file diff --git a/app/views/products/categories_products.html.erb b/app/views/products/categories_products.html.erb new file mode 100644 index 0000000000..1b926375ca --- /dev/null +++ b/app/views/products/categories_products.html.erb @@ -0,0 +1,12 @@ +
+ <%=image_tag("#{product.image_url}")%>
+ Product ID: <%= product.id %>
+ <%= link_to product.name, product_path(product.id) %>
+ <%= product.price_in_dollars %>
+
+ Product ID: <%= product.id %>
+ <%= link_to product.name, user_product_path(product.user_id, product.id) %>
+ <%= product.price %>
+
+ Price: <%= number_to_currency(@product.price_in_dollars) %> + Quantity In Stock: <%= @product.quantity %> + Description: <%= @product.description %> + Sold by: <%= link_to @merchant.first.user_name, merchant_store_path(@merchant.first.id) %> +
+ + <%=link_to "BUY NOW", cart_path(@product.id), method: :post, :class => "btn btn-primary btn-md" %> + ++ Rating: <%= review.rating %> + Review: <%= review.review_text %> +
+ <%end%> + + <% if !current_user || current_user.id != @product.user_id %> + <%=link_to "Review this product", new_product_review_path(@product.id), :class => "btn btn-primary btn-md"%> + <% end %> ++<% @merchant_products.each do |product| %> + <%=image_tag(("#{product.image_url}"), :class => 'img-responsive')%> + Product: <%=product.name%> + Price: <%=product.price_in_dollars%> + Description: <%=product.description%> +<% end %> +
+ +<%= link_to "Shop Some More", products_path, :class => "btn btn-primary btn-md" %> diff --git a/app/views/products/users_products.html.erb b/app/views/products/users_products.html.erb new file mode 100644 index 0000000000..4798472d15 --- /dev/null +++ b/app/views/products/users_products.html.erb @@ -0,0 +1,17 @@ +
+ <%=image_tag("#{product.image_url}")%>
+ Product ID: <%= product.id %>
+ <%= link_to product.name, product_path(product.id) %>
+ <%= product.price_in_dollars %>
+
+ <%= f.label :review_text %>
+ <%= f.text_area :review_text %>
+
+ <%=f.label :rating%>
+ <%=f.select :rating, [1,2,3,4,5] %>
+ <%= f.hidden_field :product_id, :value => params[:product_id] %>
+
Please use your back button and try again.
+ +<% if @category.errors.any? %> ++ Product + | ++ Visibility + | ++ Make Changes + | + <% @products.each do |product| %> +|
---|---|---|---|
<%= link_to product.name, product_path(product.id) %> | + <% if product.visible == true %> +<%= "Visible to buyers" %> | + <% else %> +<%= "Not visible to buyers" %> | + <% end %> +<%= button_to "Edit", edit_product_path, :method => :get, params: {product_id: product.id} %> | +
+ Order Product + | ++ Order Item Number + | ++ Order Number + | ++ Order Time + | ++ Order Status + | ++ Shipping Status + | +
---|---|---|---|---|---|
+ <%= link_to data.product.name, order_item_path(data.order.id) %> + | ++ <%= data.id %> + | ++ <%= link_to data.order.id, merchant_order_path(data.order.id) %> + | ++ <%= data.order.created_at %> + | ++ <%= data.order.status %> + | ++ <%= form_for data do |f| %> + <%= f.label :mark_as_shipped %> + <%= f.radio_button :shipped, :true, :checked => :true %> + <%= f.submit %> + <% end %> + | + <% end %> +
+ Order Product + | ++ Order Item Number + | ++ Order Number + | ++ Order Time + | ++ Quantity + | ++ Sale Total + | ++ Order Status + | +
---|---|---|---|---|---|---|
+ <%= link_to data.product.name, order_item_path(data.id) %> + | ++ <%= data.order.id %> + | ++ <%= data.id %> + | ++ <%= data.order.created_at %> + | ++ <%= data.quantity %> + | ++ <%= data.product.price_in_dollars * (data.quantity) %> + | ++ <%= data.order.status %> + | + <% end %> +
+ <%= number_to_currency(@total_revenue) %> +
++ Number of Orders: <%= @completed_orders %> + Subtotal: <%= number_to_currency(@completed_orders_subtotal) %> +
++ Number of Orders: <%= @pending_orders %> + Subtotal: <%= number_to_currency(@pending_orders_subtotal) %> +
+ + + + diff --git a/app/views/users/show_merchant_order.html.erb b/app/views/users/show_merchant_order.html.erb new file mode 100644 index 0000000000..4f0bb3c2f3 --- /dev/null +++ b/app/views/users/show_merchant_order.html.erb @@ -0,0 +1,16 @@ +