diff --git a/.idea/amazezonewebsite.iml b/.idea/amazezonewebsite.iml index c6ac18b..d7cc791 100644 --- a/.idea/amazezonewebsite.iml +++ b/.idea/amazezonewebsite.iml @@ -26,85 +26,110 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -164,4 +189,103 @@ + + + file://$MODULE_DIR$/app + + + file://$MODULE_DIR$/app/assets + + + file://$MODULE_DIR$/app/channels + + + file://$MODULE_DIR$/app/controllers + + + file://$MODULE_DIR$/app/helpers + + + file://$MODULE_DIR$/app/mailers + + + file://$MODULE_DIR$/app/models + + + file://$MODULE_DIR$/app/views + + + file://$MODULE_DIR$/config + + + file://$MODULE_DIR$/config/cable.yml + + + file://$MODULE_DIR$/config/database.yml + + + file://$MODULE_DIR$/config/environment.rb + + + file://$MODULE_DIR$/config/environments + + + file://$MODULE_DIR$/config/initializers + + + file://$MODULE_DIR$/config/locales + + + file://$MODULE_DIR$/config/routes + + + file://$MODULE_DIR$/config/routes.rb + + + file://$MODULE_DIR$/db + + + file://$MODULE_DIR$/db/migrate + + + file://$MODULE_DIR$/db/seeds.rb + + + file://$MODULE_DIR$/lib + + + file://$MODULE_DIR$/lib/assets + + + file://$MODULE_DIR$/lib/tasks + + + file://$MODULE_DIR$/lib/templates + + + file://$MODULE_DIR$/log/development.log + + + file://$MODULE_DIR$/public + + + file://$MODULE_DIR$/public/javascripts + + + file://$MODULE_DIR$/public/stylesheets + + + file://$MODULE_DIR$/test/mailers/previews + file://$MODULE_DIR$/test/mailers/previews + + + file://$MODULE_DIR$/tmp + + + file://$MODULE_DIR$/vendor + + + file://$MODULE_DIR$/vendor/assets + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..3c2b3ed --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/db/development.sqlite3 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/data_source_mapping.xml b/.idea/data_source_mapping.xml new file mode 100644 index 0000000..b3eb2ec --- /dev/null +++ b/.idea/data_source_mapping.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.ruby-version b/.ruby-version index b2eb314..5497891 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.6.3 \ No newline at end of file +ruby-3.4.5 diff --git a/Gemfile.lock b/Gemfile.lock index 7f18d70..af29700 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,67 +1,67 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.2.1) - actionpack (= 7.2.1) - activesupport (= 7.2.1) + actioncable (8.0.2.1) + actionpack (= 8.0.2.1) + activesupport (= 8.0.2.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.2.1) - actionpack (= 7.2.1) - activejob (= 7.2.1) - activerecord (= 7.2.1) - activestorage (= 7.2.1) - activesupport (= 7.2.1) + actionmailbox (8.0.2.1) + actionpack (= 8.0.2.1) + activejob (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) mail (>= 2.8.0) - actionmailer (7.2.1) - actionpack (= 7.2.1) - actionview (= 7.2.1) - activejob (= 7.2.1) - activesupport (= 7.2.1) + actionmailer (8.0.2.1) + actionpack (= 8.0.2.1) + actionview (= 8.0.2.1) + activejob (= 8.0.2.1) + activesupport (= 8.0.2.1) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.2.1) - actionview (= 7.2.1) - activesupport (= 7.2.1) + actionpack (8.0.2.1) + actionview (= 8.0.2.1) + activesupport (= 8.0.2.1) nokogiri (>= 1.8.5) - racc - rack (>= 2.2.4, < 3.2) + rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (7.2.1) - actionpack (= 7.2.1) - activerecord (= 7.2.1) - activestorage (= 7.2.1) - activesupport (= 7.2.1) + actiontext (8.0.2.1) + actionpack (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.2.1) - activesupport (= 7.2.1) + actionview (8.0.2.1) + activesupport (= 8.0.2.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.2.1) - activesupport (= 7.2.1) + activejob (8.0.2.1) + activesupport (= 8.0.2.1) globalid (>= 0.3.6) - activemodel (7.2.1) - activesupport (= 7.2.1) - activerecord (7.2.1) - activemodel (= 7.2.1) - activesupport (= 7.2.1) + activemodel (8.0.2.1) + activesupport (= 8.0.2.1) + activerecord (8.0.2.1) + activemodel (= 8.0.2.1) + activesupport (= 8.0.2.1) timeout (>= 0.4.0) - activestorage (7.2.1) - actionpack (= 7.2.1) - activejob (= 7.2.1) - activerecord (= 7.2.1) - activesupport (= 7.2.1) + activestorage (8.0.2.1) + actionpack (= 8.0.2.1) + activejob (= 8.0.2.1) + activerecord (= 8.0.2.1) + activesupport (= 8.0.2.1) marcel (~> 1.0) - activesupport (7.2.1) + activesupport (8.0.2.1) base64 + benchmark (>= 0.3) bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) @@ -71,27 +71,30 @@ GEM minitest (>= 5.1) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - archive-zip (0.12.0) - io-like (~> 0.3.0) - base64 (0.2.0) - bcrypt (3.1.16) - bigdecimal (3.1.8) + uri (>= 0.13.1) + addressable (2.8.8) + public_suffix (>= 2.0.2, < 8.0) + archive-zip (0.13.1) + io-like (~> 0.4.0) + base64 (0.3.0) + bcrypt (3.1.21) + benchmark (0.5.0) + bigdecimal (4.0.1) bindex (0.8.1) - bootsnap (1.18.4) + bootsnap (1.22.0) msgpack (~> 1.2) builder (3.3.0) - byebug (11.1.3) - capybara (3.35.3) + byebug (13.0.0) + reline (>= 0.6.0) + capybara (3.40.0) addressable + matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - childprocess (3.0.0) chromedriver-helper (2.1.1) archive-zip (~> 0.10) nokogiri (~> 1.8) @@ -102,106 +105,122 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.3.4) - connection_pool (2.4.1) + concurrent-ruby (1.3.6) + connection_pool (3.0.2) crass (1.0.6) - date (3.3.4) - drb (2.2.1) - duktape (2.6.0.0) - erubi (1.13.0) - execjs (2.7.0) - ffi (1.14.2) - ffi (1.14.2-x64-mingw32) - globalid (1.2.1) + date (3.5.1) + drb (2.2.3) + duktape (2.7.0.0) + erb (6.0.1) + erubi (1.13.1) + execjs (2.10.0) + ffi (1.17.3) + globalid (1.3.0) activesupport (>= 6.1) - i18n (1.14.5) + i18n (1.14.8) concurrent-ruby (~> 1.0) - io-console (0.7.2) - io-like (0.3.1) - irb (1.14.0) + io-console (0.8.2) + io-like (0.4.0) + irb (1.17.0) + pp (>= 0.6.0) + prism (>= 1.3.0) rdoc (>= 4.0.0) reline (>= 0.4.2) - jbuilder (2.11.2) - activesupport (>= 5.0.0) - logger (1.6.1) - loofah (2.22.0) + jbuilder (2.14.1) + actionview (>= 7.0.0) + activesupport (>= 7.0.0) + logger (1.7.0) + loofah (2.25.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) - mail (2.8.1) + mail (2.9.0) + logger mini_mime (>= 0.1.1) net-imap net-pop net-smtp - marcel (1.0.4) + marcel (1.1.0) + matrix (0.4.3) mini_mime (1.1.5) - mini_portile2 (2.8.7) - minitest (5.25.1) - msgpack (1.7.2) - net-imap (0.4.16) + mini_portile2 (2.8.9) + minitest (6.0.1) + prism (~> 1.5) + msgpack (1.8.0) + net-imap (0.6.2) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.5.0) + net-smtp (0.5.1) net-protocol - nio4r (2.7.3) - nokogiri (1.16.7) + nio4r (2.7.5) + nokogiri (1.19.0) mini_portile2 (~> 2.8.2) racc (~> 1.4) - psych (5.1.2) + nokogiri (1.19.0-x86_64-linux-gnu) + racc (~> 1.4) + pp (0.6.3) + prettyprint + prettyprint (0.2.0) + prism (1.9.0) + psych (5.3.1) + date stringio - public_suffix (4.0.6) + public_suffix (7.0.2) puma (3.12.6) racc (1.8.1) - rack (2.2.9) + rack (2.2.21) rack-session (1.0.2) rack (< 3) - rack-test (2.1.0) + rack-test (2.2.0) rack (>= 1.3) - rackup (1.0.0) + rackup (1.0.1) rack (< 3) webrick - rails (7.2.1) - actioncable (= 7.2.1) - actionmailbox (= 7.2.1) - actionmailer (= 7.2.1) - actionpack (= 7.2.1) - actiontext (= 7.2.1) - actionview (= 7.2.1) - activejob (= 7.2.1) - activemodel (= 7.2.1) - activerecord (= 7.2.1) - activestorage (= 7.2.1) - activesupport (= 7.2.1) + rails (8.0.2.1) + actioncable (= 8.0.2.1) + actionmailbox (= 8.0.2.1) + actionmailer (= 8.0.2.1) + actionpack (= 8.0.2.1) + actiontext (= 8.0.2.1) + actionview (= 8.0.2.1) + activejob (= 8.0.2.1) + activemodel (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) bundler (>= 1.15.0) - railties (= 7.2.1) - rails-dom-testing (2.2.0) + railties (= 8.0.2.1) + rails-dom-testing (2.3.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) + rails-html-sanitizer (1.6.2) loofah (~> 2.21) - nokogiri (~> 1.14) - railties (7.2.1) - actionpack (= 7.2.1) - activesupport (= 7.2.1) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.0.2.1) + actionpack (= 8.0.2.1) + activesupport (= 8.0.2.1) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) - rake (13.2.1) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) + rake (13.3.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) ffi (~> 1.0) - rdoc (6.7.0) + rdoc (7.2.0) + erb psych (>= 4.0.0) - regexp_parser (2.0.3) - reline (0.5.10) + tsort + regexp_parser (2.11.3) + reline (0.6.3) io-console (~> 0.5) - rubyzip (2.3.0) + rexml (3.4.4) + rubyzip (3.2.2) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -213,11 +232,14 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - securerandom (0.3.1) - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) - rubyzip (>= 1.2.2) - sprockets (3.7.4) + securerandom (0.4.1) + selenium-webdriver (4.40.0) + base64 (~> 0.2) + logger (~> 1.4) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 4.0) + websocket (~> 1.0) + sprockets (3.7.5) base64 concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -225,33 +247,39 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) - sqlite3 (1.4.2) - stringio (3.1.1) - thor (1.3.2) - tilt (2.0.10) - timeout (0.4.1) + sqlite3 (2.9.0) + mini_portile2 (~> 2.8.0) + sqlite3 (2.9.0-x86_64-linux-gnu) + stringio (3.2.0) + thor (1.5.0) + tilt (2.7.0) + timeout (0.6.0) + tsort (0.2.0) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - tzinfo-data (1.2021.1) + tzinfo-data (1.2025.3) tzinfo (>= 1.0.0) - uglifier (4.2.0) + uglifier (4.2.1) execjs (>= 0.3.0, < 3) - useragent (0.16.10) - web-console (3.7.0) - actionview (>= 5.0) - activemodel (>= 5.0) + uri (1.1.1) + useragent (0.16.11) + web-console (4.2.1) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) bindex (>= 0.4.0) - railties (>= 5.0) - webrick (1.8.1) - websocket-driver (0.7.6) + railties (>= 6.0.0) + webrick (1.9.2) + websocket (1.2.11) + websocket-driver (0.8.0) + base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.18) + zeitwerk (2.7.4) PLATFORMS x64-mingw32 @@ -267,7 +295,7 @@ DEPENDENCIES duktape jbuilder (~> 2.5) puma (~> 3.11) - rails (~> 7.2.1) + rails (~> 8.0.2.1) sass-rails (~> 5.0) selenium-webdriver sqlite3 @@ -277,7 +305,7 @@ DEPENDENCIES web-console (>= 3.3.0) RUBY VERSION - ruby 3.2.0p0 + ruby 3.4.5p51 BUNDLED WITH 2.4.1 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bcbc6be..85c9fc4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,7 @@ class ApplicationController < ActionController::Base helper_method :current_user + before_action :authorized + helper_method :logged_in? def current_user if session[:user_id] @@ -8,4 +10,13 @@ def current_user @current_user = nil end end + + def logged_in? + !current_user.nil? + end + + def authorized + redirect_to root_path unless logged_in? + end end + diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 95f2992..be10979 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,5 @@ class HomeController < ApplicationController + skip_before_action :authorized, only: [:index] def index end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 0b40e4e..8d8c903 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,4 +1,5 @@ class SessionsController < ApplicationController + skip_before_action :authorized, only: [:new, :create] def new end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5d00f54..e48106d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + skip_before_action :authorized, only: [:new, :create] before_action :set_user, only: %i[ show edit update destroy ] # GET /users or /users.json diff --git a/app/models/user.rb b/app/models/user.rb index dc62ef5..47fbc5c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,6 @@ class User < ApplicationRecord has_secure_password - + has_many :credit_cards + has_many :transactions validates :email_address, presence: true, uniqueness: true end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 9efbbf4..2419b46 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -3,6 +3,9 @@

Purchase items at the snap of your finger

<% if current_user %> Logged in as <%= current_user.name %>. + <%= link_to 'View all products', products_path %> + <%= link_to 'Add credit card', new_credit_card_path %>
+ <%= link_to 'View purchase history', transactions_path %>
<%= link_to "Logout", logout_path %> <% else %> <%= link_to "Signup", signup_path %> or diff --git a/config/routes.rb b/config/routes.rb index a527ddd..5417f0f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do + resources :transactions + resources :credit_cards + resources :products root 'home#index' resources :users resources :sessions, only: [:new, :create, :destroy] diff --git a/db/schema.rb b/db/schema.rb index 9590ac9..bae9b03 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,41 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_09_13_130539) do +ActiveRecord::Schema[8.0].define(version: 2026_02_13_004048) do + create_table "credit_cards", force: :cascade do |t| + t.string "name" + t.string "card_number" + t.date "expiration_date" + t.string "cvv" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "user_id", null: false + t.index ["user_id"], name: "index_credit_cards_on_user_id" + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.string "category" + t.integer "quantity" + t.integer "price" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "transactions", force: :cascade do |t| + t.integer "transaction_number" + t.integer "quantity" + t.decimal "total_cost" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "user_id", null: false + t.integer "product_id", null: false + t.integer "credit_card_id", null: false + t.index ["credit_card_id"], name: "index_transactions_on_credit_card_id" + t.index ["product_id"], name: "index_transactions_on_product_id" + t.index ["user_id"], name: "index_transactions_on_user_id" + end + create_table "users", force: :cascade do |t| t.string "name" t.string "email_address" @@ -21,4 +55,9 @@ t.datetime "updated_at", precision: nil, null: false t.index ["email_address"], name: "index_users_on_email_address", unique: true end + + add_foreign_key "credit_cards", "users" + add_foreign_key "transactions", "credit_cards" + add_foreign_key "transactions", "products" + add_foreign_key "transactions", "users" end