<%= flash[:error] %>
+diff --git a/.gitignore b/.gitignore index dcc5b36..416f2fc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ /yarn-error.log .byebug_history +.DS_Store diff --git a/Gemfile b/Gemfile index d35de94..fcd8638 100644 --- a/Gemfile +++ b/Gemfile @@ -6,10 +6,18 @@ git_source(:github) do |repo_name| end + +gem 'bootstrap-sass' + +gem 'simple_form' +gem 'geocoder' +gem 'carrierwave', '~> 1.0' + +gem 'stripe' +gem 'cloudinary' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.4' -# Use sqlite3 as the database for Active Record -gem 'sqlite3' + # Use Puma as the app server gem 'puma', '~> 3.7' # Use SCSS for stylesheets @@ -18,7 +26,7 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby - +gem 'devise' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks @@ -39,6 +47,8 @@ group :development, :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '~> 2.13' gem 'selenium-webdriver' + # Use sqlite3 as the database for Active Record + gem 'sqlite3' end group :development do @@ -46,5 +56,8 @@ group :development do gem 'web-console', '>= 3.3.0' end +group :production do + gem 'pg' +end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock index 1500572..452197a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,7 +41,15 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) arel (8.0.0) + autoprefixer-rails (7.1.5) + execjs + aws_cf_signer (0.1.3) + bcrypt (3.1.11) + bcrypt (3.1.11-x64-mingw32) bindex (0.5.0) + bootstrap-sass (3.3.7) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.3) byebug (9.1.0) capybara (2.15.4) @@ -51,8 +59,15 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + carrierwave (1.2.1) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) + mime-types (>= 1.16) childprocess (0.8.0) ffi (~> 1.0, >= 1.0.11) + cloudinary (1.8.1) + aws_cf_signer + rest-client coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -62,11 +77,25 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.0.5) crass (1.0.2) + devise (4.3.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.2) + responders + warden (~> 1.2.3) + domain_name (0.5.20170404) + unf (>= 0.0.5, < 1.0.0) erubi (1.7.0) execjs (2.7.0) + faraday (0.13.1) + multipart-post (>= 1.2, < 3) + ffi (1.9.18) ffi (1.9.18-x64-mingw32) + geocoder (1.4.4) globalid (0.4.0) activesupport (>= 4.2.0) + http-cookie (1.0.3) + domain_name (~> 0.5) i18n (0.9.0) concurrent-ruby (~> 1.0) jbuilder (2.7.0) @@ -85,9 +114,16 @@ GEM mini_portile2 (2.3.0) minitest (5.10.3) multi_json (1.12.2) + multipart-post (2.0.0) + netrc (0.11.0) nio4r (2.1.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) nokogiri (1.8.1-x64-mingw32) mini_portile2 (~> 2.3.0) + orm_adapter (0.5.0) + pg (0.21.0) + pg (0.21.0-x64-mingw32) public_suffix (3.0.0) puma (3.10.0) rack (2.0.3) @@ -120,6 +156,18 @@ GEM rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) + rest-client (2.0.2) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) + rest-client (2.0.2-x64-mingw32) + ffi (~> 1.9) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) rubyzip (1.2.1) sass (3.5.2) sass-listen (~> 4.0.0) @@ -135,6 +183,9 @@ GEM selenium-webdriver (3.6.0) childprocess (~> 0.5) rubyzip (~> 1.0) + simple_form (3.5.0) + actionpack (> 4, < 5.2) + activemodel (> 4, < 5.2) sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -142,7 +193,10 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + sqlite3 (1.3.13) sqlite3 (1.3.13-x64-mingw32) + stripe (3.6.0) + faraday (~> 0.10) thor (0.20.0) thread_safe (0.3.6) tilt (2.0.8) @@ -155,6 +209,12 @@ GEM tzinfo (>= 1.0.0) uglifier (3.2.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.4) + unf_ext (0.0.7.4-x64-mingw32) + warden (1.2.7) + rack (>= 1.0) web-console (3.5.1) actionview (>= 5.0) activemodel (>= 5.0) @@ -167,22 +227,31 @@ GEM nokogiri (~> 1.3) PLATFORMS + ruby x64-mingw32 DEPENDENCIES + bootstrap-sass byebug capybara (~> 2.13) + carrierwave (~> 1.0) + cloudinary coffee-rails (~> 4.2) + devise + geocoder jbuilder (~> 2.5) + pg puma (~> 3.7) rails (~> 5.1.4) sass-rails (~> 5.0) selenium-webdriver + simple_form sqlite3 + stripe turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) BUNDLED WITH - 1.16.0.pre.2 + 1.16.0.pre.3 diff --git a/OnlineStore b/OnlineStore new file mode 160000 index 0000000..3faa00c --- /dev/null +++ b/OnlineStore @@ -0,0 +1 @@ +Subproject commit 3faa00c3be93e801c7b852d3961ad96f3d5303b4 diff --git a/README.md b/README.md index 7db80e4..65037e4 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,77 @@ # README +Art House -This README would normally document whatever steps are necessary to get the -application up and running. +A one-sided online store that provides users with the ability to view, inspect and +purchase art posted by various potential sellers. -Things you may want to cover: +Tests -* Ruby version +There are several tests within the test.rb file .e.g. -* System dependencies +require 'test_helper' -* Configuration +class CustomersControllerTest < ActionDispatch::IntegrationTest + setup do + @customer = customers(:one) + end -* Database creation + test "should get index" do + get customers_url + assert_response :success + end -* Database initialization + test "should get new" do + get new_customer_url + assert_response :success + end -* How to run the test suite + test "should create customer" do + assert_difference('Customer.count') do + post customers_url, params: { customer: { email: @customer.email, login: @customer.login, name: @customer.name } } + end -* Services (job queues, cache servers, search engines, etc.) + assert_redirected_to customer_url(Customer.last) + end -* Deployment instructions + test "should show customer" do + get customer_url(@customer) + assert_response :success + end -* ... + This allowed for extensive debugging and resolution of conflicts within the source code. + + + + +Built With + +Ruby on Rails - The web framework used +Ruby Gems - Dependency Management +Stripe - To generate payments. +Contributing + + +Versioning + +We use Github as our primary source of version control. https://github.com/HackStoreCode/OnlineStore + +Authors + +Gregory Parkes-skelly +Alex Pham +Ali Ansari + +License + +This project is licensed under the MIT License - see the LICENSE.md file for details + +Acknowledgments + +Hat tip to anyone who's code was used +Inspiration +etc + + +* ERD + * + diff --git a/app/assets/javascripts/charges.coffee b/app/assets/javascripts/charges.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/charges.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/customers.coffee b/app/assets/javascripts/customers.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/customers.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/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/home.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_groups.coffee b/app/assets/javascripts/order_groups.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/order_groups.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 0000000..24f83d1 --- /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/payments.coffee b/app/assets/javascripts/payments.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/payments.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 0000000..24f83d1 --- /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/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 0000000..24f83d1 --- /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.scss similarity index 84% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index d05ea0f..71e7b58 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -10,6 +10,16 @@ * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * + *= require_tree . *= require_self */ +@import "bootstrap-sprockets"; +@import "bootstrap"; + +html, body { + max-width: 100%; + overflow-x: hidden; +.container {margin: 4% + +} diff --git a/app/assets/stylesheets/charges.scss b/app/assets/stylesheets/charges.scss new file mode 100644 index 0000000..3ef2d76 --- /dev/null +++ b/app/assets/stylesheets/charges.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the charges 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/customers.scss b/app/assets/stylesheets/customers.scss new file mode 100644 index 0000000..892b0ad --- /dev/null +++ b/app/assets/stylesheets/customers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the customers 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/home.css b/app/assets/stylesheets/home.css new file mode 100644 index 0000000..8b9461e --- /dev/null +++ b/app/assets/stylesheets/home.css @@ -0,0 +1,5 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.body {background-image: url(/assets/images/bi.jpg);} diff --git a/app/assets/stylesheets/order_groups.scss b/app/assets/stylesheets/order_groups.scss new file mode 100644 index 0000000..7fc32c9 --- /dev/null +++ b/app/assets/stylesheets/order_groups.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrderGroups 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 0000000..7415069 --- /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/payments.scss b/app/assets/stylesheets/payments.scss new file mode 100644 index 0000000..09456e2 --- /dev/null +++ b/app/assets/stylesheets/payments.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Payments 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 0000000..12a047c --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,107 @@ +// 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/ +@import url('https://fonts.googleapis.com/css?family=Raleway:100,400,700'); + +// Variables +$font: 'Raleway', sans-serif; +$white: #fff; +$black: #212129; +$max: 100%; + +* { + margin: 0; + padding: 0; + font-family: $font; + text-decoration: none; + outline: none; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -ms-box-sizing: border-box; + -o-box-sizing: border-box; + box-sizing: border-box; +} + +img { + max-width: $max; +} + +html, body { + height: 100vh; +} + +body { + background: $white; +} + +.container { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + .flex-block { + margin: 10px; + // border: 1px solid #000; + border-radius: 5px; + box-shadow: 0px 0px 8px 1px $black; + padding: 10px; + a { + display: block; + background: $white; + color: $white; + text-align: center; + padding: 5px; + margin-top: 10px; + text-transform: uppercase; + letter-spacing: 0.1em; + border-radius: 3px; + transition: 300ms; + &:hover { + box-shadow: 0px 0px 8px 1px $black; + transition: 300ms; + } + } + } +} + +@media screen and(max-width: 1020px) { + .container { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + flex-wrap: wrap; + .flex-block { + position: relative; + max-width: 400px; + } + } +} + +@media screen and(max-width: 858px) { + .container { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + flex-wrap: wrap; + .flex-block { + position: relative; + max-width: 350px; + } + } +} + +@media screen and(max-width: 758px) { + .container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + flex-wrap: wrap; + .flex-block { + position: relative; + max-width: 100%; + } + } +} diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..6045188 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,84 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +th { + padding-bottom: 5px; +} + +td { + padding: 0 5px 7px; +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} + +label { + display: block; +} diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000..1efc835 --- /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/charges_controller.rb b/app/controllers/charges_controller.rb new file mode 100644 index 0000000..264f666 --- /dev/null +++ b/app/controllers/charges_controller.rb @@ -0,0 +1,27 @@ +class ChargesController < ApplicationController + +def new +end + +def create + # Amount in cents + @amount = 500 + + customer = Stripe::Customer.create( + :email => params[:stripeEmail], + :source => params[:stripeToken] + ) + + charge = Stripe::Charge.create( + :customer => customer.id, + :amount => @amount, + :description => 'Rails Stripe customer', + :currency => 'usd' + ) + +rescue Stripe::CardError => e + flash[:error] = e.message + redirect_to new_charge_path +end + +end diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb new file mode 100644 index 0000000..a07c656 --- /dev/null +++ b/app/controllers/customers_controller.rb @@ -0,0 +1,74 @@ +class CustomersController < ApplicationController + before_action :set_customer, only: [:show, :edit, :update, :destroy] + + # GET /customers + # GET /customers.json + def index + @customers = Customer.all + end + + # GET /customers/1 + # GET /customers/1.json + def show + end + + # GET /customers/new + def new + @customer = Customer.new + end + + # GET /customers/1/edit + def edit + end + + # POST /customers + # POST /customers.json + def create + @customer = Customer.new(customer_params) + + respond_to do |format| + if @customer.save + format.html { redirect_to @customer, notice: 'Customer was successfully created.' } + format.json { render :show, status: :created, location: @customer } + else + format.html { render :new } + format.json { render json: @customer.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /customers/1 + # PATCH/PUT /customers/1.json + def update + respond_to do |format| + if @customer.update(customer_params) + format.html { redirect_to @customer, notice: 'Customer was successfully updated.' } + format.json { render :show, status: :ok, location: @customer } + else + format.html { render :edit } + format.json { render json: @customer.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /customers/1 + # DELETE /customers/1.json + def destroy + @customer.destroy + respond_to do |format| + format.html { redirect_to customers_url, notice: 'Customer was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_customer + @customer = Customer.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def customer_params + params.require(:customer).permit(:name, :email, :login) + end +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..95f2992 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,4 @@ +class HomeController < ApplicationController + def index + end +end diff --git a/app/controllers/order_groups_controller.rb b/app/controllers/order_groups_controller.rb new file mode 100644 index 0000000..3f3463e --- /dev/null +++ b/app/controllers/order_groups_controller.rb @@ -0,0 +1,74 @@ +class OrderGroupsController < ApplicationController + before_action :set_order_group, only: [:show, :edit, :update, :destroy] + + # GET /order_groups + # GET /order_groups.json + def index + @order_groups = OrderGroup.all + end + + # GET /order_groups/1 + # GET /order_groups/1.json + def show + end + + # GET /order_groups/new + def new + @order_group = OrderGroup.new + end + + # GET /order_groups/1/edit + def edit + end + + # POST /order_groups + # POST /order_groups.json + def create + @order_group = OrderGroup.new(order_group_params) + + respond_to do |format| + if @order_group.save + format.html { redirect_to @order_group, notice: 'Order group was successfully created.' } + format.json { render :show, status: :created, location: @order_group } + else + format.html { render :new } + format.json { render json: @order_group.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /order_groups/1 + # PATCH/PUT /order_groups/1.json + def update + respond_to do |format| + if @order_group.update(order_group_params) + format.html { redirect_to @order_group, notice: 'Order group was successfully updated.' } + format.json { render :show, status: :ok, location: @order_group } + else + format.html { render :edit } + format.json { render json: @order_group.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /order_groups/1 + # DELETE /order_groups/1.json + def destroy + @order_group.destroy + respond_to do |format| + format.html { redirect_to order_groups_url, notice: 'Order group was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_order_group + @order_group = OrderGroup.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def order_group_params + params.require(:order_group).permit(:order_date, :user_id) + end +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000..5659462 --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,74 @@ +class OrdersController < ApplicationController + before_action :set_order, only: [:show, :edit, :update, :destroy] + + # GET /orders + # GET /orders.json + def index + @orders = Order.all + end + + # GET /orders/1 + # GET /orders/1.json + def show + end + + # GET /orders/new + def new + @order = Order.new + end + + # GET /orders/1/edit + def edit + end + + # POST /orders + # POST /orders.json + def create + @order = Order.new(order_params) + + respond_to do |format| + if @order.save + format.html { redirect_to @order, notice: 'Order was successfully created.' } + format.json { render :show, status: :created, location: @order } + else + format.html { render :new } + format.json { render json: @order.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /orders/1 + # PATCH/PUT /orders/1.json + def update + respond_to do |format| + if @order.update(order_params) + format.html { redirect_to @order, notice: 'Order was successfully updated.' } + format.json { render :show, status: :ok, location: @order } + else + format.html { render :edit } + format.json { render json: @order.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /orders/1 + # DELETE /orders/1.json + def destroy + @order.destroy + respond_to do |format| + format.html { redirect_to orders_url, notice: 'Order was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_order + @order = Order.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def order_params + params.require(:order).permit(:order_date, :product_id, :ordergroup_id) + end +end diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb new file mode 100644 index 0000000..22c9d59 --- /dev/null +++ b/app/controllers/payments_controller.rb @@ -0,0 +1,74 @@ +class PaymentsController < ApplicationController + before_action :set_payment, only: [:show, :edit, :update, :destroy] + + # GET /payments + # GET /payments.json + def index + @payments = Payment.all + end + + # GET /payments/1 + # GET /payments/1.json + def show + end + + # GET /payments/new + def new + @payment = Payment.new + end + + # GET /payments/1/edit + def edit + end + + # POST /payments + # POST /payments.json + def create + @payment = Payment.new(payment_params) + + respond_to do |format| + if @payment.save + format.html { redirect_to @payment, notice: 'Payment was successfully created.' } + format.json { render :show, status: :created, location: @payment } + else + format.html { render :new } + format.json { render json: @payment.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /payments/1 + # PATCH/PUT /payments/1.json + def update + respond_to do |format| + if @payment.update(payment_params) + format.html { redirect_to @payment, notice: 'Payment was successfully updated.' } + format.json { render :show, status: :ok, location: @payment } + else + format.html { render :edit } + format.json { render json: @payment.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /payments/1 + # DELETE /payments/1.json + def destroy + @payment.destroy + respond_to do |format| + format.html { redirect_to payments_url, notice: 'Payment was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_payment + @payment = Payment.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def payment_params + params.require(:payment).permit(:payment_date, :description, :total_amount, :ordergroup_id) + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..0238376 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,80 @@ +class ProductsController < ApplicationController + before_action :set_product, only: [:show, :edit, :update, :destroy] + + # GET /products + # GET /products.json + def index + @products = Product.all + end + + # GET /products/1 + # GET /products/1.json + def show + end + + # GET /products/new + def new + @product = Product.new + end + + # GET /products/1/edit + def edit + end + + # POST /products + # POST /products.json + def create + @product = Product.new(product_params) + + @product.user_id = current_user.id + + respond_to do |format| + if @product.save + format.html { redirect_to @product, notice: 'Product was successfully created.' } + format.json { render :show, status: :created, location: @product } + else + format.html { render :new } + format.json { render json: @product.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /products/1 + # PATCH/PUT /products/1.json + def update + respond_to do |format| + if @product.update(product_params) + format.html { redirect_to @product, notice: 'Product was successfully updated.' } + format.json { render :show, status: :ok, location: @product } + else + format.html { render :edit } + format.json { render json: @product.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /products/1 + # DELETE /products/1.json + def destroy + @product.destroy + respond_to do |format| + format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_product + @product = Product.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def product_params + + params.require(:product).permit(:name, :price, :description, :available, :image) + + params.require(:product).permit(:description, :price, :image, :user_id) + + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..3544e08 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,74 @@ +class UsersController < ApplicationController + before_action :set_user, only: [:show, :edit, :update, :destroy] + + # GET /users + # GET /users.json + def index + @users = User.all + end + + # GET /users/1 + # GET /users/1.json + def show + end + + # GET /users/new + def new + @user = User.new + end + + # GET /users/1/edit + def edit + end + + # POST /users + # POST /users.json + def create + @user = User.new(user_params) + + respond_to do |format| + if @user.save + format.html { redirect_to @user, notice: 'User was successfully created.' } + format.json { render :show, status: :created, location: @user } + else + format.html { render :new } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /users/1 + # PATCH/PUT /users/1.json + def update + respond_to do |format| + if @user.update(user_params) + format.html { redirect_to @user, notice: 'User was successfully updated.' } + format.json { render :show, status: :ok, location: @user } + else + format.html { render :edit } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /users/1 + # DELETE /users/1.json + def destroy + @user.destroy + respond_to do |format| + format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_user + @user = User.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def user_params + params.require(:user).permit(:name, :email, :login) + end +end diff --git a/app/helpers/charges_helper.rb b/app/helpers/charges_helper.rb new file mode 100644 index 0000000..414ee90 --- /dev/null +++ b/app/helpers/charges_helper.rb @@ -0,0 +1,2 @@ +module ChargesHelper +end diff --git a/app/helpers/customers_helper.rb b/app/helpers/customers_helper.rb new file mode 100644 index 0000000..a07ce29 --- /dev/null +++ b/app/helpers/customers_helper.rb @@ -0,0 +1,2 @@ +module CustomersHelper +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/helpers/order_groups_helper.rb b/app/helpers/order_groups_helper.rb new file mode 100644 index 0000000..68e9e15 --- /dev/null +++ b/app/helpers/order_groups_helper.rb @@ -0,0 +1,2 @@ +module OrderGroupsHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000..443227f --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/payments_helper.rb b/app/helpers/payments_helper.rb new file mode 100644 index 0000000..c1b884f --- /dev/null +++ b/app/helpers/payments_helper.rb @@ -0,0 +1,2 @@ +module PaymentsHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000..ab5c42b --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb new file mode 100644 index 0000000..5710e02 --- /dev/null +++ b/app/mailers/user_mailer.rb @@ -0,0 +1,9 @@ +class UserMailer < ApplicationMailer + default from: 'notifications@example.com' + + def welcome_email(user) + @user = user + @url = 'http//:example.com/login' + mail(to: @user.email, subject: 'Welcome to my Awesome Site ') + end +end diff --git a/app/mailers/welcome_email.html.erb b/app/mailers/welcome_email.html.erb new file mode 100644 index 0000000..a42058a --- /dev/null +++ b/app/mailers/welcome_email.html.erb @@ -0,0 +1,23 @@ + + +
+ + + + +
+ You have successfully signed up to example.com,your username is:
+ <%= @user.login %>.
+
+ To login to the site, just follow this link: + <%= @url %>. +
+ +Thanks for joining and have a great day!
+ + + diff --git a/app/models/customer.rb b/app/models/customer.rb new file mode 100644 index 0000000..0b52773 --- /dev/null +++ b/app/models/customer.rb @@ -0,0 +1,2 @@ +class Customer < ApplicationRecord +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000..b494acc --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,4 @@ +class Order < ApplicationRecord + belongs_to :product + belongs_to :ordergroup +end diff --git a/app/models/order_group.rb b/app/models/order_group.rb new file mode 100644 index 0000000..2369624 --- /dev/null +++ b/app/models/order_group.rb @@ -0,0 +1,3 @@ +class OrderGroup < ApplicationRecord + belongs_to :user +end diff --git a/app/models/payment.rb b/app/models/payment.rb new file mode 100644 index 0000000..5ccb3fa --- /dev/null +++ b/app/models/payment.rb @@ -0,0 +1,3 @@ +class Payment < ApplicationRecord + belongs_to :ordergroup +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000..ba5a4ab --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,3 @@ +class Product < ApplicationRecord + mount_uploader :image, ProductImageUploader +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..989875d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,7 @@ +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable + has_many :products +end diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb new file mode 100644 index 0000000..836a047 --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,49 @@ +class ImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_whitelist + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/uploaders/product_image_uploader.rb b/app/uploaders/product_image_uploader.rb new file mode 100644 index 0000000..ce37d4e --- /dev/null +++ b/app/uploaders/product_image_uploader.rb @@ -0,0 +1,49 @@ +class ProductImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_whitelist + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/charges/create.html.erb b/app/views/charges/create.html.erb new file mode 100644 index 0000000..7d9db94 --- /dev/null +++ b/app/views/charges/create.html.erb @@ -0,0 +1 @@ +<%= flash[:error] %>
+<%= notice %>
+ +| Name | +Login | ++ | |||
|---|---|---|---|---|---|
| <%= customer.name %> | +<%= customer.email %> | +<%= customer.login %> | +<%= link_to 'Show', customer %> | +<%= link_to 'Edit', edit_customer_path(customer) %> | +<%= link_to 'Destroy', customer, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Name: + <%= @customer.name %> +
+ ++ Email: + <%= @customer.email %> +
+ ++ Login: + <%= @customer.login %> +
+ +<%= link_to 'Edit', edit_customer_path(@customer) %> | +<%= link_to 'Back', customers_path %> diff --git a/app/views/customers/show.json.jbuilder b/app/views/customers/show.json.jbuilder new file mode 100644 index 0000000..14cfc83 --- /dev/null +++ b/app/views/customers/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "customers/customer", customer: @customer diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 0000000..949b172 --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,16 @@ +Welcome <%= @email %>!
+ +You can confirm your account email through the link below:
+ +<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>
diff --git a/app/views/devise/mailer/email_changed.html.erb b/app/views/devise/mailer/email_changed.html.erb new file mode 100644 index 0000000..32f4ba8 --- /dev/null +++ b/app/views/devise/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +Hello <%= @email %>!
+ +<% if @resource.try(:unconfirmed_email?) %> +We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.
+<% else %> +We're contacting you to notify you that your email has been changed to <%= @resource.email %>.
+<% end %> diff --git a/app/views/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 0000000..b41daf4 --- /dev/null +++ b/app/views/devise/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +Hello <%= @resource.email %>!
+ +We're contacting you to notify you that your password has been changed.
diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..f667dc1 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +Hello <%= @resource.email %>!
+ +Someone has requested a link to change your password. You can do this through the link below.
+ +<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>
+ +If you didn't request this, please ignore this email.
+Your password won't change until you access the link above and create a new one.
diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..41e148b --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +Hello <%= @resource.email %>!
+ +Your account has been locked due to an excessive number of unsuccessful sign in attempts.
+ +Click the link below to unlock your account:
+ +<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>
diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 0000000..a938930 --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,19 @@ +Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + + <%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %> + <%= f.input :password_confirmation, required: false %> + <%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %> +Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>
+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 0000000..34b4279 --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,17 @@ ++ + + + +
+This is a simple front store app
+Use the menu to access Gallery or put your art to show
++ + + SignUp +
<%= notice %>
+<%= alert %>
+ + +