From 0d7391d64b07a6545c84a0caf177db52402cfc02 Mon Sep 17 00:00:00 2001 From: paolacalle <98432607+paolacalle@users.noreply.github.com> Date: Thu, 14 Sep 2023 00:30:53 -0400 Subject: [PATCH 01/45] Created rake task to import station & bike data from csv files --- lib/tasks/import_bikes.rake | 42 ++++++++++++++++++++++++++++++++++ lib/tasks/import_stations.rake | 19 +++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 lib/tasks/import_bikes.rake create mode 100644 lib/tasks/import_stations.rake diff --git a/lib/tasks/import_bikes.rake b/lib/tasks/import_bikes.rake new file mode 100644 index 000000000..d3eccf3e4 --- /dev/null +++ b/lib/tasks/import_bikes.rake @@ -0,0 +1,42 @@ + + +# lib/tasks/import_bike.rake + +require_relative '../../config/environment' +require 'csv' +csv_file = 'notes/bike-data.csv' + +namespace :import do + task :bikes => :environment do + + CSV.foreach(csv_file, headers: true) do |row| + Bike.create!( + identifier: row['identifier'], + current_station_id: row['current_station_id'], + created_at: row['created_at'], + updated_at: row['updated_at'] + ) + end + + puts "Success import of #{csv_file} into **Bike** db." + end +end + + +# csv_text = File.read('notes/bike-data.csv') +# csv = CSV.parse(csv_text, :headers => true) +# csv.each do |row| +# CreateBikes.create!(row.to_hash) +# end + +# namespace :import do +# desc "Import data from stations.csv" +# task :bikes => :environment do +# require 'csv' +# csv_text = File.read('notes/bike-data.csv') + +# CSV.parse(csv_text, headers: true) do |row| +# CreateBikes.create!(row.to_hash) +# end +# end +# end \ No newline at end of file diff --git a/lib/tasks/import_stations.rake b/lib/tasks/import_stations.rake new file mode 100644 index 000000000..871ec52e6 --- /dev/null +++ b/lib/tasks/import_stations.rake @@ -0,0 +1,19 @@ +require_relative '../../config/environment' +require 'csv' +csv_file = 'notes/station-data.csv' + +namespace :import do + task :stations => :environment do + + CSV.foreach(csv_file, headers: true) do |row| + Station.create!( + identifier: row['identifier'], + name: row['name'], + address: row['address'], + created_at: row['created_at'], + updated_at: row['updated_at'] + ) + end + puts "Success import of #{csv_file} into **Station** db." + end +end \ No newline at end of file From bcee2cb92a5840ddcd88e011c9b9f3f9539c0a86 Mon Sep 17 00:00:00 2001 From: paolacalle <98432607+paolacalle@users.noreply.github.com> Date: Sun, 17 Sep 2023 09:49:03 -0400 Subject: [PATCH 02/45] Added navbar/links, displayed bike/station lists, add more pages --- Gemfile.lock | 1 + app/controllers/bikes_controller.rb | 7 ++++ app/controllers/home_controller.rb | 4 +++ app/helpers/bikes_helper.rb | 2 ++ app/helpers/home_helper.rb | 2 ++ app/views/bikes/_row.html.erb | 17 +++++++++ app/views/bikes/index.html.erb | 20 +++++++++++ app/views/home/index.html.erb | 6 ++++ app/views/layouts/_navbar.html.erb | 22 ++++++++++++ app/views/layouts/application.html.erb | 8 +++++ app/views/stations/_row.html.erb | 4 +++ app/views/stations/index.html.erb | 7 ++-- config/routes.rb | 8 +++-- db/migrate/20220831090424_create_stations.rb | 3 +- db/migrate/20220831090719_create_bikes.rb | 1 - lib/tasks/import_bikes.rake | 6 +--- lib/tasks/import_stations.rake | 37 +++++++++++++------- test/controllers/bikes_controller_test.rb | 7 ++++ test/controllers/home_controller_test.rb | 8 +++++ 19 files changed, 145 insertions(+), 25 deletions(-) create mode 100644 app/controllers/bikes_controller.rb create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/bikes_helper.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/views/bikes/_row.html.erb create mode 100644 app/views/bikes/index.html.erb create mode 100644 app/views/home/index.html.erb create mode 100644 app/views/layouts/_navbar.html.erb create mode 100644 test/controllers/bikes_controller_test.rb create mode 100644 test/controllers/home_controller_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index c3e104938..c90d46043 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -223,6 +223,7 @@ GEM PLATFORMS arm64-darwin-20 + arm64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb new file mode 100644 index 000000000..4a81f1581 --- /dev/null +++ b/app/controllers/bikes_controller.rb @@ -0,0 +1,7 @@ +class BikesController < ApplicationController + def index + @bikes = Bike.all.order(identifier: :asc) + + end + +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 000000000..95f29929c --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,4 @@ +class HomeController < ApplicationController + def index + end +end diff --git a/app/helpers/bikes_helper.rb b/app/helpers/bikes_helper.rb new file mode 100644 index 000000000..a2645e4e1 --- /dev/null +++ b/app/helpers/bikes_helper.rb @@ -0,0 +1,2 @@ +module BikesHelper +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 000000000..23de56ac6 --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/views/bikes/_row.html.erb b/app/views/bikes/_row.html.erb new file mode 100644 index 000000000..8288b170a --- /dev/null +++ b/app/views/bikes/_row.html.erb @@ -0,0 +1,17 @@ +
flexbox vertical stretch"> + ID: <%=bike.identifier %> + <%# <% station = Station.find_by(identifier: station_identifier) %> +
flexbox vertical stretch"> + <%# <%= station.address %> + <% station = Station.find_by(identifier: bike.current_station_id) %> + + <% if station.present? %> + Station Name: <%= station.name %>
+ Station Address: <%= station.address %> + <% else %> + Station not found + <% end %> + +
+ +
\ No newline at end of file diff --git a/app/views/bikes/index.html.erb b/app/views/bikes/index.html.erb new file mode 100644 index 000000000..9ed9a628c --- /dev/null +++ b/app/views/bikes/index.html.erb @@ -0,0 +1,20 @@ +
+
+ <%= link_to 'View Station List', stations_path %> +
+
+

Bikes:

+
+ <% if @bikes.present? %> + <%= render(partial: "bikes/row", collection: @bikes, as: :bike) %> + <% else %> +
+ No stations found. +
+ <% end %> + + +
+
+
+ diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 000000000..ff47e4a4c --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,6 @@ + +
+
+ Welcome to ValetBike! +
+
\ No newline at end of file diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb new file mode 100644 index 000000000..80e622d53 --- /dev/null +++ b/app/views/layouts/_navbar.html.erb @@ -0,0 +1,22 @@ + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7ace1393e..be3097e52 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -3,6 +3,12 @@ + + + + + + <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> @@ -13,6 +19,7 @@ ValetBike + <%= render partial: 'layouts/navbar' %>
<%= yield %> @@ -20,3 +27,4 @@
+ diff --git a/app/views/stations/_row.html.erb b/app/views/stations/_row.html.erb index 68a74d983..d0b1c329c 100644 --- a/app/views/stations/_row.html.erb +++ b/app/views/stations/_row.html.erb @@ -1,3 +1,7 @@
flexbox vertical stretch"> <%= station.identifier %>: <%= station.name %> (<%= station.address %>) + <% bikes_in_station = Bike.where(current_station_id: station.identifier) %> + Number of Bikes: <%= bikes_in_station.count %> +
+ Number of Docked Bikes:
\ No newline at end of file diff --git a/app/views/stations/index.html.erb b/app/views/stations/index.html.erb index d211dda42..8b5336f59 100644 --- a/app/views/stations/index.html.erb +++ b/app/views/stations/index.html.erb @@ -1,9 +1,10 @@
-
- Welcome to ValetBike! -
+ <%= link_to 'View Bike List', bikes_path %> +
+

Stations:

+
<% if @stations.present? %> <%= render(partial: "stations/row", collection: @stations, as: :station) %> <% else %> diff --git a/config/routes.rb b/config/routes.rb index f1eb0a0d8..2b6a48a52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,7 @@ Rails.application.routes.draw do - root to: "stations#index" -end \ No newline at end of file + resources :stations, only: [:index] + resources :bikes, only: [:index] + + root 'home#index' +end + diff --git a/db/migrate/20220831090424_create_stations.rb b/db/migrate/20220831090424_create_stations.rb index 765811e88..13d330a4f 100644 --- a/db/migrate/20220831090424_create_stations.rb +++ b/db/migrate/20220831090424_create_stations.rb @@ -4,8 +4,9 @@ def change t.integer :identifier t.string :name t.string :address - t.timestamps end end end + +#identifier, name, has_kiosk, needs_maintenance, dock_count, docked_bike_count, address \ No newline at end of file diff --git a/db/migrate/20220831090719_create_bikes.rb b/db/migrate/20220831090719_create_bikes.rb index 8e0f2dcd3..ed13793e6 100644 --- a/db/migrate/20220831090719_create_bikes.rb +++ b/db/migrate/20220831090719_create_bikes.rb @@ -3,7 +3,6 @@ def change create_table :bikes do |t| t.integer :identifier t.integer :current_station_id - t.timestamps end end diff --git a/lib/tasks/import_bikes.rake b/lib/tasks/import_bikes.rake index d3eccf3e4..67215d0d4 100644 --- a/lib/tasks/import_bikes.rake +++ b/lib/tasks/import_bikes.rake @@ -1,7 +1,3 @@ - - -# lib/tasks/import_bike.rake - require_relative '../../config/environment' require 'csv' csv_file = 'notes/bike-data.csv' @@ -12,7 +8,7 @@ namespace :import do CSV.foreach(csv_file, headers: true) do |row| Bike.create!( identifier: row['identifier'], - current_station_id: row['current_station_id'], + current_station_id: row['current_station_identifier'], created_at: row['created_at'], updated_at: row['updated_at'] ) diff --git a/lib/tasks/import_stations.rake b/lib/tasks/import_stations.rake index 871ec52e6..27a32e51a 100644 --- a/lib/tasks/import_stations.rake +++ b/lib/tasks/import_stations.rake @@ -1,19 +1,30 @@ require_relative '../../config/environment' require 'csv' + csv_file = 'notes/station-data.csv' namespace :import do - task :stations => :environment do - - CSV.foreach(csv_file, headers: true) do |row| - Station.create!( - identifier: row['identifier'], - name: row['name'], - address: row['address'], - created_at: row['created_at'], - updated_at: row['updated_at'] - ) - end - puts "Success import of #{csv_file} into **Station** db." + task :stations => :environment do + csv_data = File.read(csv_file) + csv = CSV.parse(csv_data, headers: true) + + csv.each do |row| + station_data = {} + station_data[:identifier] = row['identifier'] + station_data[:name] = row['name'] + station_data[:address] = row['address'] + + station = Station.find_by(identifier: station_data[:identifier]) + if station.nil? + # Create a new station + station = Station.create!(station_data) + else + # Update the existing station if needed + station.update!(station_data) + end + end -end \ No newline at end of file + + puts "Success import of #{csv_file} into **Station** db." + end +end diff --git a/test/controllers/bikes_controller_test.rb b/test/controllers/bikes_controller_test.rb new file mode 100644 index 000000000..d156f629c --- /dev/null +++ b/test/controllers/bikes_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class BikesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 000000000..f6f3785e8 --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class HomeControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get home_index_url + assert_response :success + end +end From 307fb279a1a6b39c64d8424d9f7f4aa9d1e71b32 Mon Sep 17 00:00:00 2001 From: paolacalle <98432607+paolacalle@users.noreply.github.com> Date: Sun, 17 Sep 2023 22:10:00 -0400 Subject: [PATCH 03/45] extracted stations data, added img to home, got docked bikes to work in a odd way --- app/models/station.rb | 5 +++++ app/views/home/index.html.erb | 17 ++++++++++++----- app/views/stations/_row.html.erb | 6 ++++-- db/migrate/20220831090424_create_stations.rb | 6 ++++++ ...20230918012959_add_attributes_to_stations.rb | 12 ++++++++++++ db/schema.rb | 6 +++++- lib/tasks/import_stations.rake | 7 +++++++ 7 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20230918012959_add_attributes_to_stations.rb diff --git a/app/models/station.rb b/app/models/station.rb index 64b9eaada..d51a921b2 100644 --- a/app/models/station.rb +++ b/app/models/station.rb @@ -2,6 +2,11 @@ class Station < ApplicationRecord validates_presence_of :identifier, :name, :address + attribute :has_kiosk + attribute :needs_maintenance + attribute :dock_count + attribute :docked_bike_count + validates_uniqueness_of :identifier has_many :docked_bikes, class_name: :Bike, foreign_key: :current_station_id diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index ff47e4a4c..837a478a9 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,6 +1,13 @@ -
-
- Welcome to ValetBike! -
-
\ No newline at end of file + +
+
+
+ + +
+ +
+

ValetBike!

+

The Public Bike System Northampton Needs.

+
diff --git a/app/views/stations/_row.html.erb b/app/views/stations/_row.html.erb index d0b1c329c..5b06dafca 100644 --- a/app/views/stations/_row.html.erb +++ b/app/views/stations/_row.html.erb @@ -1,7 +1,9 @@
flexbox vertical stretch"> <%= station.identifier %>: <%= station.name %> (<%= station.address %>) <% bikes_in_station = Bike.where(current_station_id: station.identifier) %> - Number of Bikes: <%= bikes_in_station.count %> + Number of Bikes at Station: <%= bikes_in_station.count %>
- Number of Docked Bikes: +

Number of Docked Bikes: + <%= Station.find_by(identifier: station.identifier).docked_bike_count%>

+
\ No newline at end of file diff --git a/db/migrate/20220831090424_create_stations.rb b/db/migrate/20220831090424_create_stations.rb index 13d330a4f..be75ac015 100644 --- a/db/migrate/20220831090424_create_stations.rb +++ b/db/migrate/20220831090424_create_stations.rb @@ -4,6 +4,12 @@ def change t.integer :identifier t.string :name t.string :address + + t.integer :has_kiosk + t.integer :needs_maintenance + t.integer :dock_count + t.integer :docked_bike_count + t.timestamps end end diff --git a/db/migrate/20230918012959_add_attributes_to_stations.rb b/db/migrate/20230918012959_add_attributes_to_stations.rb new file mode 100644 index 000000000..b7246c540 --- /dev/null +++ b/db/migrate/20230918012959_add_attributes_to_stations.rb @@ -0,0 +1,12 @@ +# to add these attributes, I ran rails generate migration AddAttributesToStations has_kiosk:boolean needs_maintenance:boolean dock_count:integer docked_bike_count:integer +# then, rails db:migrate +# I was experiencing an error beacuse the schema and mirgate did not match + +class AddAttributesToStations < ActiveRecord::Migration[7.0] + def change + add_column :stations, :has_kiosk, :boolean + add_column :stations, :needs_maintenance, :boolean + add_column :stations, :dock_count, :integer + add_column :stations, :docked_bike_count, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index b98268f0e..c097d9919 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_08_31_090719) do +ActiveRecord::Schema[7.0].define(version: 2023_09_18_012959) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -24,6 +24,10 @@ t.string "address" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "has_kiosk" + t.boolean "needs_maintenance" + t.integer "dock_count" + t.integer "docked_bike_count" end end diff --git a/lib/tasks/import_stations.rake b/lib/tasks/import_stations.rake index 27a32e51a..36ddb8694 100644 --- a/lib/tasks/import_stations.rake +++ b/lib/tasks/import_stations.rake @@ -13,6 +13,13 @@ namespace :import do station_data[:identifier] = row['identifier'] station_data[:name] = row['name'] station_data[:address] = row['address'] + station_data[:has_kiosk] = row['has_kiosk'].to_i + station_data[:needs_maintenance] = row['needs_maintenance'].to_i + station_data[:dock_count] = row['dock_count'].to_i + station_data[:docked_bike_count] = row['docked_bike_count'].to_i + + puts "Station Data: #{station_data.inspect}" + station = Station.find_by(identifier: station_data[:identifier]) if station.nil? From a97704c1796b54600ac08674f76e0564bc5a8fbd Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Thu, 2 Nov 2023 13:17:37 -0400 Subject: [PATCH 04/45] removed unwanted file --- db/migrate/20220831090424_create_stations.rb | 4 -- ...230918012959_add_attributes_to_stations.rb | 12 ----- db/schema.rb | 45 ++++++++++++++++--- 3 files changed, 40 insertions(+), 21 deletions(-) delete mode 100644 db/migrate/20230918012959_add_attributes_to_stations.rb diff --git a/db/migrate/20220831090424_create_stations.rb b/db/migrate/20220831090424_create_stations.rb index be75ac015..a9f90d07b 100644 --- a/db/migrate/20220831090424_create_stations.rb +++ b/db/migrate/20220831090424_create_stations.rb @@ -5,10 +5,6 @@ def change t.string :name t.string :address - t.integer :has_kiosk - t.integer :needs_maintenance - t.integer :dock_count - t.integer :docked_bike_count t.timestamps end diff --git a/db/migrate/20230918012959_add_attributes_to_stations.rb b/db/migrate/20230918012959_add_attributes_to_stations.rb deleted file mode 100644 index b7246c540..000000000 --- a/db/migrate/20230918012959_add_attributes_to_stations.rb +++ /dev/null @@ -1,12 +0,0 @@ -# to add these attributes, I ran rails generate migration AddAttributesToStations has_kiosk:boolean needs_maintenance:boolean dock_count:integer docked_bike_count:integer -# then, rails db:migrate -# I was experiencing an error beacuse the schema and mirgate did not match - -class AddAttributesToStations < ActiveRecord::Migration[7.0] - def change - add_column :stations, :has_kiosk, :boolean - add_column :stations, :needs_maintenance, :boolean - add_column :stations, :dock_count, :integer - add_column :stations, :docked_bike_count, :integer - end -end diff --git a/db/schema.rb b/db/schema.rb index c097d9919..9af990b97 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_09_18_012959) do +ActiveRecord::Schema[7.0].define(version: 2023_10_29_163859) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -18,16 +18,51 @@ t.datetime "updated_at", null: false end + create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.string "name" t.string "address" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "has_kiosk" - t.boolean "needs_maintenance" + t.integer "has_kiosk" + t.integer "needs_maintenance" t.integer "dock_count" t.integer "docked_bike_count" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "tags_tasks", id: false, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.bigint "tag_id", null: false + t.bigint "task_id", null: false + t.index ["tag_id", "task_id"], name: "index_tags_tasks_on_tag_id_and_task_id" + t.index ["task_id", "tag_id"], name: "index_tags_tasks_on_task_id_and_tag_id" + end + + create_table "task_assignments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "tasks", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "first_name" + t.string "last_name" + t.string "email" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end end From 42918f5734ba2eaea0c702ca901991f92f9ced7a Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Thu, 2 Nov 2023 13:32:29 -0400 Subject: [PATCH 05/45] My name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 85f6c86ae..cf4dfe740 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ValetBike - +Paola Smith College CSC223: Software Engineering\ Starter App for ValetBike project From 01ec38cbf97de3440215d6d812065cc72ee88f59 Mon Sep 17 00:00:00 2001 From: chel48 Date: Thu, 2 Nov 2023 13:41:26 -0400 Subject: [PATCH 06/45] edits to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 85f6c86ae..9f2746a45 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Smith College CSC223: Software Engineering\ Starter App for ValetBike project +This is a change that I am making to valetbike! ## Environment Configuration From 9075d76cdf7706a781c4adb9ed76d545a610e7c6 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sun, 5 Nov 2023 11:22:29 -0500 Subject: [PATCH 07/45] Created memebership and user basics --- app/controllers/memberships_controller.rb | 17 +++++++++ app/controllers/users_controller.rb | 17 +++++++++ app/helpers/memberships_helper.rb | 2 + app/helpers/users_helper.rb | 2 + app/models/membership.rb | 2 + app/models/user.rb | 8 ++++ app/views/memberships/edit.html.erb | 4 ++ app/views/memberships/index.html.erb | 4 ++ app/views/memberships/new.html.erb | 4 ++ app/views/memberships/show.html.erb | 4 ++ app/views/users/edit.html.erb | 4 ++ app/views/users/index.html.erb | 4 ++ app/views/users/new.html.erb | 4 ++ app/views/users/show.html.erb | 4 ++ config/routes.rb | 8 ++++ db/migrate/20231103203007_create_users.rb | 13 +++++++ .../20231103203528_create_memberships.rb | 11 ++++++ db/schema.rb | 37 ++++--------------- .../memberships_controller_test.rb | 23 ++++++++++++ test/controllers/users_controller_test.rb | 23 ++++++++++++ test/fixtures/memberships.yml | 11 ++++++ test/fixtures/users.yml | 15 ++++++++ test/models/membership_test.rb | 7 ++++ test/models/user_test.rb | 7 ++++ 24 files changed, 206 insertions(+), 29 deletions(-) create mode 100644 app/controllers/memberships_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/memberships_helper.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/models/membership.rb create mode 100644 app/models/user.rb create mode 100644 app/views/memberships/edit.html.erb create mode 100644 app/views/memberships/index.html.erb create mode 100644 app/views/memberships/new.html.erb create mode 100644 app/views/memberships/show.html.erb create mode 100644 app/views/users/edit.html.erb create mode 100644 app/views/users/index.html.erb create mode 100644 app/views/users/new.html.erb create mode 100644 app/views/users/show.html.erb create mode 100644 db/migrate/20231103203007_create_users.rb create mode 100644 db/migrate/20231103203528_create_memberships.rb create mode 100644 test/controllers/memberships_controller_test.rb create mode 100644 test/controllers/users_controller_test.rb create mode 100644 test/fixtures/memberships.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/models/membership_test.rb create mode 100644 test/models/user_test.rb diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb new file mode 100644 index 000000000..052b3846d --- /dev/null +++ b/app/controllers/memberships_controller.rb @@ -0,0 +1,17 @@ +class MembershipsController < ApplicationController + def index + @membership = Membership.order(:price) + end + + def show + @membership = Membership.find(params[:id]) + end + + def new + @membership = Membership.new + end + + def edit + @membership = Membership.find(params[:id]) + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..51da5416b --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,17 @@ +class UsersController < ApplicationController + def index + @user = User.order(:price) + end + + def show + @user = User.find(params[:id]) + end + + def new + @user = Users.new + end + + def edit + @user = Users.find(params[:id]) + end +end diff --git a/app/helpers/memberships_helper.rb b/app/helpers/memberships_helper.rb new file mode 100644 index 000000000..eaf43c733 --- /dev/null +++ b/app/helpers/memberships_helper.rb @@ -0,0 +1,2 @@ +module MembershipsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 000000000..2310a240d --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/membership.rb b/app/models/membership.rb new file mode 100644 index 000000000..55591b5b1 --- /dev/null +++ b/app/models/membership.rb @@ -0,0 +1,2 @@ +class Membership < ApplicationRecord +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..edf452030 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,8 @@ +class User < ApplicationRecord + validates_presence_of :first_name, + :last_name, + :email_address, + :password + + validates_uniqueness_of :email_address +end diff --git a/app/views/memberships/edit.html.erb b/app/views/memberships/edit.html.erb new file mode 100644 index 000000000..1221fd4c7 --- /dev/null +++ b/app/views/memberships/edit.html.erb @@ -0,0 +1,4 @@ +
+

Memberships#edit

+

Find me in app/views/memberships/edit.html.erb

+
diff --git a/app/views/memberships/index.html.erb b/app/views/memberships/index.html.erb new file mode 100644 index 000000000..9208c3424 --- /dev/null +++ b/app/views/memberships/index.html.erb @@ -0,0 +1,4 @@ +
+

Memberships#index

+

Find me in app/views/memberships/index.html.erb

+
diff --git a/app/views/memberships/new.html.erb b/app/views/memberships/new.html.erb new file mode 100644 index 000000000..c7ab13974 --- /dev/null +++ b/app/views/memberships/new.html.erb @@ -0,0 +1,4 @@ +
+

Memberships#new

+

Find me in app/views/memberships/new.html.erb

+
diff --git a/app/views/memberships/show.html.erb b/app/views/memberships/show.html.erb new file mode 100644 index 000000000..3dfd45236 --- /dev/null +++ b/app/views/memberships/show.html.erb @@ -0,0 +1,4 @@ +
+

Memberships#show

+

Find me in app/views/memberships/show.html.erb

+
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 000000000..6873e47ac --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,4 @@ +
+

Users#edit

+

Find me in app/views/users/edit.html.erb

+
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 000000000..091dc8f99 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,4 @@ +
+

Users#index

+

Find me in app/views/users/index.html.erb

+
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 000000000..f8ca344c7 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,4 @@ +
+

Users#new

+

Find me in app/views/users/new.html.erb

+
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 000000000..8f05314da --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,4 @@ +
+

Users#show

+

Find me in app/views/users/show.html.erb

+
diff --git a/config/routes.rb b/config/routes.rb index 2b6a48a52..512207306 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,12 @@ Rails.application.routes.draw do + get 'memberships/index' + get 'memberships/show' + get 'memberships/new' + get 'memberships/edit' + get 'users/index' + get 'users/show' + get 'users/new' + get 'users/edit' resources :stations, only: [:index] resources :bikes, only: [:index] diff --git a/db/migrate/20231103203007_create_users.rb b/db/migrate/20231103203007_create_users.rb new file mode 100644 index 000000000..b97b38396 --- /dev/null +++ b/db/migrate/20231103203007_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration[7.0] + def change + create_table :users do |t| + t.string :first_name + t.string :last_name + t.string :email_address + t.boolean :has_bike + t.string :password + + t.timestamps + end + end +end diff --git a/db/migrate/20231103203528_create_memberships.rb b/db/migrate/20231103203528_create_memberships.rb new file mode 100644 index 000000000..20e453221 --- /dev/null +++ b/db/migrate/20231103203528_create_memberships.rb @@ -0,0 +1,11 @@ +class CreateMemberships < ActiveRecord::Migration[7.0] + def change + create_table :memberships do |t| + t.string :type + t.float :cost + t.date :expiration_date + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9af990b97..e529fed69 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_29_163859) do +ActiveRecord::Schema[7.0].define(version: 2023_11_03_203528) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -18,7 +18,10 @@ t.datetime "updated_at", null: false end - create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "type" + t.float "cost" + t.date "expiration_date" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -27,32 +30,6 @@ t.integer "identifier" t.string "name" t.string "address" - t.integer "has_kiosk" - t.integer "needs_maintenance" - t.integer "dock_count" - t.integer "docked_bike_count" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "tags_tasks", id: false, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "tag_id", null: false - t.bigint "task_id", null: false - t.index ["tag_id", "task_id"], name: "index_tags_tasks_on_tag_id_and_task_id" - t.index ["task_id", "tag_id"], name: "index_tags_tasks_on_task_id_and_tag_id" - end - - create_table "task_assignments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "tasks", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -60,7 +37,9 @@ create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "first_name" t.string "last_name" - t.string "email" + t.string "email_address" + t.boolean "has_bike" + t.string "password" t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/test/controllers/memberships_controller_test.rb b/test/controllers/memberships_controller_test.rb new file mode 100644 index 000000000..16008437b --- /dev/null +++ b/test/controllers/memberships_controller_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class MembershipsControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get memberships_index_url + assert_response :success + end + + test "should get show" do + get memberships_show_url + assert_response :success + end + + test "should get new" do + get memberships_new_url + assert_response :success + end + + test "should get edit" do + get memberships_edit_url + assert_response :success + end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 000000000..8e31f7ce6 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class UsersControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get users_index_url + assert_response :success + end + + test "should get show" do + get users_show_url + assert_response :success + end + + test "should get new" do + get users_new_url + assert_response :success + end + + test "should get edit" do + get users_edit_url + assert_response :success + end +end diff --git a/test/fixtures/memberships.yml b/test/fixtures/memberships.yml new file mode 100644 index 000000000..07a32b3e1 --- /dev/null +++ b/test/fixtures/memberships.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + type: + cost: 1.5 + expiration_date: 2023-11-03 + +two: + type: + cost: 1.5 + expiration_date: 2023-11-03 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 000000000..148530e18 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,15 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + first_name: MyString + last_name: MyString + email_address: MyString + has_bike: false + password: MyString + +two: + first_name: MyString + last_name: MyString + email_address: MyString + has_bike: false + password: MyString diff --git a/test/models/membership_test.rb b/test/models/membership_test.rb new file mode 100644 index 000000000..8506331ed --- /dev/null +++ b/test/models/membership_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class MembershipTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 000000000..5c07f4900 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 1252fa6aa344696343f39428ff1d0eb357e947e8 Mon Sep 17 00:00:00 2001 From: chel48 Date: Sun, 5 Nov 2023 17:36:18 -0500 Subject: [PATCH 08/45] payment and rental forms and mvc --- Gemfile.lock | 1 + app/controllers/payments_controller.rb | 35 +++++++++++++++ app/controllers/rentals_controller.rb | 39 +++++++++++++++++ app/helpers/payments_helper.rb | 2 + app/helpers/rentals_helper.rb | 2 + app/models/payment.rb | 2 + app/models/rental.rb | 2 + app/views/layouts/_navbar.html.erb | 6 +++ app/views/payments/_row.html.erb | 7 +++ app/views/payments/create.html.erb | 4 ++ app/views/payments/destroy.html.erb | 4 ++ app/views/payments/edit.html.erb | 4 ++ app/views/payments/index.html.erb | 36 ++++++++++++++++ app/views/payments/new.html.erb | 12 ++++++ app/views/payments/show.html.erb | 4 ++ app/views/payments/update.html.erb | 4 ++ app/views/rentals/_row.html.erb | 7 +++ app/views/rentals/create.html.erb | 4 ++ app/views/rentals/destroy.html.erb | 4 ++ app/views/rentals/edit.html.erb | 4 ++ app/views/rentals/index.html.erb | 38 +++++++++++++++++ app/views/rentals/new.html.erb | 17 ++++++++ app/views/rentals/show.html.erb | 4 ++ app/views/rentals/update.html.erb | 4 ++ config/routes.rb | 20 +++++++++ db/migrate/20231105185936_create_rentals.rb | 13 ++++++ db/migrate/20231105190001_create_payments.rb | 9 ++++ db/schema.rb | 45 ++++++-------------- test/controllers/payments_controller_test.rb | 38 +++++++++++++++++ test/controllers/rentals_controller_test.rb | 38 +++++++++++++++++ test/fixtures/payments.yml | 7 +++ test/fixtures/rentals.yml | 15 +++++++ test/models/payment_test.rb | 7 +++ test/models/rental_test.rb | 7 +++ 34 files changed, 413 insertions(+), 32 deletions(-) create mode 100644 app/controllers/payments_controller.rb create mode 100644 app/controllers/rentals_controller.rb create mode 100644 app/helpers/payments_helper.rb create mode 100644 app/helpers/rentals_helper.rb create mode 100644 app/models/payment.rb create mode 100644 app/models/rental.rb create mode 100644 app/views/payments/_row.html.erb create mode 100644 app/views/payments/create.html.erb create mode 100644 app/views/payments/destroy.html.erb create mode 100644 app/views/payments/edit.html.erb create mode 100644 app/views/payments/index.html.erb create mode 100644 app/views/payments/new.html.erb create mode 100644 app/views/payments/show.html.erb create mode 100644 app/views/payments/update.html.erb create mode 100644 app/views/rentals/_row.html.erb create mode 100644 app/views/rentals/create.html.erb create mode 100644 app/views/rentals/destroy.html.erb create mode 100644 app/views/rentals/edit.html.erb create mode 100644 app/views/rentals/index.html.erb create mode 100644 app/views/rentals/new.html.erb create mode 100644 app/views/rentals/show.html.erb create mode 100644 app/views/rentals/update.html.erb create mode 100644 db/migrate/20231105185936_create_rentals.rb create mode 100644 db/migrate/20231105190001_create_payments.rb create mode 100644 test/controllers/payments_controller_test.rb create mode 100644 test/controllers/rentals_controller_test.rb create mode 100644 test/fixtures/payments.yml create mode 100644 test/fixtures/rentals.yml create mode 100644 test/models/payment_test.rb create mode 100644 test/models/rental_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index c90d46043..4a4ad4140 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -223,6 +223,7 @@ GEM PLATFORMS arm64-darwin-20 + arm64-darwin-21 arm64-darwin-22 x86_64-linux diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb new file mode 100644 index 000000000..2c0175417 --- /dev/null +++ b/app/controllers/payments_controller.rb @@ -0,0 +1,35 @@ +class PaymentsController < ApplicationController + def index + @payments = Payment.order(:amount) + render :index + end + + def new + @payment = Payment.new + render :new + end + + def create + @payment = Payment.new(params.require(:payment).permit(:credit_card_info, :amount)) + if @payment.save + flash[:success] = "Payment complete" + redirect_to payments_url + else + flash.now[:error] = "Payment failed" + render :new + end + end + + def show + end + + def update + end + + def edit + end + + def destroy + end + +end diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb new file mode 100644 index 000000000..d6334868e --- /dev/null +++ b/app/controllers/rentals_controller.rb @@ -0,0 +1,39 @@ +class RentalsController < ApplicationController + def index + @rentals = Rental.order(:rented_at) + render :index + end + + def new + @rental = Rental.new + render :new + end + + def create + @rental = Rental.new(params.require(:rental).permit(:identifier, :rental_period, :return_by)) + if @rental.save + flash[:success] = "Rental created!" + redirect_to rentals_url + flash[:success] = "Rental created for real!" + else + flash.now[:error] = "Rental creation failed" + render :new + end + end + + def show + @rental = Rental.find(params[:id]) + render :show + end + + def update + end + + def edit + end + + def destroy + end + + +end diff --git a/app/helpers/payments_helper.rb b/app/helpers/payments_helper.rb new file mode 100644 index 000000000..c1b884f80 --- /dev/null +++ b/app/helpers/payments_helper.rb @@ -0,0 +1,2 @@ +module PaymentsHelper +end diff --git a/app/helpers/rentals_helper.rb b/app/helpers/rentals_helper.rb new file mode 100644 index 000000000..5a8b81508 --- /dev/null +++ b/app/helpers/rentals_helper.rb @@ -0,0 +1,2 @@ +module RentalsHelper +end diff --git a/app/models/payment.rb b/app/models/payment.rb new file mode 100644 index 000000000..eab5c2611 --- /dev/null +++ b/app/models/payment.rb @@ -0,0 +1,2 @@ +class Payment < ApplicationRecord +end diff --git a/app/models/rental.rb b/app/models/rental.rb new file mode 100644 index 000000000..79e3a65ca --- /dev/null +++ b/app/models/rental.rb @@ -0,0 +1,2 @@ +class Rental < ApplicationRecord +end diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 80e622d53..fe823aaa8 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -15,6 +15,12 @@ + +
diff --git a/app/views/payments/_row.html.erb b/app/views/payments/_row.html.erb new file mode 100644 index 000000000..5c7ced441 --- /dev/null +++ b/app/views/payments/_row.html.erb @@ -0,0 +1,7 @@ +
flexbox vertical stretch"> + <%= payment.id %> + Credit card info: <%= payment.credit_card_info %> +
+

Amount: <%= payment.amount %> + +

\ No newline at end of file diff --git a/app/views/payments/create.html.erb b/app/views/payments/create.html.erb new file mode 100644 index 000000000..64043289d --- /dev/null +++ b/app/views/payments/create.html.erb @@ -0,0 +1,4 @@ +
+

Payments#create

+

Find me in app/views/payments/create.html.erb

+
diff --git a/app/views/payments/destroy.html.erb b/app/views/payments/destroy.html.erb new file mode 100644 index 000000000..5b8401406 --- /dev/null +++ b/app/views/payments/destroy.html.erb @@ -0,0 +1,4 @@ +
+

Payments#destroy

+

Find me in app/views/payments/destroy.html.erb

+
diff --git a/app/views/payments/edit.html.erb b/app/views/payments/edit.html.erb new file mode 100644 index 000000000..aeef7dd69 --- /dev/null +++ b/app/views/payments/edit.html.erb @@ -0,0 +1,4 @@ +
+

Payments#edit

+

Find me in app/views/payments/edit.html.erb

+
diff --git a/app/views/payments/index.html.erb b/app/views/payments/index.html.erb new file mode 100644 index 000000000..9ce7e3888 --- /dev/null +++ b/app/views/payments/index.html.erb @@ -0,0 +1,36 @@ + + +
+
+
+ +
+ +
+

ValetBike!

+

The Public Bike System Northampton Needs.

+
+ +
+

Payments#index

+

Find me in app/views/payments/index.html.erb

+

+ <%= link_to "New Payment", new_payment_path, class: 'btn btn-primary' %> +

+
+ +
+
+
+

Payments:

+
+ <% if @payments.present? %> + <%= render(partial: "payments/row", collection: @payments, as: :payment) %> + <% else %> +
+ No payments found. +
+ <% end %> +
+
+
\ No newline at end of file diff --git a/app/views/payments/new.html.erb b/app/views/payments/new.html.erb new file mode 100644 index 000000000..df381befe --- /dev/null +++ b/app/views/payments/new.html.erb @@ -0,0 +1,12 @@ +

New Payment

+<%= form_with model: @payment, url: payments_path, method: :post, local:true do |f| %> + + <%= f.label (:credit_card_info) %> + <%= f.text_field (:credit_card_info) %> + + <%= f.label (:amount) %> + <%= f.text_field (:amount) %> + + <%= f.submit %> + +<% end %> diff --git a/app/views/payments/show.html.erb b/app/views/payments/show.html.erb new file mode 100644 index 000000000..ad0b41045 --- /dev/null +++ b/app/views/payments/show.html.erb @@ -0,0 +1,4 @@ +
+

Payments#show

+

Find me in app/views/payments/show.html.erb

+
diff --git a/app/views/payments/update.html.erb b/app/views/payments/update.html.erb new file mode 100644 index 000000000..059fec6ed --- /dev/null +++ b/app/views/payments/update.html.erb @@ -0,0 +1,4 @@ +
+

Payments#update

+

Find me in app/views/payments/update.html.erb

+
diff --git a/app/views/rentals/_row.html.erb b/app/views/rentals/_row.html.erb new file mode 100644 index 000000000..411596120 --- /dev/null +++ b/app/views/rentals/_row.html.erb @@ -0,0 +1,7 @@ +
flexbox vertical stretch"> + <%= rental.identifier %> + Rental period: <%= rental.rental_period %> +
+

Return by: <%= rental.return_by %> + +

\ No newline at end of file diff --git a/app/views/rentals/create.html.erb b/app/views/rentals/create.html.erb new file mode 100644 index 000000000..bcac74f77 --- /dev/null +++ b/app/views/rentals/create.html.erb @@ -0,0 +1,4 @@ +
+

Rentals#create

+

Find me in app/views/rentals/create.html.erb

+
diff --git a/app/views/rentals/destroy.html.erb b/app/views/rentals/destroy.html.erb new file mode 100644 index 000000000..044026fe7 --- /dev/null +++ b/app/views/rentals/destroy.html.erb @@ -0,0 +1,4 @@ +
+

Rentals#destroy

+

Find me in app/views/rentals/destroy.html.erb

+
diff --git a/app/views/rentals/edit.html.erb b/app/views/rentals/edit.html.erb new file mode 100644 index 000000000..e4b490a4a --- /dev/null +++ b/app/views/rentals/edit.html.erb @@ -0,0 +1,4 @@ +
+

Rentals#edit

+

Find me in app/views/rentals/edit.html.erb

+
diff --git a/app/views/rentals/index.html.erb b/app/views/rentals/index.html.erb new file mode 100644 index 000000000..bb4141aa2 --- /dev/null +++ b/app/views/rentals/index.html.erb @@ -0,0 +1,38 @@ +
+
+
+ + +
+ +
+

ValetBike!

+

The Public Bike System Northampton Needs.

+
+ + +
+

Rentals#index

+

Find me in app/views/rentals/index.html.erb

+

+ <%= link_to "Create New Rental", new_rental_path, class: 'btn btn-primary' %> +

+
+ +
+
+
+

Rentals:

+
+ <% if @rentals.present? %> + <%= render(partial: "rentals/row", collection: @rentals, as: :rental) %> + <% else %> +
+ No rentals found. +
+ <% end %> +
+
+
+ + diff --git a/app/views/rentals/new.html.erb b/app/views/rentals/new.html.erb new file mode 100644 index 000000000..0be037c26 --- /dev/null +++ b/app/views/rentals/new.html.erb @@ -0,0 +1,17 @@ +

Create New Rental

+ <%= form_with model: @rental, url: rentals_path, method: :post, local:true do |f| %> + + <%= f.label (:identifier) %> + <%= f.text_field (:identifier) %> + + <%= f.label (:rental_period) %> + <%= f.text_field (:rental_period) %> + + <%= f.label (:return_by) %> + <%= f.date_field (:return_by) %> + + <%= f.submit %> + + <% end %> + + \ No newline at end of file diff --git a/app/views/rentals/show.html.erb b/app/views/rentals/show.html.erb new file mode 100644 index 000000000..857494e93 --- /dev/null +++ b/app/views/rentals/show.html.erb @@ -0,0 +1,4 @@ +
+

Rentals#show

+

Find me in app/views/rentals/show.html.erb

+
diff --git a/app/views/rentals/update.html.erb b/app/views/rentals/update.html.erb new file mode 100644 index 000000000..66795b4c0 --- /dev/null +++ b/app/views/rentals/update.html.erb @@ -0,0 +1,4 @@ +
+

Rentals#update

+

Find me in app/views/rentals/update.html.erb

+
diff --git a/config/routes.rb b/config/routes.rb index 2b6a48a52..53949d7f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,27 @@ Rails.application.routes.draw do + + get 'payments', to: 'payments#index', as: 'payments' + post 'payments', to: 'payments#create' + get 'payments/new', to: 'payments#new', as: 'new_payment' + get 'payments/:id' , to: 'payments#show', as: 'payment' + get 'payments/update' + get 'payments/edit' + get 'payments/destroy' + + get 'rentals', to: 'rentals#index', as: 'rentals' + post 'rentals', to: 'rentals#create' + get 'rentals/new', to: 'rentals#new', as: 'new_rental' + get 'rentals/:id' , to: 'rentals#show', as: 'rental' + get 'rentals/update' + get 'rentals/edit' + get 'rentals/destroy' + resources :stations, only: [:index] resources :bikes, only: [:index] + # resources :rentals, only: [:index] + # resources :payments, only: [:index] root 'home#index' + end diff --git a/db/migrate/20231105185936_create_rentals.rb b/db/migrate/20231105185936_create_rentals.rb new file mode 100644 index 000000000..5af0a7568 --- /dev/null +++ b/db/migrate/20231105185936_create_rentals.rb @@ -0,0 +1,13 @@ +class CreateRentals < ActiveRecord::Migration[7.0] + def change + create_table :rentals do |t| + t.integer :identifier + t.datetime :rented_at + t.datetime :returned_at + t.integer :rental_period + t.datetime :return_by + + t.timestamps + end + end +end diff --git a/db/migrate/20231105190001_create_payments.rb b/db/migrate/20231105190001_create_payments.rb new file mode 100644 index 000000000..16e57249f --- /dev/null +++ b/db/migrate/20231105190001_create_payments.rb @@ -0,0 +1,9 @@ +class CreatePayments < ActiveRecord::Migration[7.0] + def change + create_table :payments do |t| + t.string :credit_card_info + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9af990b97..d89a13ac7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_29_163859) do +ActiveRecord::Schema[7.0].define(version: 2023_11_05_190001) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -18,7 +18,18 @@ t.datetime "updated_at", null: false end - create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + create_table "payments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "credit_card_info" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "rentals", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.integer "identifier" + t.datetime "rented_at" + t.datetime "returned_at" + t.integer "rental_period" + t.datetime "return_by" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -35,34 +46,4 @@ t.datetime "updated_at", null: false end - create_table "tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "tags_tasks", id: false, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "tag_id", null: false - t.bigint "task_id", null: false - t.index ["tag_id", "task_id"], name: "index_tags_tasks_on_tag_id_and_task_id" - t.index ["task_id", "tag_id"], name: "index_tags_tasks_on_task_id_and_tag_id" - end - - create_table "task_assignments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "tasks", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.string "first_name" - t.string "last_name" - t.string "email" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - end diff --git a/test/controllers/payments_controller_test.rb b/test/controllers/payments_controller_test.rb new file mode 100644 index 000000000..288d0ef1c --- /dev/null +++ b/test/controllers/payments_controller_test.rb @@ -0,0 +1,38 @@ +require "test_helper" + +class PaymentsControllerTest < ActionDispatch::IntegrationTest + test "should get new" do + get payments_new_url + assert_response :success + end + + test "should get create" do + get payments_create_url + assert_response :success + end + + test "should get update" do + get payments_update_url + assert_response :success + end + + test "should get edit" do + get payments_edit_url + assert_response :success + end + + test "should get destroy" do + get payments_destroy_url + assert_response :success + end + + test "should get index" do + get payments_index_url + assert_response :success + end + + test "should get show" do + get payments_show_url + assert_response :success + end +end diff --git a/test/controllers/rentals_controller_test.rb b/test/controllers/rentals_controller_test.rb new file mode 100644 index 000000000..80fe9bd67 --- /dev/null +++ b/test/controllers/rentals_controller_test.rb @@ -0,0 +1,38 @@ +require "test_helper" + +class RentalsControllerTest < ActionDispatch::IntegrationTest + test "should get new" do + get rentals_new_url + assert_response :success + end + + test "should get create" do + get rentals_create_url + assert_response :success + end + + test "should get update" do + get rentals_update_url + assert_response :success + end + + test "should get edit" do + get rentals_edit_url + assert_response :success + end + + test "should get destroy" do + get rentals_destroy_url + assert_response :success + end + + test "should get index" do + get rentals_index_url + assert_response :success + end + + test "should get show" do + get rentals_show_url + assert_response :success + end +end diff --git a/test/fixtures/payments.yml b/test/fixtures/payments.yml new file mode 100644 index 000000000..2047d212c --- /dev/null +++ b/test/fixtures/payments.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + credit_card_info: MyString + +two: + credit_card_info: MyString diff --git a/test/fixtures/rentals.yml b/test/fixtures/rentals.yml new file mode 100644 index 000000000..766b4bff2 --- /dev/null +++ b/test/fixtures/rentals.yml @@ -0,0 +1,15 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + identifier: 1 + rented_at: 2023-11-05 13:59:36 + returned_at: 2023-11-05 13:59:36 + rental_period: 1 + return_by: 2023-11-05 13:59:36 + +two: + identifier: 1 + rented_at: 2023-11-05 13:59:36 + returned_at: 2023-11-05 13:59:36 + rental_period: 1 + return_by: 2023-11-05 13:59:36 diff --git a/test/models/payment_test.rb b/test/models/payment_test.rb new file mode 100644 index 000000000..f43bc797b --- /dev/null +++ b/test/models/payment_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class PaymentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/rental_test.rb b/test/models/rental_test.rb new file mode 100644 index 000000000..c3d74bd40 --- /dev/null +++ b/test/models/rental_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RentalTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 2f34480ccdee9097cfc2f33e5105af6d4b103844 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sun, 5 Nov 2023 17:41:17 -0500 Subject: [PATCH 09/45] changed --- app/controllers/categories_controller.rb | 23 ++++++++ app/controllers/memberships_controller.rb | 12 ++++ app/controllers/users_controller.rb | 7 +++ app/helpers/application_helper.rb | 7 +++ app/helpers/categories_helper.rb | 2 + app/models/category.rb | 5 ++ app/models/membership.rb | 2 + app/views/categories/delete.html.erb | 4 ++ app/views/categories/edit.html.erb | 4 ++ app/views/categories/index.html.erb | 4 ++ app/views/categories/new.html.erb | 0 app/views/categories/show.html.erb | 4 ++ app/views/memberships/delete.html.erb | 0 app/views/users/delete.html.erb | 0 config/routes.rb | 56 +++++++++++++++---- db/migrate/20231103203007_create_users.rb | 3 + .../20231105194701_create_categories.rb | 9 +++ ...5194806_add_category_id_to_memeberships.rb | 5 ++ db/schema.rb | 9 ++- .../controllers/categories_controller_test.rb | 23 ++++++++ test/fixtures/categories.yml | 7 +++ test/models/category_test.rb | 7 +++ 22 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 app/controllers/categories_controller.rb create mode 100644 app/helpers/categories_helper.rb create mode 100644 app/models/category.rb create mode 100644 app/views/categories/delete.html.erb create mode 100644 app/views/categories/edit.html.erb create mode 100644 app/views/categories/index.html.erb create mode 100644 app/views/categories/new.html.erb create mode 100644 app/views/categories/show.html.erb create mode 100644 app/views/memberships/delete.html.erb create mode 100644 app/views/users/delete.html.erb create mode 100644 db/migrate/20231105194701_create_categories.rb create mode 100644 db/migrate/20231105194806_add_category_id_to_memeberships.rb create mode 100644 test/controllers/categories_controller_test.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/models/category_test.rb diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 000000000..bd5653d1e --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,23 @@ +class CategoriesController < ApplicationController + def index + end + + def show + end + + def edit + end + + def create + end + + def delete + end + + def destroy + end + + def new + end + +end diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb index 052b3846d..1ef59ac32 100644 --- a/app/controllers/memberships_controller.rb +++ b/app/controllers/memberships_controller.rb @@ -14,4 +14,16 @@ def new def edit @membership = Membership.find(params[:id]) end + + def update + + end + + def delete + + end + + def destroy + + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 51da5416b..fbbd7a832 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,4 +14,11 @@ def new def edit @user = Users.find(params[:id]) end + + def delete + end + + def full_name + [first_name, last_name].join(' ') + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..ed572c74d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,9 @@ module ApplicationHelper + def logged_in? + + end + + def current_user + + end end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 000000000..e06f31554 --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 000000000..ac2224535 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,5 @@ +class Category < ApplicationRecord + has_many :memberships + + +end diff --git a/app/models/membership.rb b/app/models/membership.rb index 55591b5b1..8ae5cdf86 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -1,2 +1,4 @@ class Membership < ApplicationRecord + belongs_to :category #annual, weekly, day, monthly + end diff --git a/app/views/categories/delete.html.erb b/app/views/categories/delete.html.erb new file mode 100644 index 000000000..c157520b5 --- /dev/null +++ b/app/views/categories/delete.html.erb @@ -0,0 +1,4 @@ +
+

Categories#delete

+

Find me in app/views/categories/delete.html.erb

+
diff --git a/app/views/categories/edit.html.erb b/app/views/categories/edit.html.erb new file mode 100644 index 000000000..1e2205a5f --- /dev/null +++ b/app/views/categories/edit.html.erb @@ -0,0 +1,4 @@ +
+

Categories#edit

+

Find me in app/views/categories/edit.html.erb

+
diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb new file mode 100644 index 000000000..8a8143af2 --- /dev/null +++ b/app/views/categories/index.html.erb @@ -0,0 +1,4 @@ +
+

Categories#index

+

Find me in app/views/categories/index.html.erb

+
diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 000000000..e00d1a237 --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,4 @@ +
+

Categories#show

+

Find me in app/views/categories/show.html.erb

+
diff --git a/app/views/memberships/delete.html.erb b/app/views/memberships/delete.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/users/delete.html.erb b/app/views/users/delete.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/routes.rb b/config/routes.rb index 512207306..9b162a067 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,51 @@ Rails.application.routes.draw do - get 'memberships/index' - get 'memberships/show' - get 'memberships/new' - get 'memberships/edit' - get 'users/index' - get 'users/show' - get 'users/new' - get 'users/edit' + + resources :categories do + member do + #adds delete action since not added by deafult + #optional, can simply destory + get :delete + end + + end + + resources :memberships do + member do + get :delete + end + + end + + resources :users do + member do + get :delete + end + + end + resources :stations, only: [:index] - resources :bikes, only: [:index] + resources :bikes, only: [:index] + - root 'home#index' + root 'home#index' #homepage end + # get 'categories/index' + # get 'categories/show' + # get 'categories/edit' + # get 'categories/delete' + # get 'categories/new' + + + # get 'memberships/index' + # get 'memberships/show' + # get 'memberships/new' + # get 'memberships/edit' + # get 'memberships/delete' + + + # get 'users/index' + # get 'users/show' + # get 'users/new' + # get 'users/edit' + # get 'memberships/delete' \ No newline at end of file diff --git a/db/migrate/20231103203007_create_users.rb b/db/migrate/20231103203007_create_users.rb index b97b38396..4cbc1c3cb 100644 --- a/db/migrate/20231103203007_create_users.rb +++ b/db/migrate/20231103203007_create_users.rb @@ -11,3 +11,6 @@ def change end end end + +# change combined up and down method +# allows you to drop users and add users \ No newline at end of file diff --git a/db/migrate/20231105194701_create_categories.rb b/db/migrate/20231105194701_create_categories.rb new file mode 100644 index 000000000..aaa868dda --- /dev/null +++ b/db/migrate/20231105194701_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[7.0] + def change + create_table :categories do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20231105194806_add_category_id_to_memeberships.rb b/db/migrate/20231105194806_add_category_id_to_memeberships.rb new file mode 100644 index 000000000..ce4407556 --- /dev/null +++ b/db/migrate/20231105194806_add_category_id_to_memeberships.rb @@ -0,0 +1,5 @@ +class AddCategoryIdToMemeberships < ActiveRecord::Migration[7.0] + def change + add_column(:memberships, :category_id, :integer, index: true) #annual, weekly, monthy, day + end +end diff --git a/db/schema.rb b/db/schema.rb index e529fed69..ca74fa1e4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_03_203528) do +ActiveRecord::Schema[7.0].define(version: 2023_11_05_194806) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -18,12 +18,19 @@ t.datetime "updated_at", null: false end + create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "type" t.float "cost" t.date "expiration_date" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "category_id" end create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 000000000..bd3492bf8 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class CategoriesControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get categories_index_url + assert_response :success + end + + test "should get show" do + get categories_show_url + assert_response :success + end + + test "should get edit" do + get categories_edit_url + assert_response :success + end + + test "should get delete" do + get categories_delete_url + assert_response :success + end +end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 000000000..7d4122404 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 000000000..869357c88 --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From f0dd917dac04b7719a629e7b2f1e6dab23efea8c Mon Sep 17 00:00:00 2001 From: chel48 Date: Sun, 5 Nov 2023 17:57:44 -0500 Subject: [PATCH 10/45] payment amount forgotten column --- db/migrate/20231105190001_create_payments.rb | 1 + db/schema.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/db/migrate/20231105190001_create_payments.rb b/db/migrate/20231105190001_create_payments.rb index 16e57249f..b4cc6a01c 100644 --- a/db/migrate/20231105190001_create_payments.rb +++ b/db/migrate/20231105190001_create_payments.rb @@ -2,6 +2,7 @@ class CreatePayments < ActiveRecord::Migration[7.0] def change create_table :payments do |t| t.string :credit_card_info + t.float :amount t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index d89a13ac7..5eab27a32 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -20,6 +20,7 @@ create_table "payments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "credit_card_info" + t.float "amount" t.datetime "created_at", null: false t.datetime "updated_at", null: false end From 724f86a651c051f0f673f6ad2f296e1b323537d1 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sun, 5 Nov 2023 20:52:54 -0500 Subject: [PATCH 11/45] Added bolderplate for login --- app/controllers/application_controller.rb | 19 ++++++++++++ app/controllers/sessions_controller.rb | 15 +++++++++ app/controllers/users_controller.rb | 23 +++++++++++--- app/helpers/sessions_helper.rb | 2 ++ app/views/sessions/new.html.erb | 5 +++ app/views/users/new.html.erb | 32 ++++++++++++++++++-- config/routes.rb | 24 +++------------ test/controllers/sessions_controller_test.rb | 7 +++++ 8 files changed, 99 insertions(+), 28 deletions(-) create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/helpers/sessions_helper.rb create mode 100644 app/views/sessions/new.html.erb create mode 100644 test/controllers/sessions_controller_test.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12a..9e7adca9f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,21 @@ class ApplicationController < ActionController::Base + #declare as helper so accessable to all views + helper_method :current_user + helper_method :logged_in? + before_action :require_login + + def logged_in? + session[:user_id] + end + + def require_login + if !logged_in? + redirect_to login_path + end + end + + def current_user + @current_user ||= User.find(session[:user_id]) if + session[:user_id] + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 000000000..a2317ed5d --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,15 @@ +class SessionsController < ApplicationController + def new + end + + def create + user = User.find_by(username: params[:gmail_address]) + session[:user_id] = user.id + redirect_to user_path(user) + end + + def destroy + session.clear + redirect_to login_path + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fbbd7a832..9cb72e4c8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,6 @@ class UsersController < ApplicationController + skip_before_action :require_login, only:[:new, :create] #requires login + def index @user = User.order(:price) end @@ -8,17 +10,28 @@ def show end def new - @user = Users.new + @user = User.new end def edit - @user = Users.find(params[:id]) + @user = User.find(params[:id]) end def delete end - def full_name - [first_name, last_name].join(' ') - end + def create + @user = User.new({email_address: params[:email_address], + first_name: params[:first_name], + last_name: params[:last_name], + password: params[:password]}) + + puts @user + + if @user.save #if save is sucessful + redirect_to rentals_path + else + render :new + end + end end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 000000000..309f8b2eb --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 000000000..e2ecacb9e --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,5 @@ +

Login

+<%=form_tag (sessions_path) do %> +<%=text_field_tag :email %> +<%=submit_tag %> +<% end %> \ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index f8ca344c7..d881f3687 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,4 +1,30 @@ -
-

Users#new

-

Find me in app/views/users/new.html.erb

+
+

Welcome

+

Sign Up

+ + <%= form_tag(users_path) do %> + + + + + + + + + + + + + + + + + +
<%= label_tag(:first_name) %><%= text_field_tag(:first_name, params[:first_name]) %>
<%= label_tag(:last_name) %><%= text_field_tag(:last_name, params[:last_name]) %>
<%= label_tag(:gmail_address) %><%= text_field_tag(:gmail_address, params[:gmail_address]) %>
<%= label_tag(:password) %><%= password_field_tag(:password) %>
+ +
+ <%= submit_tag("Sign Up") %> +
+ + <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 03731abcb..29116a2ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,9 @@ Rails.application.routes.draw do + get '/login', to: 'sessions#new', as: 'login' + post '/sessions', to: 'sessions#create', as: 'sessions' + delete '/sessions', to: 'sessions#destroy' + resources :categories do member do #adds delete action since not added by deafult @@ -47,23 +51,3 @@ end - - # get 'categories/index' - # get 'categories/show' - # get 'categories/edit' - # get 'categories/delete' - # get 'categories/new' - - - # get 'memberships/index' - # get 'memberships/show' - # get 'memberships/new' - # get 'memberships/edit' - # get 'memberships/delete' - - - # get 'users/index' - # get 'users/show' - # get 'users/new' - # get 'users/edit' - # get 'memberships/delete' \ No newline at end of file diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 000000000..e5da4b3f3 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class SessionsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end From ef39e717dd976ac77930a1cdc0cf7a98daf59cd4 Mon Sep 17 00:00:00 2001 From: okveery Date: Tue, 7 Nov 2023 10:24:21 -0500 Subject: [PATCH 12/45] added some ux changes to user, membership + navbar --- .vs/slnx.sqlite | 0 app/controllers/application_controller.rb | 6 ++--- app/views/home/index.html.erb | 4 +++ app/views/layouts/_navbar.html.erb | 6 +++++ app/views/memberships/new.html.erb | 2 ++ app/views/sessions/new.html.erb | 14 +++++++--- app/views/users/new.html.erb | 6 ++--- app/views/users/show.html.erb | 3 ++- config/routes.rb | 5 ++++ db/schema.rb | 32 ++++++++++++++--------- 10 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 .vs/slnx.sqlite diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 000000000..e69de29bb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9e7adca9f..e0055054e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,9 +9,9 @@ def logged_in? end def require_login - if !logged_in? - redirect_to login_path - end + #if !logged_in? + # redirect_to login_path + #end end def current_user diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 837a478a9..2b362824f 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -11,3 +11,7 @@

ValetBike!

The Public Bike System Northampton Needs.

+ + + + diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index fe823aaa8..ee77daa00 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -21,6 +21,12 @@ + +
diff --git a/app/views/memberships/new.html.erb b/app/views/memberships/new.html.erb index c7ab13974..56760b28e 100644 --- a/app/views/memberships/new.html.erb +++ b/app/views/memberships/new.html.erb @@ -2,3 +2,5 @@

Memberships#new

Find me in app/views/memberships/new.html.erb

+ + diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index e2ecacb9e..a6befd305 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,5 +1,13 @@ -

Login

+

Login

<%=form_tag (sessions_path) do %> <%=text_field_tag :email %> -<%=submit_tag %> -<% end %> \ No newline at end of file +<%=submit_tag "login", class: 'btn btn-primary'%> +<% end %> +
+ +

+Don't have an account? +

+

+ <%= link_to "Create New user", new_user_path, class: 'btn btn-primary' %> +

\ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index d881f3687..6ef06d16b 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,6 +1,6 @@
-

Welcome

-

Sign Up

+

Sign up for Valetbike!

+ <%= form_tag(users_path) do %> @@ -23,7 +23,7 @@
- <%= submit_tag("Sign Up") %> + <%= submit_tag "Sign Up", class: 'btn btn-primary' %>
<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 8f05314da..593df6cff 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,4 +1,5 @@
-

Users#show

+

users#show

Find me in app/views/users/show.html.erb

+ diff --git a/config/routes.rb b/config/routes.rb index 29116a2ba..f5f940ada 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,9 @@ post '/sessions', to: 'sessions#create', as: 'sessions' delete '/sessions', to: 'sessions#destroy' + get '/users/show', to: 'users#show' + + resources :categories do member do #adds delete action since not added by deafult @@ -50,4 +53,6 @@ get 'rentals/destroy' + + end diff --git a/db/schema.rb b/db/schema.rb index f930827ed..de4b59efd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. - ActiveRecord::Schema[7.0].define(version: 2023_11_05_194806) do - create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -20,6 +18,21 @@ t.datetime "updated_at", null: false end + create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "type" + t.float "cost" + t.date "expiration_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "category_id" + end + create_table "payments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "credit_card_info" t.datetime "created_at", null: false @@ -36,19 +49,14 @@ t.datetime "updated_at", null: false end - create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.string "type" - t.float "cost" - t.date "expiration_date" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "category_id" - end - create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.string "name" t.string "address" + t.integer "has_kiosk" + t.integer "needs_maintenance" + t.integer "dock_count" + t.integer "docked_bike_count" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -62,5 +70,5 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false end - + end From 22fec456e5fa947053cab0ad8ea75f8f3f89a1a0 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 7 Nov 2023 11:48:54 -0500 Subject: [PATCH 13/45] Login routes --- Gemfile | 2 +- Gemfile.lock | 2 + app/controllers/application_controller.rb | 14 ++----- app/controllers/sessions_controller.rb | 25 +++++++++-- app/controllers/users_controller.rb | 40 ++++++++---------- app/models/user.rb | 10 ++++- app/views/layouts/application.html.erb | 1 + app/views/sessions/_flash.html.erb | 5 +++ app/views/sessions/menu.html.erb | 2 + app/views/sessions/new.html.erb | 11 ++++- config/routes.rb | 42 +++++++++---------- db/migrate/20231103203007_create_users.rb | 4 +- ...1107032240_add_password_digest_to_users.rb | 5 +++ db/schema.rb | 31 ++++++++------ 14 files changed, 114 insertions(+), 80 deletions(-) create mode 100644 app/views/sessions/_flash.html.erb create mode 100644 app/views/sessions/menu.html.erb create mode 100644 db/migrate/20231107032240_add_password_digest_to_users.rb diff --git a/Gemfile b/Gemfile index 5efe339e6..a350bc5b0 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ gem "redis", "~> 4.0" # gem "kredis" # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] -# gem "bcrypt", "~> 3.1.7" +gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] diff --git a/Gemfile.lock b/Gemfile.lock index 4a4ad4140..5a3beedda 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) + bcrypt (3.1.19) bindex (0.8.1) bootsnap (1.13.0) msgpack (~> 1.2) @@ -228,6 +229,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + bcrypt (~> 3.1.7) bootsnap capybara debug diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9e7adca9f..fe3bdfe9e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,21 +1,13 @@ class ApplicationController < ActionController::Base #declare as helper so accessable to all views - helper_method :current_user - helper_method :logged_in? before_action :require_login - def logged_in? - session[:user_id] - end - def require_login - if !logged_in? - redirect_to login_path - end + redirect_to new_session_path unless session.include? :user_id end + private def current_user - @current_user ||= User.find(session[:user_id]) if - session[:user_id] + @current_user ||= User.find(session[:user_id]) if session[:user_id] end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index a2317ed5d..354e4c692 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,15 +1,32 @@ class SessionsController < ApplicationController + skip_before_action :require_login, only: [:create, :new] + def new + end def create - user = User.find_by(username: params[:gmail_address]) - session[:user_id] = user.id - redirect_to user_path(user) + session_params = params.permit(:email_address, :password) + @user = User.find_by(email_address: session_params[:email_address]) + logger.info("*** #{@user}") + if @user && @user.authenticate(session_params[:password]) + session[:user_id] = @user.id + redirect_to new_user_path + else + flash[:notice] = "Login is invalid!" + redirect_to new_session_path + end end def destroy - session.clear + logger.info("*** Logged out #{cookies[:email_address]}") + flash[:notice] = "You have been signed out!" + + # do logout process here + session[:user_id] = nil + cookies[:user_name] = nil + @current_user = nil + redirect_to login_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9cb72e4c8..bf636c18b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,37 +1,31 @@ class UsersController < ApplicationController - skip_before_action :require_login, only:[:new, :create] #requires login - - def index - @user = User.order(:price) - end def show @user = User.find(params[:id]) end - def new - @user = User.new + def index end - def edit - @user = User.find(params[:id]) + def new + @user = User.new end - def delete - end - def create - @user = User.new({email_address: params[:email_address], - first_name: params[:first_name], - last_name: params[:last_name], - password: params[:password]}) - - puts @user - - if @user.save #if save is sucessful - redirect_to rentals_path + @user = User.new(user_params) + if @user.save + session[:user_id] = @user.id + redirect_to users_path else - render :new + flash[:error] = "Error- please try to create an account again." + redirect_to :new end end -end + + private + + def user_params + params.require(:user).permit(:gmail_address, :password) + end + +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index edf452030..93a298f7a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,8 +1,14 @@ class User < ApplicationRecord + include ActiveModel::SecurePassword + has_secure_password + has_secure_password :recovery_password, validations: false + validates_presence_of :first_name, :last_name, - :email_address, - :password + :email_address validates_uniqueness_of :email_address + + validates :email_address, format: {with: /\A(^@\s)+@(^@\s)+\z/, message: "Email invalid" } + attr_accessor :password_digest, :recovery_password_digest end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index be3097e52..c43e07c96 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,6 +19,7 @@ ValetBike + <%= render partial: 'layouts/navbar' %>
diff --git a/app/views/sessions/_flash.html.erb b/app/views/sessions/_flash.html.erb new file mode 100644 index 000000000..db68cc6a5 --- /dev/null +++ b/app/views/sessions/_flash.html.erb @@ -0,0 +1,5 @@ +<% if flash[:notice].present? %> +
+ <%= flash[:notice] %> +
+<% end %> \ No newline at end of file diff --git a/app/views/sessions/menu.html.erb b/app/views/sessions/menu.html.erb new file mode 100644 index 000000000..54e09678c --- /dev/null +++ b/app/views/sessions/menu.html.erb @@ -0,0 +1,2 @@ +<%= content_tag :h1, current_user.welcome %> +<%= link_to "Sign out", session_path, method:"delete" %> \ No newline at end of file diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index e2ecacb9e..7a5d94337 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,5 +1,14 @@ +<% if flash[:notice] %> + <%= content_tag :h1, flash[:notice] %> +<% else %> + <%= content_tag :h1, "Please Log in" %> +<% end %> +

Login

<%=form_tag (sessions_path) do %> -<%=text_field_tag :email %> +
+ Username: <%=text_field_tag :email_address %>

+ Password: <%=text_field_tag :password %>
+
<%=submit_tag %> <% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 29116a2ba..eebae6569 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,31 +1,24 @@ Rails.application.routes.draw do - get '/login', to: 'sessions#new', as: 'login' - post '/sessions', to: 'sessions#create', as: 'sessions' - delete '/sessions', to: 'sessions#destroy' - - resources :categories do - member do - #adds delete action since not added by deafult - #optional, can simply destory - get :delete - end - - end + get 'login' => 'sessions#new' + get 'home' => 'home#index' - resources :memberships do - member do - get :delete - end - - end + post 'sessions', to: 'sessions#create', as: 'sessions' + delete 'sessions', to: 'sessions#destroy' + + #Sessions routes + # get '/login', to: 'sessions#new' + # post '/login', to: 'sessions#create' + # post 'logout', to: 'sessions#destroy' + # get 'logout', to: 'sessions#destroy' + + # get 'sign_up', to: 'users#new' + # post 'sing_up', to: 'users#create' - resources :users do - member do - get :delete - end + resources :users, only: [:new, :create, :index, :show] + resources :sessions, only: [:new, :create, :destroy] - end + # end resources :stations, only: [:index] resources :bikes, only: [:index] @@ -51,3 +44,6 @@ end + + + diff --git a/db/migrate/20231103203007_create_users.rb b/db/migrate/20231103203007_create_users.rb index 4cbc1c3cb..478b95e5a 100644 --- a/db/migrate/20231103203007_create_users.rb +++ b/db/migrate/20231103203007_create_users.rb @@ -3,9 +3,9 @@ def change create_table :users do |t| t.string :first_name t.string :last_name - t.string :email_address + t.string :email_address, null: false t.boolean :has_bike - t.string :password + t.string :password_digest t.timestamps end diff --git a/db/migrate/20231107032240_add_password_digest_to_users.rb b/db/migrate/20231107032240_add_password_digest_to_users.rb new file mode 100644 index 000000000..b6b2d5f0d --- /dev/null +++ b/db/migrate/20231107032240_add_password_digest_to_users.rb @@ -0,0 +1,5 @@ +class AddPasswordDigestToUsers < ActiveRecord::Migration[7.0] + def change + add_column :users, :password_digest, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index f930827ed..44cb9ed80 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[7.0].define(version: 2023_11_05_194806) do - +ActiveRecord::Schema[7.0].define(version: 2023_11_07_032240) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -20,6 +18,21 @@ t.datetime "updated_at", null: false end + create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "type" + t.float "cost" + t.date "expiration_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "category_id" + end + create_table "payments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "credit_card_info" t.datetime "created_at", null: false @@ -36,15 +49,6 @@ t.datetime "updated_at", null: false end - create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.string "type" - t.float "cost" - t.date "expiration_date" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "category_id" - end - create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.string "name" @@ -61,6 +65,7 @@ t.string "password" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "password_digest" end - + end From 574e5ee8e7c8c9b7a95806c51047f0cfabf5490e Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 7 Nov 2023 12:07:00 -0500 Subject: [PATCH 14/45] Fixed error with missing amount --- db/migrate/20231105190001_create_payments.rb | 1 - .../20231107165624_add_amount_to_payments.rb | 5 +++ db/schema.rb | 33 +++++++++++-------- 3 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20231107165624_add_amount_to_payments.rb diff --git a/db/migrate/20231105190001_create_payments.rb b/db/migrate/20231105190001_create_payments.rb index b4cc6a01c..16e57249f 100644 --- a/db/migrate/20231105190001_create_payments.rb +++ b/db/migrate/20231105190001_create_payments.rb @@ -2,7 +2,6 @@ class CreatePayments < ActiveRecord::Migration[7.0] def change create_table :payments do |t| t.string :credit_card_info - t.float :amount t.timestamps end diff --git a/db/migrate/20231107165624_add_amount_to_payments.rb b/db/migrate/20231107165624_add_amount_to_payments.rb new file mode 100644 index 000000000..e709bf247 --- /dev/null +++ b/db/migrate/20231107165624_add_amount_to_payments.rb @@ -0,0 +1,5 @@ +class AddAmountToPayments < ActiveRecord::Migration[7.0] + def change + add_column :payments, :amount, :float + end +end diff --git a/db/schema.rb b/db/schema.rb index 00e789f13..a7302a605 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema[7.0].define(version: 2023_11_05_194806) do - +ActiveRecord::Schema[7.0].define(version: 2023_11_07_165624) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -20,11 +18,26 @@ t.datetime "updated_at", null: false end + create_table "categories", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "type" + t.float "cost" + t.date "expiration_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "category_id" + end + create_table "payments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "credit_card_info" - t.float "amount" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.float "amount" end create_table "rentals", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| @@ -37,15 +50,6 @@ t.datetime "updated_at", null: false end - create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.string "type" - t.float "cost" - t.date "expiration_date" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "category_id" - end - create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.string "name" @@ -62,6 +66,7 @@ t.string "password" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "password_digest" end - + end From ce081cf1d712602ac5284b725c146303e7a165d5 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 7 Nov 2023 12:12:45 -0500 Subject: [PATCH 15/45] fixed route to membership --- config/routes.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 7119986b5..5ca23a110 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,25 +1,24 @@ Rails.application.routes.draw do - get '/login', to: 'sessions#new', as: 'login' - post '/sessions', to: 'sessions#create', as: 'sessions' - delete '/sessions', to: 'sessions#destroy' - - get '/users/show', to: 'users#show' - + # get 'login', to: 'sessions#new', as: 'login' + # post 'sessions', to: 'sessions#create', as: 'sessions' + # delete 'sessions', to: 'sessions#destroy' + get 'users/show', to: 'users#show' post 'sessions', to: 'sessions#create', as: 'sessions' delete 'sessions', to: 'sessions#destroy' #Sessions routes - # get '/login', to: 'sessions#new' - # post '/login', to: 'sessions#create' - # post 'logout', to: 'sessions#destroy' - # get 'logout', to: 'sessions#destroy' + get '/login', to: 'sessions#new' + post '/login', to: 'sessions#create' + post 'logout', to: 'sessions#destroy' + get 'logout', to: 'sessions#destroy' # get 'sign_up', to: 'users#new' # post 'sing_up', to: 'users#create' resources :users, only: [:new, :create, :index, :show] + resources :memberships, only: [:new, :create, :index, :show] resources :sessions, only: [:new, :create, :destroy] # end From 1c46975995fa8fa5d2e3f8a98f67aa1835b0f9c2 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 7 Nov 2023 12:14:10 -0500 Subject: [PATCH 16/45] added bcyrpt for password encrpytion --- Gemfile | 2 +- Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5efe339e6..a350bc5b0 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ gem "redis", "~> 4.0" # gem "kredis" # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] -# gem "bcrypt", "~> 3.1.7" +gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] diff --git a/Gemfile.lock b/Gemfile.lock index 4a4ad4140..5a3beedda 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) + bcrypt (3.1.19) bindex (0.8.1) bootsnap (1.13.0) msgpack (~> 1.2) @@ -228,6 +229,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + bcrypt (~> 3.1.7) bootsnap capybara debug From 5593b7712757775f2d12b1b2f37f09193153b503 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 7 Nov 2023 12:49:47 -0500 Subject: [PATCH 17/45] Allow users to either login or signup --- app/controllers/sessions_controller.rb | 4 +-- app/controllers/users_controller.rb | 7 +++- app/views/layouts/_navbar.html.erb | 5 +-- app/views/sessions/new.html.erb | 49 ++++++++++++++++---------- app/views/users/new.html.erb | 8 +++-- config/routes.rb | 4 +-- 6 files changed, 48 insertions(+), 29 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 354e4c692..91c9a7b6e 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,10 +11,10 @@ def create logger.info("*** #{@user}") if @user && @user.authenticate(session_params[:password]) session[:user_id] = @user.id - redirect_to new_user_path + render :user else flash[:notice] = "Login is invalid!" - redirect_to new_session_path + redirect_to login_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bf636c18b..761f8427a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,11 @@ class UsersController < ApplicationController + skip_before_action :require_login, only: [:create, :new] + + #keep login def show - @user = User.find(params[:id]) + @user = User.find(params[:user_id]) + render :current_user end def index @@ -11,6 +15,7 @@ def new @user = User.new end + #Sign-up def create @user = User.new(user_params) if @user.save diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index ee77daa00..45be9c3f4 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -22,10 +22,7 @@ <%= link_to 'Payments', payments_path, class: 'nav-link' %> - diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 9a55232e4..ea9a48291 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,20 +1,33 @@ - -<% if flash[:notice] %> - <%= content_tag :h1, flash[:notice] %> -<% else %> - <%= content_tag :h1, "Please Log in" %> -<% end %> - +

Login

-<%=form_tag (sessions_path) do %> -<%=text_field_tag :email %> -<%=submit_tag "login", class: 'btn btn-primary'%> -<% end %> -
+
+ <% if flash[:notice] %> + <%= content_tag :h1, flash[:notice] %> + <% else %> + <%= content_tag :h1, "Please Log in" %> + <% end %> + + + <%= form_tag(sessions_path) do %> + +
+ + + + + + + + +
+
<%= label_tag(:email_address) %><%= text_field_tag(:email_address, params[:email_address]) %>
<%= label_tag(:password) %><%= password_field_tag(:password) %>
+ +
+ <%= submit_tag "Login in", class: 'btn btn-primary', style: 'color: black;' %> +
+ + <% end %> -

-Don't have an account? -

-

- <%= link_to "Create New user", new_user_path, class: 'btn btn-primary' %> -

+

Don't have an account?

+

<%= link_to "Create New user", new_user_path, class: 'btn btn-primary' %>

+
\ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 6ef06d16b..a4c74fa77 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -2,7 +2,7 @@

Sign up for Valetbike!

- <%= form_tag(users_path) do %> + <%= form_tag @user do %> @@ -13,7 +13,7 @@ - + @@ -26,5 +26,9 @@ <%= submit_tag "Sign Up", class: 'btn btn-primary' %> + +

Do have an account?

+

<%= link_to "Login to Account", login_path, class: 'btn btn-primary' %>

+ <% end %> diff --git a/config/routes.rb b/config/routes.rb index 5ca23a110..352f89bd4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,8 +14,8 @@ post 'logout', to: 'sessions#destroy' get 'logout', to: 'sessions#destroy' - # get 'sign_up', to: 'users#new' - # post 'sing_up', to: 'users#create' + get '/sign_up', to: 'users#new' + post '/sing_up', to: 'users#create' resources :users, only: [:new, :create, :index, :show] resources :memberships, only: [:new, :create, :index, :show] From 920e1a3160ef66f2fff32ac2e1cc3d67e9fdfa80 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 7 Nov 2023 14:13:03 -0500 Subject: [PATCH 18/45] removed dijest attr and got the sign in to work with db --- app/controllers/users_controller.rb | 14 +++++++++----- app/models/user.rb | 3 ++- app/views/sessions/new.html.erb | 2 +- app/views/users/new.html.erb | 8 ++++++-- config/routes.rb | 4 ++-- ...1107184506_remove_password_digest_from_users.rb | 5 +++++ db/schema.rb | 9 ++------- 7 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20231107184506_remove_password_digest_from_users.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 761f8427a..8900b6579 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -12,17 +12,20 @@ def index end def new - @user = User.new + end #Sign-up def create - @user = User.new(user_params) + logger.info("\n\n*****attempting to create new user\n\n") + logger.info("\n\n*****In new #{user_params}\n\n") + @user = User.create(user_params) + logger.info("\n\n*****Set new\n\n") if @user.save session[:user_id] = @user.id - redirect_to users_path + redirect_to login_path else - flash[:error] = "Error- please try to create an account again." + logger.info("\n\n*****Failed\n\n") redirect_to :new end end @@ -30,7 +33,8 @@ def create private def user_params - params.require(:user).permit(:gmail_address, :password) + logger.info("\n\n*****attempting to create new user\n\n") + params.permit(:email_address, :password, :password_confirmation, :first_name, :last_name) end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 93a298f7a..789328617 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,6 @@ class User < ApplicationRecord include ActiveModel::SecurePassword + # EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/ has_secure_password has_secure_password :recovery_password, validations: false @@ -9,6 +10,6 @@ class User < ApplicationRecord validates_uniqueness_of :email_address - validates :email_address, format: {with: /\A(^@\s)+@(^@\s)+\z/, message: "Email invalid" } + # validates :email_address, format: {with: EMAIL_REGEX, message: "Email invalid" } attr_accessor :password_digest, :recovery_password_digest end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index ea9a48291..b75fe8a1b 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -29,5 +29,5 @@ <% end %>

Don't have an account?

-

<%= link_to "Create New user", new_user_path, class: 'btn btn-primary' %>

+

<%= link_to "Create New user", sign_up_path, class: 'btn btn-primary' %>

\ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index a4c74fa77..0124df195 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -14,16 +14,20 @@
- + + + + +
<%= label_tag(:first_name) %><%= text_field_tag(:last_name, params[:last_name]) %>
<%= label_tag(:gmail_address) %><%= label_tag(:email_address) %> <%= text_field_tag(:gmail_address, params[:gmail_address]) %>
<%= label_tag(:email_address) %><%= text_field_tag(:gmail_address, params[:gmail_address]) %><%= text_field_tag(:email_address, params[:email_address]) %>
<%= label_tag(:password) %> <%= password_field_tag(:password) %>
<%= label_tag(:password_confirmation) %><%= password_field_tag(:password_confirmation) %>
- <%= submit_tag "Sign Up", class: 'btn btn-primary' %> + <%= submit_tag "Sign Up", class: 'btn btn-primary', style: 'color: black;' %>
diff --git a/config/routes.rb b/config/routes.rb index 352f89bd4..64304c765 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,9 +15,9 @@ get 'logout', to: 'sessions#destroy' get '/sign_up', to: 'users#new' - post '/sing_up', to: 'users#create' + post '/sign_up', to: 'users#create' - resources :users, only: [:new, :create, :index, :show] + # resources :users, only: [:new, :create, :index, :show] resources :memberships, only: [:new, :create, :index, :show] resources :sessions, only: [:new, :create, :destroy] diff --git a/db/migrate/20231107184506_remove_password_digest_from_users.rb b/db/migrate/20231107184506_remove_password_digest_from_users.rb new file mode 100644 index 000000000..633fc2269 --- /dev/null +++ b/db/migrate/20231107184506_remove_password_digest_from_users.rb @@ -0,0 +1,5 @@ +class RemovePasswordDigestFromUsers < ActiveRecord::Migration[7.0] + def change + remove_column :users, :password_digest, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index cbb3e84db..c349882ff 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_07_032240) do +ActiveRecord::Schema[7.0].define(version: 2023_11_07_184506) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -35,9 +35,9 @@ create_table "payments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "credit_card_info" - t.float "amount" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.float "amount" end create_table "rentals", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| @@ -54,10 +54,6 @@ t.integer "identifier" t.string "name" t.string "address" - t.integer "has_kiosk" - t.integer "needs_maintenance" - t.integer "dock_count" - t.integer "docked_bike_count" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -70,7 +66,6 @@ t.string "password" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "password_digest" end end From 68291047ac16239b27c001f7b61b7c97568ee3de Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 7 Nov 2023 14:59:20 -0500 Subject: [PATCH 19/45] added required create user --- app/controllers/users_controller.rb | 10 +++++++--- app/views/users/new.html.erb | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8900b6579..14773952d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -23,10 +23,14 @@ def create logger.info("\n\n*****Set new\n\n") if @user.save session[:user_id] = @user.id - redirect_to login_path + redirect_to payments_path else - logger.info("\n\n*****Failed\n\n") - redirect_to :new + if @user.email_address.present? + logger.info("\n\n*****Failed, email exists\n\n") + flash[:error] = "Email Exists..." + end + + redirect_to sign_up_path end end diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 0124df195..05b642f96 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,6 +1,11 @@

Sign up for Valetbike!

- +
+ <% if flash[:error] %> + <%= content_tag :h1, flash[:error] %> + <% else %> + <%= content_tag :h1, "Please Log in" %> + <% end %> <%= form_tag @user do %> From 4c8dd0a3e07723e827f488c6f3b7ab5120ce8a67 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Fri, 10 Nov 2023 17:58:54 -0500 Subject: [PATCH 20/45] changed the rake files for stations and bikes to create the association we want --- lib/tasks/import_bikes.rake | 64 ++++++++++++++++----------------- lib/tasks/import_stations.rake | 66 +++++++++++++++++----------------- 2 files changed, 63 insertions(+), 67 deletions(-) diff --git a/lib/tasks/import_bikes.rake b/lib/tasks/import_bikes.rake index 67215d0d4..a59109ae9 100644 --- a/lib/tasks/import_bikes.rake +++ b/lib/tasks/import_bikes.rake @@ -1,38 +1,36 @@ -require_relative '../../config/environment' -require 'csv' -csv_file = 'notes/bike-data.csv' - -namespace :import do - task :bikes => :environment do - - CSV.foreach(csv_file, headers: true) do |row| - Bike.create!( - identifier: row['identifier'], - current_station_id: row['current_station_identifier'], - created_at: row['created_at'], - updated_at: row['updated_at'] - ) +# This task imports bike data from a CSV file +# Use after importing station data +# Usage: rake db:import_bikes["notes/bike-data.csv"] + +namespace :db do + + desc "Import bike data from csv file" + + task :import_bikes, [:filename] => :environment do |task, args| + require 'csv' + + puts "Importing bike data..." + + CSV.parse(File.read(args[:filename]), headers: true).each do |row| + puts "Importing: Bike #{row.to_hash["identifier"]}\n" + import_bike(row.to_hash) end + end + + def import_bike(item) + bike = Bike.new(identifier: item["identifier"]) + bike.current_station = Station.find_by(identifier: item ["current_station_identifier"]) + + if bike.save + puts "Success import of Bike #{item["identifier"]}\n" + else + puts "Failed to import: Bike #{item["identifier"]}\n" + end + + end - puts "Success import of #{csv_file} into **Bike** db." - end end -# csv_text = File.read('notes/bike-data.csv') -# csv = CSV.parse(csv_text, :headers => true) -# csv.each do |row| -# CreateBikes.create!(row.to_hash) -# end - -# namespace :import do -# desc "Import data from stations.csv" -# task :bikes => :environment do -# require 'csv' -# csv_text = File.read('notes/bike-data.csv') - -# CSV.parse(csv_text, headers: true) do |row| -# CreateBikes.create!(row.to_hash) -# end -# end -# end \ No newline at end of file + + diff --git a/lib/tasks/import_stations.rake b/lib/tasks/import_stations.rake index 36ddb8694..1441dde72 100644 --- a/lib/tasks/import_stations.rake +++ b/lib/tasks/import_stations.rake @@ -1,37 +1,35 @@ -require_relative '../../config/environment' -require 'csv' - -csv_file = 'notes/station-data.csv' - -namespace :import do - task :stations => :environment do - csv_data = File.read(csv_file) - csv = CSV.parse(csv_data, headers: true) - - csv.each do |row| - station_data = {} - station_data[:identifier] = row['identifier'] - station_data[:name] = row['name'] - station_data[:address] = row['address'] - station_data[:has_kiosk] = row['has_kiosk'].to_i - station_data[:needs_maintenance] = row['needs_maintenance'].to_i - station_data[:dock_count] = row['dock_count'].to_i - station_data[:docked_bike_count] = row['docked_bike_count'].to_i - - puts "Station Data: #{station_data.inspect}" - - - station = Station.find_by(identifier: station_data[:identifier]) - if station.nil? - # Create a new station - station = Station.create!(station_data) - else - # Update the existing station if needed - station.update!(station_data) - end - +# This task imports bike data from a CSV file +# Use before importing bike data +# Usage: rake db:import_stations["notes/station-data.csv"] + +namespace :db do + + desc "Import station data from csv file" + + task :import_stations, [:filename] => :environment do |task, args| + require 'csv' + + puts "Importing station data..." + + CSV.parse(File.read(args[:filename]), headers: true).each do |row| + puts "Importing: #{row.to_hash["name"]}\n" + import_station(row.to_hash) end + end + + def import_station(item) + station = Station.new({ + identifier: item["identifier"], + name: item["name"], + address: item["address"]}) + + if station.save + puts "Successfully imported: #{item["name"]}\n" + else + puts "Failed to import: #{item["name"]}\n" + end + + end - puts "Success import of #{csv_file} into **Station** db." - end end + From b00d88594a0a6806d680e0766d79eb6f9e613d50 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Fri, 10 Nov 2023 18:20:55 -0500 Subject: [PATCH 21/45] validate rental fields, error flash not working --- app/controllers/rentals_controller.rb | 9 +++++---- app/models/rental.rb | 4 ++++ app/views/rentals/_row.html.erb | 2 +- app/views/rentals/index.html.erb | 4 ++++ app/views/rentals/new.html.erb | 10 +++++++--- .../20231110223754_remove_identifier_from_rentals.rb | 5 +++++ db/schema.rb | 3 +-- 7 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20231110223754_remove_identifier_from_rentals.rb diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index d6334868e..3262eed81 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -10,14 +10,15 @@ def new end def create - @rental = Rental.new(params.require(:rental).permit(:identifier, :rental_period, :return_by)) + @rental = Rental.new(params.require(:rental).permit(:rental_period, :return_by)) if @rental.save + puts "saved new rental" flash[:success] = "Rental created!" redirect_to rentals_url - flash[:success] = "Rental created for real!" else - flash.now[:error] = "Rental creation failed" - render :new + puts "failed to save new rental" + flash[:error] = "Rental creation failed" + render(action: :new) end end diff --git a/app/models/rental.rb b/app/models/rental.rb index 79e3a65ca..93f306d64 100644 --- a/app/models/rental.rb +++ b/app/models/rental.rb @@ -1,2 +1,6 @@ class Rental < ApplicationRecord + validates_presence_of :rental_period, + :return_by + + end diff --git a/app/views/rentals/_row.html.erb b/app/views/rentals/_row.html.erb index 411596120..8a4e73b47 100644 --- a/app/views/rentals/_row.html.erb +++ b/app/views/rentals/_row.html.erb @@ -1,5 +1,5 @@
flexbox vertical stretch"> - <%= rental.identifier %> + <%= rental.id %> Rental period: <%= rental.rental_period %>

Return by: <%= rental.return_by %> diff --git a/app/views/rentals/index.html.erb b/app/views/rentals/index.html.erb index bb4141aa2..68db72c43 100644 --- a/app/views/rentals/index.html.erb +++ b/app/views/rentals/index.html.erb @@ -5,6 +5,10 @@

+<% if flash[:success] %> + <%= content_tag :h2, flash[:success] %> + <% end %> +

ValetBike!

The Public Bike System Northampton Needs.

diff --git a/app/views/rentals/new.html.erb b/app/views/rentals/new.html.erb index 0be037c26..f264d2ebc 100644 --- a/app/views/rentals/new.html.erb +++ b/app/views/rentals/new.html.erb @@ -1,8 +1,12 @@

Create New Rental

+ + <% if flash[:error] %> + <%= content_tag :h2, flash[:error] %> + <% elsif flash[:success] %> + <%= content_tag :h2, flash[:success] %> + <% end %> + <%= form_with model: @rental, url: rentals_path, method: :post, local:true do |f| %> - - <%= f.label (:identifier) %> - <%= f.text_field (:identifier) %> <%= f.label (:rental_period) %> <%= f.text_field (:rental_period) %> diff --git a/db/migrate/20231110223754_remove_identifier_from_rentals.rb b/db/migrate/20231110223754_remove_identifier_from_rentals.rb new file mode 100644 index 000000000..3c3513985 --- /dev/null +++ b/db/migrate/20231110223754_remove_identifier_from_rentals.rb @@ -0,0 +1,5 @@ +class RemoveIdentifierFromRentals < ActiveRecord::Migration[7.0] + def change + remove_column :rentals, :identifier, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 4eddda3e6..4c8aebe67 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_07_184506) do +ActiveRecord::Schema[7.0].define(version: 2023_11_10_223754) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -41,7 +41,6 @@ end create_table "rentals", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.integer "identifier" t.datetime "rented_at" t.datetime "returned_at" t.integer "rental_period" From 0d0daad51b16acfce464cb06305be44400abd0c1 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Fri, 10 Nov 2023 22:10:00 -0500 Subject: [PATCH 22/45] added changes to stations and bikes --- app/assets/stylesheets/error-messages.css | 20 +++++++++++++++++++ app/assets/stylesheets/pages.css | 17 ++++++++++++++++ app/assets/stylesheets/variables.css | 3 +++ app/controllers/application_controller.rb | 4 ++++ app/controllers/bikes_controller.rb | 7 +++++-- app/controllers/users_controller.rb | 14 +++++-------- app/views/bikes/_row.html.erb | 19 +++--------------- app/views/bikes/index.html.erb | 23 +++++++++++++++++----- app/views/layouts/_error_messages.html.erb | 12 +++++++++++ app/views/layouts/_navbar.html.erb | 23 +++++++++++++++++++--- app/views/layouts/application.html.erb | 1 + app/views/sessions/new.html.erb | 3 +-- app/views/stations/_row.html.erb | 9 ++------- app/views/users/new.html.erb | 22 ++++++++++----------- config/routes.rb | 12 ++--------- 15 files changed, 123 insertions(+), 66 deletions(-) create mode 100644 app/assets/stylesheets/error-messages.css create mode 100644 app/views/layouts/_error_messages.html.erb diff --git a/app/assets/stylesheets/error-messages.css b/app/assets/stylesheets/error-messages.css new file mode 100644 index 000000000..86738f4e4 --- /dev/null +++ b/app/assets/stylesheets/error-messages.css @@ -0,0 +1,20 @@ +/* Error Messages CSS */ +.error-explanation { + background-color: #fed7d7; + border: 1px solid #f98080; + color: #c53030; + padding: 1rem; + border-radius: 0.375rem; + margin-top: 1rem; + } + +.error-list { +list-style-type: disc; +padding-left: 1.25rem; +margin-top: 0.5rem; +} + +.error-message { +font-weight: bold; +} + \ No newline at end of file diff --git a/app/assets/stylesheets/pages.css b/app/assets/stylesheets/pages.css index 16bd64b55..60ad1091b 100644 --- a/app/assets/stylesheets/pages.css +++ b/app/assets/stylesheets/pages.css @@ -26,14 +26,31 @@ line-height: 1.75em; } +.record-row.header { + background: var(--black-color); + color:aliceblue; +} + + .record-row.even { background: var(--medium-white-color); } +.record-row.even.flexbox:hover{ + background: var(--light-black-color); + color:aliceblue; +} + .record-row.odd { background: var(--dark-white-color); } +.record-row.odd.flexbox:hover{ + background: var(--light-black-color); + color:aliceblue; +} + + /***********************************/ /* Responsiveness */ diff --git a/app/assets/stylesheets/variables.css b/app/assets/stylesheets/variables.css index 915c14dd3..67b9f5d5b 100644 --- a/app/assets/stylesheets/variables.css +++ b/app/assets/stylesheets/variables.css @@ -10,4 +10,7 @@ --medium-white-color: #FDFCFD; --white-color: #FFFFFF; + --green-color: #3BD6AF; + --orange-color: #F89356; + } \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fe3bdfe9e..1be456b7e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,10 @@ def require_login redirect_to new_session_path unless session.include? :user_id end + def logged_in? + !current_user.nil? + end + private def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index 4a81f1581..a424682e2 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -1,7 +1,10 @@ class BikesController < ApplicationController def index - @bikes = Bike.all.order(identifier: :asc) - + if params[:reverse].blank? || params[:reverse] == "0" + @bikes = Bike.all.order(identifier: :asc) + else + @bikes = Bike.all.order(identifier: :desc) + end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 14773952d..2ec777d93 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -11,25 +11,21 @@ def show def index end - def new + # def new - end + # end #Sign-up def create logger.info("\n\n*****attempting to create new user\n\n") logger.info("\n\n*****In new #{user_params}\n\n") - @user = User.create(user_params) + @user = User.new(user_params) logger.info("\n\n*****Set new\n\n") if @user.save session[:user_id] = @user.id - redirect_to payments_path + redirect_to root_path else - if @user.email_address.present? - logger.info("\n\n*****Failed, email exists\n\n") - flash[:error] = "Email Exists..." - end - + logger.info("\n\n*****ERRORRRRRRRRR\n\n") redirect_to sign_up_path end end diff --git a/app/views/bikes/_row.html.erb b/app/views/bikes/_row.html.erb index 8288b170a..352b43842 100644 --- a/app/views/bikes/_row.html.erb +++ b/app/views/bikes/_row.html.erb @@ -1,17 +1,4 @@ -
flexbox vertical stretch"> - ID: <%=bike.identifier %> - <%# <% station = Station.find_by(identifier: station_identifier) %> -
flexbox vertical stretch"> - <%# <%= station.address %> - <% station = Station.find_by(identifier: bike.current_station_id) %> - - <% if station.present? %> - Station Name: <%= station.name %>
- Station Address: <%= station.address %> - <% else %> - Station not found - <% end %> - -
- +
flexbox vertical stretch justify-space-between"> +
<%= bike.identifier %>
+
<%= bike.current_station.blank? ? "In Use" : "Docked (#{bike.current_station.address})" %>
\ No newline at end of file diff --git a/app/views/bikes/index.html.erb b/app/views/bikes/index.html.erb index 9ed9a628c..e8c0cce19 100644 --- a/app/views/bikes/index.html.erb +++ b/app/views/bikes/index.html.erb @@ -1,19 +1,32 @@
- <%= link_to 'View Station List', stations_path %> -
+
+ ValetBike Fleet! +
+ + View Stations +
-

Bikes:

-
<% if @bikes.present? %> + +
+ <% if params[:reverse].blank? || params[:reverse] == "0" %> + Sort ⬇ + + <% else %> + Sort ⬆ + + <% end %> +
+ <%= render(partial: "bikes/row", collection: @bikes, as: :bike) %> + <% else %>
No stations found.
<% end %> -
diff --git a/app/views/layouts/_error_messages.html.erb b/app/views/layouts/_error_messages.html.erb new file mode 100644 index 000000000..4934da522 --- /dev/null +++ b/app/views/layouts/_error_messages.html.erb @@ -0,0 +1,12 @@ +<% if object && object.errors.size > 0 %> + logger.log("OKAY so obj exists and there are errors") +
+

<%= pluralize(object.errors.size, 'error') %> prohibited this record from being saved

+

There were problems with the following fields:

+
    + <% object.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+<% end %> diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 45be9c3f4..1cf30bdd1 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -21,9 +21,26 @@ - + <% if logged_in? %> + + <% else %> + + <% end %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c43e07c96..6305db9c2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,6 +26,7 @@ <%= yield %>
+ diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index b75fe8a1b..3529e278c 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -28,6 +28,5 @@ <% end %> -

Don't have an account?

-

<%= link_to "Create New user", sign_up_path, class: 'btn btn-primary' %>

+

New user? <%= link_to "Sign up now!", sign_up_path %>

\ No newline at end of file diff --git a/app/views/stations/_row.html.erb b/app/views/stations/_row.html.erb index 5b06dafca..f753b1c44 100644 --- a/app/views/stations/_row.html.erb +++ b/app/views/stations/_row.html.erb @@ -1,9 +1,4 @@
flexbox vertical stretch"> - <%= station.identifier %>: <%= station.name %> (<%= station.address %>) - <% bikes_in_station = Bike.where(current_station_id: station.identifier) %> - Number of Bikes at Station: <%= bikes_in_station.count %> -
-

Number of Docked Bikes: - <%= Station.find_by(identifier: station.identifier).docked_bike_count%>

- +
<%= station.identifier %>: <%= station.name %> (<%= station.address %>)
+
<%= station.docked_bikes.count %> bikes
\ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 05b642f96..e2550b17d 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,13 +1,13 @@ -
-

Sign up for Valetbike!

+
+

Sign up for Valetbike!


- <% if flash[:error] %> - <%= content_tag :h1, flash[:error] %> - <% else %> - <%= content_tag :h1, "Please Log in" %> - <% end %> + - <%= form_tag @user do %> + <%= form_tag(@user) do |f| %> + + <% if @user.present? %> + <%= render 'layouts/error_messages', user: @user %> + <% end %>
@@ -28,16 +28,14 @@ - +
<%= label_tag(:first_name) %>
<%= label_tag(:password_confirmation) %> <%= password_field_tag(:password_confirmation) %>
<%= submit_tag "Sign Up", class: 'btn btn-primary', style: 'color: black;' %>
- -

Do have an account?

-

<%= link_to "Login to Account", login_path, class: 'btn btn-primary' %>

+

Have an account? <%= link_to "Login now!", login_path %>

<% end %>
diff --git a/config/routes.rb b/config/routes.rb index 64304c765..ac6ca0265 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,18 +1,13 @@ Rails.application.routes.draw do - # get 'login', to: 'sessions#new', as: 'login' - # post 'sessions', to: 'sessions#create', as: 'sessions' - # delete 'sessions', to: 'sessions#destroy' + root 'home#index' #homepage get 'users/show', to: 'users#show' - post 'sessions', to: 'sessions#create', as: 'sessions' - delete 'sessions', to: 'sessions#destroy' #Sessions routes get '/login', to: 'sessions#new' post '/login', to: 'sessions#create' - post 'logout', to: 'sessions#destroy' - get 'logout', to: 'sessions#destroy' + delete 'logout', to: 'sessions#destroy' get '/sign_up', to: 'users#new' post '/sign_up', to: 'users#create' @@ -25,9 +20,6 @@ resources :stations, only: [:index] resources :bikes, only: [:index] - - - root 'home#index' #homepage get 'payments', to: 'payments#index', as: 'payments' post 'payments', to: 'payments#create' From 6ae4c285d8437315323bef76987ee78f7ecef30c Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Fri, 10 Nov 2023 23:18:21 -0500 Subject: [PATCH 23/45] removed uneeded station columns --- app/models/station.rb | 4 ---- db/migrate/20231111041347_remove_attributes_from_stations.rb | 5 +++++ db/schema.rb | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20231111041347_remove_attributes_from_stations.rb diff --git a/app/models/station.rb b/app/models/station.rb index d51a921b2..93f60b9a0 100644 --- a/app/models/station.rb +++ b/app/models/station.rb @@ -2,10 +2,6 @@ class Station < ApplicationRecord validates_presence_of :identifier, :name, :address - attribute :has_kiosk - attribute :needs_maintenance - attribute :dock_count - attribute :docked_bike_count validates_uniqueness_of :identifier diff --git a/db/migrate/20231111041347_remove_attributes_from_stations.rb b/db/migrate/20231111041347_remove_attributes_from_stations.rb new file mode 100644 index 000000000..511050813 --- /dev/null +++ b/db/migrate/20231111041347_remove_attributes_from_stations.rb @@ -0,0 +1,5 @@ +class RemoveAttributesFromStations < ActiveRecord::Migration[7.0] + def change + + end +end diff --git a/db/schema.rb b/db/schema.rb index 4eddda3e6..ffb83206c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_07_184506) do +ActiveRecord::Schema[7.0].define(version: 2023_11_11_041347) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" From 0f4367aa594bef96648e2b771e09930107b3508f Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sat, 11 Nov 2023 01:22:25 -0500 Subject: [PATCH 24/45] User can now log in --- app/controllers/sessions_controller.rb | 7 ++++--- app/controllers/users_controller.rb | 15 +++++++++----- app/helpers/layout_helper.rb | 18 +++++++++++++++++ app/models/user.rb | 1 - app/views/layouts/application.html.erb | 4 ++++ app/views/sessions/new.html.erb | 8 ++------ app/views/users/new.html.erb | 27 +++++++++++--------------- config/routes.rb | 4 ++-- 8 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 app/helpers/layout_helper.rb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 91c9a7b6e..d1ca1db05 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,10 +11,11 @@ def create logger.info("*** #{@user}") if @user && @user.authenticate(session_params[:password]) session[:user_id] = @user.id - render :user + flash[:notice] = "You've successfully Logged In. Thank you." + redirect_to root_path else - flash[:notice] = "Login is invalid!" - redirect_to login_path + flash.now[:alert] = "Login is invalid!" + render :new end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2ec777d93..0091e438d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,11 +9,9 @@ def show end def index + @user = User.find(params[:user_id]) end - # def new - - # end #Sign-up def create @@ -23,10 +21,17 @@ def create logger.info("\n\n*****Set new\n\n") if @user.save session[:user_id] = @user.id - redirect_to root_path + flash[:notice] = "You've successfully submitted. Thank you." + redirect_to rentals_path else logger.info("\n\n*****ERRORRRRRRRRR\n\n") - redirect_to sign_up_path + + flash.now[:alert] ||= "" + @user.errors.full_messages.each do |message| + flash.now[:alert] << message + ". " + puts "#{message}" + end + render sign_up_path end end diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb new file mode 100644 index 000000000..f40eda088 --- /dev/null +++ b/app/helpers/layout_helper.rb @@ -0,0 +1,18 @@ +module LayoutHelper + def display_alerts + if flash[:alert].present? + content_tag(:div, class: "flash", id: "alert") do + content_tag(:div, flash[:alert], class: "text") + end + end + end + + def display_notices + if flash[:notice].present? + content_tag(:div, class: "flash", id: "notice") do + content_tag(:div, flash[:notice], class: "text") + end + end + end + end + \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 789328617..ba95eaa1b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,5 +11,4 @@ class User < ApplicationRecord validates_uniqueness_of :email_address # validates :email_address, format: {with: EMAIL_REGEX, message: "Email invalid" } - attr_accessor :password_digest, :recovery_password_digest end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6305db9c2..7c8119de8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -23,6 +23,10 @@ <%= render partial: 'layouts/navbar' %>
+ <% if logged_in? %> + <% puts "hellllllo" %> + <%end%> + <%= display_notices %> <%= yield %>
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 3529e278c..2a687a812 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,12 +1,8 @@

Login


- <% if flash[:notice] %> - <%= content_tag :h1, flash[:notice] %> - <% else %> - <%= content_tag :h1, "Please Log in" %> - <% end %> - + + <%= display_alerts %> <%= form_tag(sessions_path) do %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index e2550b17d..3d26d3412 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,41 +1,36 @@

Sign up for Valetbike!


- - - <%= form_tag(@user) do |f| %> - - <% if @user.present? %> - <%= render 'layouts/error_messages', user: @user %> - <% end %> -
+ <%= display_alerts %> + <%= form_with url: '/sign_up', method: :post do |form| %> +
- + - + - + - + - +
<%= label_tag(:first_name) %><%= text_field_tag(:first_name, params[:first_name]) %><%= text_field_tag(:first_name, params[:first_name], required: true) %>
<%= label_tag(:last_name) %><%= text_field_tag(:last_name, params[:last_name]) %><%= text_field_tag(:last_name, params[:last_name], required: true) %>
<%= label_tag(:email_address) %><%= text_field_tag(:email_address, params[:email_address]) %><%= text_field_tag(:email_address, params[:email_address], type: 'email', required: true) %>
<%= label_tag(:password) %><%= password_field_tag(:password) %><%= password_field_tag(:password, nil, required: true, minlength: 8) %>
<%= label_tag(:password_confirmation) %><%= password_field_tag(:password_confirmation) %><%= password_field_tag(:password_confirmation, nil, required: true, minlength: 8) %>
- +
<%= submit_tag "Sign Up", class: 'btn btn-primary', style: 'color: black;' %>
- +

Have an account? <%= link_to "Login now!", login_path %>

- <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index ac6ca0265..cf4b85e0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do - root 'home#index' #homepage + root 'stations#index' #homepage get 'users/show', to: 'users#show' @@ -11,7 +11,7 @@ get '/sign_up', to: 'users#new' post '/sign_up', to: 'users#create' - + resources :users # resources :users, only: [:new, :create, :index, :show] resources :memberships, only: [:new, :create, :index, :show] resources :sessions, only: [:new, :create, :destroy] From 181d5e8b7bd73e480b3bf1023f95067e277eaf15 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Sun, 12 Nov 2023 01:01:23 -0500 Subject: [PATCH 25/45] flashesworking entrytypesvalidated formatallflash --- app/controllers/payments_controller.rb | 4 ++-- app/controllers/rentals_controller.rb | 4 +--- app/models/payment.rb | 2 ++ app/models/rental.rb | 2 -- app/views/layouts/_navbar.html.erb | 8 +++++++ app/views/payments/index.html.erb | 15 ++----------- app/views/payments/new.html.erb | 3 ++- app/views/rentals/index.html.erb | 19 ++-------------- app/views/rentals/new.html.erb | 28 +++++++++--------------- app/views/sessions/new.html.erb | 7 +----- app/views/users/new.html.erb | 11 +++------- config/routes.rb | 30 ++++++++++++++------------ 12 files changed, 49 insertions(+), 84 deletions(-) diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 2c0175417..2b5b5f174 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -15,8 +15,8 @@ def create flash[:success] = "Payment complete" redirect_to payments_url else - flash.now[:error] = "Payment failed" - render :new + flash[:error] = "Payment failed" + redirect_to new_payment_path end end diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 3262eed81..02b233d9e 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -12,13 +12,11 @@ def new def create @rental = Rental.new(params.require(:rental).permit(:rental_period, :return_by)) if @rental.save - puts "saved new rental" flash[:success] = "Rental created!" redirect_to rentals_url else - puts "failed to save new rental" flash[:error] = "Rental creation failed" - render(action: :new) + redirect_to new_rental_path end end diff --git a/app/models/payment.rb b/app/models/payment.rb index eab5c2611..7dacef605 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -1,2 +1,4 @@ class Payment < ApplicationRecord + validates :credit_card_info, length: { minimum: 16, maximum: 16 } + validates_presence_of :amount end diff --git a/app/models/rental.rb b/app/models/rental.rb index 93f306d64..1dc4e4e91 100644 --- a/app/models/rental.rb +++ b/app/models/rental.rb @@ -1,6 +1,4 @@ class Rental < ApplicationRecord validates_presence_of :rental_period, :return_by - - end diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 45be9c3f4..7c3cd896e 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -29,3 +29,11 @@
+
+ <% flash.each do |type, msg| %> +
+
+ <%= msg %> +
+ <% end %> +
diff --git a/app/views/payments/index.html.erb b/app/views/payments/index.html.erb index 9ce7e3888..f4616b3e9 100644 --- a/app/views/payments/index.html.erb +++ b/app/views/payments/index.html.erb @@ -1,19 +1,9 @@ - - -
-
-
- -
- -
+

ValetBike!

-

The Public Bike System Northampton Needs.

+

Payments

-

Payments#index

-

Find me in app/views/payments/index.html.erb

<%= link_to "New Payment", new_payment_path, class: 'btn btn-primary' %>

@@ -22,7 +12,6 @@
-

Payments:


<% if @payments.present? %> <%= render(partial: "payments/row", collection: @payments, as: :payment) %> diff --git a/app/views/payments/new.html.erb b/app/views/payments/new.html.erb index df381befe..74182fd59 100644 --- a/app/views/payments/new.html.erb +++ b/app/views/payments/new.html.erb @@ -1,4 +1,5 @@

New Payment

+ <%= form_with model: @payment, url: payments_path, method: :post, local:true do |f| %> <%= f.label (:credit_card_info) %> @@ -9,4 +10,4 @@ <%= f.submit %> -<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/rentals/index.html.erb b/app/views/rentals/index.html.erb index 68db72c43..c85ef9c20 100644 --- a/app/views/rentals/index.html.erb +++ b/app/views/rentals/index.html.erb @@ -1,23 +1,9 @@ -
-
-
- - -
- -<% if flash[:success] %> - <%= content_tag :h2, flash[:success] %> - <% end %> - -
+

ValetBike!

-

The Public Bike System Northampton Needs.

+

Rentals

-
-

Rentals#index

-

Find me in app/views/rentals/index.html.erb

<%= link_to "Create New Rental", new_rental_path, class: 'btn btn-primary' %>

@@ -26,7 +12,6 @@
-

Rentals:


<% if @rentals.present? %> <%= render(partial: "rentals/row", collection: @rentals, as: :rental) %> diff --git a/app/views/rentals/new.html.erb b/app/views/rentals/new.html.erb index f264d2ebc..ff6d7110e 100644 --- a/app/views/rentals/new.html.erb +++ b/app/views/rentals/new.html.erb @@ -1,21 +1,13 @@ -

Create New Rental

+

Create New Rental

- <% if flash[:error] %> - <%= content_tag :h2, flash[:error] %> - <% elsif flash[:success] %> - <%= content_tag :h2, flash[:success] %> - <% end %> +<%= form_with model: @rental, url: rentals_path, method: :post, local:true do |f| %> - <%= form_with model: @rental, url: rentals_path, method: :post, local:true do |f| %> + <%= f.label (:rental_period) %> + <%= f.text_field (:rental_period) %> - <%= f.label (:rental_period) %> - <%= f.text_field (:rental_period) %> - - <%= f.label (:return_by) %> - <%= f.date_field (:return_by) %> - - <%= f.submit %> - - <% end %> - - \ No newline at end of file + <%= f.label (:return_by) %> + <%= f.date_field (:return_by) %> + + <%= f.submit %> + +<% end %> \ No newline at end of file diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index b75fe8a1b..f7db1eb68 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,12 +1,6 @@

Login


- <% if flash[:notice] %> - <%= content_tag :h1, flash[:notice] %> - <% else %> - <%= content_tag :h1, "Please Log in" %> - <% end %> - <%= form_tag(sessions_path) do %> @@ -28,6 +22,7 @@ <% end %> +

Don't have an account?

<%= link_to "Create New user", sign_up_path, class: 'btn btn-primary' %>

\ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 05b642f96..7e6d6c0d3 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,11 +1,6 @@

Sign up for Valetbike!


- <% if flash[:error] %> - <%= content_tag :h1, flash[:error] %> - <% else %> - <%= content_tag :h1, "Please Log in" %> - <% end %> <%= form_tag @user do %>
@@ -35,9 +30,9 @@ <%= submit_tag "Sign Up", class: 'btn btn-primary', style: 'color: black;' %> - -

Do have an account?

-

<%= link_to "Login to Account", login_path, class: 'btn btn-primary' %>

+
+

Do you have an account?

+

<%= link_to "Login", login_path, class: 'btn btn-primary' %>

<% end %> diff --git a/config/routes.rb b/config/routes.rb index 64304c765..4538ee3c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,25 +28,27 @@ root 'home#index' #homepage - - get 'payments', to: 'payments#index', as: 'payments' + + #Payments routes + resources :payments, only: [:index, :new, :create] post 'payments', to: 'payments#create' - get 'payments/new', to: 'payments#new', as: 'new_payment' - get 'payments/:id' , to: 'payments#show', as: 'payment' - get 'payments/update' - get 'payments/edit' - get 'payments/destroy' - get 'rentals', to: 'rentals#index', as: 'rentals' - post 'rentals', to: 'rentals#create' - get 'rentals/new', to: 'rentals#new', as: 'new_rental' - get 'rentals/:id' , to: 'rentals#show', as: 'rental' - get 'rentals/update' - get 'rentals/edit' - get 'rentals/destroy' + # below not set up in the controller...but will need to just add the simple thing to the resources list above + # get 'payments/:id' , to: 'payments#show', as: 'payment' + # get 'payments/update' + # get 'payments/edit' + # get 'payments/destroy' + #Rentals routes + resources :rentals, only: [:index, :new, :create] + post 'rentals', to: 'rentals#create' + # below not set up in the controller...but will need to just add the simple thing to the resources list above + # get 'rentals/:id' , to: 'rentals#show', as: 'rental' + # get 'rentals/update' + # get 'rentals/edit' + # get 'rentals/destroy' end From 8005367e0127f2d229eaf33e39286b1d8a182bd5 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sun, 12 Nov 2023 12:05:26 -0500 Subject: [PATCH 26/45] Fixed double route error --- config/routes.rb | 2 +- db/schema.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 7558261d0..495219938 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,7 +21,7 @@ resources :stations, only: [:index] resources :bikes, only: [:index] - resources :payments, only: [:index, :new, :create] + resources :payments, only: [:new] get 'payments', to: 'payments#index', as: 'payments' post 'payments', to: 'payments#create' diff --git a/db/schema.rb b/db/schema.rb index 4c8aebe67..3bcf4d18e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_10_223754) do +ActiveRecord::Schema[7.0].define(version: 2023_11_11_041347) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" From 6edb2ef7d4f65242be4f85c3c508343d72af50a4 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Mon, 13 Nov 2023 10:56:25 -0500 Subject: [PATCH 27/45] format of all lists the same, navbar logo + color --- app/assets/stylesheets/navbar.css | 5 +++ app/assets/stylesheets/variables.css | 4 +-- app/controllers/payments_controller.rb | 2 +- app/controllers/rentals_controller.rb | 2 +- app/controllers/sessions_controller.rb | 6 ++-- app/controllers/users_controller.rb | 12 +++---- app/views/bikes/index.html.erb | 4 +-- app/views/home/index.html.erb | 18 +++++----- app/views/layouts/_error_messages.html.erb | 1 + app/views/layouts/_navbar.html.erb | 27 ++++++++++++--- app/views/layouts/application.html.erb | 2 +- app/views/payments/index.html.erb | 37 +++++++++++++------- app/views/rentals/index.html.erb | 40 +++++++++++++--------- app/views/sessions/new.html.erb | 5 +-- app/views/stations/index.html.erb | 25 ++++++++++---- app/views/users/new.html.erb | 5 ++- 16 files changed, 123 insertions(+), 72 deletions(-) create mode 100644 app/assets/stylesheets/navbar.css diff --git a/app/assets/stylesheets/navbar.css b/app/assets/stylesheets/navbar.css new file mode 100644 index 000000000..20bd0b903 --- /dev/null +++ b/app/assets/stylesheets/navbar.css @@ -0,0 +1,5 @@ +/* currently does not work...not invoked or something - ryan */ +/* change navbar background color to custom */ +.navbar-custom { + background-color: var(--blue-color); +} \ No newline at end of file diff --git a/app/assets/stylesheets/variables.css b/app/assets/stylesheets/variables.css index 67b9f5d5b..db18335ce 100644 --- a/app/assets/stylesheets/variables.css +++ b/app/assets/stylesheets/variables.css @@ -11,6 +11,6 @@ --white-color: #FFFFFF; --green-color: #3BD6AF; - --orange-color: #F89356; - + --orange-color: #F89356; + --blue-color: #4B719D; } \ No newline at end of file diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 2b5b5f174..409bc7d97 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -12,7 +12,7 @@ def new def create @payment = Payment.new(params.require(:payment).permit(:credit_card_info, :amount)) if @payment.save - flash[:success] = "Payment complete" + flash[:success] = "Payment completed" redirect_to payments_url else flash[:error] = "Payment failed" diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 02b233d9e..f74aaa0fb 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -12,7 +12,7 @@ def new def create @rental = Rental.new(params.require(:rental).permit(:rental_period, :return_by)) if @rental.save - flash[:success] = "Rental created!" + flash[:success] = "Rental created" redirect_to rentals_url else flash[:error] = "Rental creation failed" diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index d1ca1db05..e00517506 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,17 +11,17 @@ def create logger.info("*** #{@user}") if @user && @user.authenticate(session_params[:password]) session[:user_id] = @user.id - flash[:notice] = "You've successfully Logged In. Thank you." + flash[:notice] = "You are now logged in" redirect_to root_path else - flash.now[:alert] = "Login is invalid!" + flash.now[:alert] = "Login information invalid" render :new end end def destroy logger.info("*** Logged out #{cookies[:email_address]}") - flash[:notice] = "You have been signed out!" + flash[:notice] = "You are now signed out" # do logout process here session[:user_id] = nil diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0091e438d..82e3716ed 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,16 +21,16 @@ def create logger.info("\n\n*****Set new\n\n") if @user.save session[:user_id] = @user.id - flash[:notice] = "You've successfully submitted. Thank you." + flash[:notice] = "Welcome to your new account." redirect_to rentals_path else logger.info("\n\n*****ERRORRRRRRRRR\n\n") - flash.now[:alert] ||= "" - @user.errors.full_messages.each do |message| - flash.now[:alert] << message + ". " - puts "#{message}" - end + # flash.now[:alert] ||= "" + # @user.errors.full_messages.each do |message| + # flash.now[:alert] << message + ". " + # puts "#{message}" + # end render sign_up_path end end diff --git a/app/views/bikes/index.html.erb b/app/views/bikes/index.html.erb index e8c0cce19..a01a3f564 100644 --- a/app/views/bikes/index.html.erb +++ b/app/views/bikes/index.html.erb @@ -1,11 +1,9 @@
- ValetBike Fleet! + Bikes
- View Stations -
<% if @bikes.present? %> diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 2b362824f..67db0dc19 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,16 +1,16 @@ - - -
+
+


- - +
+

Home

+
+
+

This is where we should put some About info...or searching for a bike on the map

+ <%= link_to "Refer to the Figma visualization (click here)", "https://www.figma.com/file/jLAscgKzd4HPAfotfuieGu/ValetBike?type=design&node-id=0%3A1&mode=design&t=op9OSiDs7IVGALMT-1" %>
-
-

ValetBike!

-

The Public Bike System Northampton Needs.

-
+ diff --git a/app/views/layouts/_error_messages.html.erb b/app/views/layouts/_error_messages.html.erb index 4934da522..3cbbba477 100644 --- a/app/views/layouts/_error_messages.html.erb +++ b/app/views/layouts/_error_messages.html.erb @@ -1,3 +1,4 @@ +# when ryan was messing around with the flashes, they deleted this file. they restored it after playing around, but may conflict with things <% if object && object.errors.size > 0 %> logger.log("OKAY so obj exists and there are errors")
diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index b936ef8c6..7d861bb90 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -1,9 +1,28 @@ -

@@ -20,7 +17,7 @@
- <%= submit_tag "Login in", class: 'btn btn-primary', style: 'color: black;' %> + <%= submit_tag "Login", class: 'btn btn-primary', style: 'color: black;' %>
<% end %> diff --git a/app/views/stations/index.html.erb b/app/views/stations/index.html.erb index 8b5336f59..95b898f0b 100644 --- a/app/views/stations/index.html.erb +++ b/app/views/stations/index.html.erb @@ -1,17 +1,30 @@ -
+
- <%= link_to 'View Bike List', bikes_path %> -
+
+ Stations +
+
-

Stations:

-
<% if @stations.present? %> + +
+ <% if params[:reverse].blank? || params[:reverse] == "0" %> + Sort ⬇ + + <% else %> + Sort ⬆ + + <% end %> +
+ <%= render(partial: "stations/row", collection: @stations, as: :station) %> + <% else %>
No stations found.
<% end %> +
-
+
\ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index f0eef1852..818df8259 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,8 +1,7 @@
-

Sign up for Valetbike!

+

Create an Account


- <%= display_alerts %> <%= form_with url: '/sign_up', method: :post do |form| %> @@ -33,7 +32,7 @@
-

Do you have an account?

+

Already have an account?

<%= link_to "Login", login_path, class: 'btn btn-primary' %>

<% end %> From 069e696c9b554602263dc259a62cd9f0282f8885 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Tue, 14 Nov 2023 15:33:46 -0500 Subject: [PATCH 28/45] navbarlogo formatpaymentpage titletodo svgsizetodo --- app/assets/images/logo.svg | 14 +++++++ app/assets/stylesheets/navbar.css | 6 ++- app/helpers/layout_helper.rb | 3 +- app/views/layouts/_navbar.html.erb | 21 +++------- app/views/layouts/application.html.erb | 2 - app/views/payments/index.html.erb | 56 +++++++++++++------------- app/views/sessions/new.html.erb | 56 ++++++++++++++------------ config/routes.rb | 2 + 8 files changed, 86 insertions(+), 74 deletions(-) create mode 100644 app/assets/images/logo.svg diff --git a/app/assets/images/logo.svg b/app/assets/images/logo.svg new file mode 100644 index 000000000..7f4121c43 --- /dev/null +++ b/app/assets/images/logo.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/assets/stylesheets/navbar.css b/app/assets/stylesheets/navbar.css index 20bd0b903..41d92dadd 100644 --- a/app/assets/stylesheets/navbar.css +++ b/app/assets/stylesheets/navbar.css @@ -2,4 +2,8 @@ /* change navbar background color to custom */ .navbar-custom { background-color: var(--blue-color); -} \ No newline at end of file + } + + .white-fill { + fill: var(--medium-white-color); + } \ No newline at end of file diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index f40eda088..da5f7b950 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -14,5 +14,4 @@ def display_notices end end end - end - \ No newline at end of file + end \ No newline at end of file diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 7d861bb90..b20a8186c 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -1,26 +1,15 @@ -
+ <% if @payments.present? %> -
- <% if params[:reverse].blank? || params[:reverse] == "0" %> - Sort ⬇ +
+ <% if params[:reverse].blank? || params[:reverse] == "0" %> + Sort ⬇ - <% else %> - Sort ⬆ + <% else %> + Sort ⬆ + + <% end %> +
+ <%= render(partial: "payments/row", collection: @payments, as: :payment) %> + + <% else %> +

+ No payments found. +

<% end %> -
- <%= render(partial: "payments/row", collection: @payments, as: :payment) %> +
- <% else %> -
- No payments found.
- <% end %> -
-
-
\ No newline at end of file + diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 62a4c58e8..35e24018c 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,29 +1,33 @@ -
-

Login

-
- - <%= form_tag(sessions_path) do %> - -
- - - - - - - - -
-
<%= label_tag(:email_address) %><%= text_field_tag(:email_address, params[:email_address]) %>
<%= label_tag(:password) %><%= password_field_tag(:password) %>
- -
- <%= submit_tag "Login", class: 'btn btn-primary', style: 'color: black;' %> +
+
+
+ Login
+
+ <%= form_tag(sessions_path) do %> + +
+ + + + + + + + +
+
<%= label_tag(:email_address) %><%= text_field_tag(:email_address, params[:email_address]) %>
<%= label_tag(:password) %><%= password_field_tag(:password) %>
+
+
+ <%= submit_tag "Login", class: 'btn btn-primary', style: 'color: black;' %> +
- <% end %> - -
-

Don't have an account?

-

<%= link_to "Create New user", sign_up_path, class: 'btn btn-primary' %>

- + <% end %> +
+
+
+

Don't have an account?

+

<%= link_to "Create Account", sign_up_path, class: 'btn btn-primary' %>

+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 495219938..bee4f479e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Rails.application.routes.draw do root 'home#index' #homepage + get 'home', to: 'home#index' + post 'home', to: 'home#index' get 'users/show', to: 'users#show' From 1794057e08b6d3817db42b5a4fd3a12cd51942ae Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 14 Nov 2023 16:59:12 -0500 Subject: [PATCH 29/45] logout works --- app/controllers/application_controller.rb | 1 + app/controllers/sessions_controller.rb | 4 +- app/controllers/users_controller.rb | 6 +-- app/views/layouts/_navbar.html.erb | 49 +++++++++++------------ app/views/layouts/application.html.erb | 2 +- app/views/users/show.html.erb | 2 +- config/routes.rb | 1 + 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1be456b7e..7463dd22f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base def require_login redirect_to new_session_path unless session.include? :user_id + end def logged_in? diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e00517506..ad4fc429c 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,8 +11,8 @@ def create logger.info("*** #{@user}") if @user && @user.authenticate(session_params[:password]) session[:user_id] = @user.id - flash[:notice] = "You are now logged in" - redirect_to root_path + flash[:notice] = "You've successfully Logged In. Thank you." + redirect_to users_show_path else flash.now[:alert] = "Login information invalid" render :new diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 82e3716ed..622d41feb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,12 +4,12 @@ class UsersController < ApplicationController #keep login def show - @user = User.find(params[:user_id]) - render :current_user + @current_user = User.find(session[:user_id]) + render :show end def index - @user = User.find(params[:user_id]) + @current_user = User.find(session[:user_id]) end diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index b20a8186c..3efe6b449 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -17,36 +17,33 @@ + + <% if session[:user_id].present? %> + <% puts "user is logged in" %> + + + + + + <% else %> - - - <% if logged_in? %> - - <% else %> - <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 39a92dc22..bf005e677 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -22,7 +22,7 @@ <%= render partial: 'layouts/navbar' %>
- <% if logged_in? %> + <% if @current_user.present? %> <% puts "hellllllo" %> <%end%> <%= yield %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 593df6cff..c6510b6cf 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,5 +1,5 @@
-

users#show

+

Welcome <%= @current_user.first_name %>

Find me in app/views/users/show.html.erb

diff --git a/config/routes.rb b/config/routes.rb index bee4f479e..ac9252aae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ #Sessions routes get '/login', to: 'sessions#new' post '/login', to: 'sessions#create' + get '/logout', to: 'sessions#destroy' delete 'logout', to: 'sessions#destroy' get '/sign_up', to: 'users#new' From 6bfeefb173c43f1375cd141fb5636e99657c0005 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 14 Nov 2023 17:39:51 -0500 Subject: [PATCH 30/45] changes to user controller --- app/controllers/application_controller.rb | 5 ----- app/controllers/users_controller.rb | 13 ++++++------- app/helpers/layout_helper.rb | 5 ++++- app/views/layouts/application.html.erb | 4 +--- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7463dd22f..fe3bdfe9e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,11 +4,6 @@ class ApplicationController < ActionController::Base def require_login redirect_to new_session_path unless session.include? :user_id - - end - - def logged_in? - !current_user.nil? end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 622d41feb..7c93190c1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -25,13 +25,12 @@ def create redirect_to rentals_path else logger.info("\n\n*****ERRORRRRRRRRR\n\n") - - # flash.now[:alert] ||= "" - # @user.errors.full_messages.each do |message| - # flash.now[:alert] << message + ". " - # puts "#{message}" - # end - render sign_up_path + flash.now[:alert] ||= "" + @user.errors.full_messages.each do |message| + flash.now[:alert] << message + ". " + puts "#{message}" + end + render :new end end diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index da5f7b950..728905b5a 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -1,8 +1,11 @@ module LayoutHelper def display_alerts if flash[:alert].present? + puts "there are alerts" content_tag(:div, class: "flash", id: "alert") do - content_tag(:div, flash[:alert], class: "text") + a = flash[:alert] + puts "The alert is/are " + a + content_tag(:div, a, class: "text") end end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bf005e677..4eb753af5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -22,9 +22,7 @@ <%= render partial: 'layouts/navbar' %>
- <% if @current_user.present? %> - <% puts "hellllllo" %> - <%end%> + <%= display_alerts %> <%= yield %>
From 806c71cdf2dc53c9a1bd26cfdac2f56349d7e1fe Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Tue, 14 Nov 2023 22:54:37 -0500 Subject: [PATCH 31/45] Fixed flash display and add simple css --- app/assets/stylesheets/flash.css | 14 +++++++++ app/assets/stylesheets/form.css | 32 ++++++++++++++++++++ app/assets/stylesheets/variables.css | 1 + app/controllers/sessions_controller.rb | 3 +- app/controllers/users_controller.rb | 11 +++---- app/javascript/application.js | 1 + app/javascript/controllers/flash_messages.js | 11 +++++++ app/views/layouts/_navbar.html.erb | 9 +----- app/views/layouts/application.html.erb | 3 +- 9 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 app/assets/stylesheets/flash.css create mode 100644 app/assets/stylesheets/form.css create mode 100644 app/javascript/controllers/flash_messages.js diff --git a/app/assets/stylesheets/flash.css b/app/assets/stylesheets/flash.css new file mode 100644 index 000000000..4d0ee4958 --- /dev/null +++ b/app/assets/stylesheets/flash.css @@ -0,0 +1,14 @@ +#alert, #notice { + padding: 20px; + color: white; + margin: 0; /* Remove margin to allow full width */ + width: 90%; /* Set width to 100% of the parent element */ +} + +#notice { + background-color: var(--green-color); /* Override color for notice */ +} + +#alert { + background-color: var(--red-color); /* Red for alert, green for notice */ +} diff --git a/app/assets/stylesheets/form.css b/app/assets/stylesheets/form.css new file mode 100644 index 000000000..696b64cef --- /dev/null +++ b/app/assets/stylesheets/form.css @@ -0,0 +1,32 @@ +.form-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 20px; + } + +.form-group { + margin-bottom: 15px; +} + +label { + display: block; + margin-bottom: 5px; + color: var(--light-black-color); + font-weight: bold; +} + +input[type="text"], input[type="password"] { + /* Inherits styles from previous CSS */ + width: 100%; /* Adjust as necessary */ +} + +.form-buttons { + display: flex; + justify-content: center; + margin-top: 20px; +} + + /* Inherits .btn and .btn-primary styles from previous CSS */ + \ No newline at end of file diff --git a/app/assets/stylesheets/variables.css b/app/assets/stylesheets/variables.css index db18335ce..8fdfe8a44 100644 --- a/app/assets/stylesheets/variables.css +++ b/app/assets/stylesheets/variables.css @@ -13,4 +13,5 @@ --green-color: #3BD6AF; --orange-color: #F89356; --blue-color: #4B719D; + --red-color: #e00f0f; } \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index ad4fc429c..8257114c7 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -8,14 +8,13 @@ def new def create session_params = params.permit(:email_address, :password) @user = User.find_by(email_address: session_params[:email_address]) - logger.info("*** #{@user}") if @user && @user.authenticate(session_params[:password]) session[:user_id] = @user.id flash[:notice] = "You've successfully Logged In. Thank you." redirect_to users_show_path else flash.now[:alert] = "Login information invalid" - render :new + render :new, status: 500 end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7c93190c1..135befa9f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -15,22 +15,21 @@ def index #Sign-up def create - logger.info("\n\n*****attempting to create new user\n\n") - logger.info("\n\n*****In new #{user_params}\n\n") + # logger.info("\n\n*****attempting to create new user\n\n") + # logger.info("\n\n*****In new #{user_params}\n\n") @user = User.new(user_params) - logger.info("\n\n*****Set new\n\n") + # logger.info("\n\n*****Set new\n\n") if @user.save session[:user_id] = @user.id flash[:notice] = "Welcome to your new account." redirect_to rentals_path else - logger.info("\n\n*****ERRORRRRRRRRR\n\n") + puts "Can not create user" flash.now[:alert] ||= "" @user.errors.full_messages.each do |message| flash.now[:alert] << message + ". " - puts "#{message}" end - render :new + render :new, status: 500 end end diff --git a/app/javascript/application.js b/app/javascript/application.js index 0d7b49404..5485246f6 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,3 +1,4 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "@hotwired/turbo-rails" import "controllers" + diff --git a/app/javascript/controllers/flash_messages.js b/app/javascript/controllers/flash_messages.js new file mode 100644 index 000000000..db8d762e8 --- /dev/null +++ b/app/javascript/controllers/flash_messages.js @@ -0,0 +1,11 @@ +// window.onload = function() { +// setTimeout(function() { +// var noticeElement = document.getElementById('notice'); +// if (alertElement) { +// alertElement.style.display = 'none'; +// } +// if (noticeElement) { +// noticeElement.style.display = 'none'; +// } +// }, 5000); // 5000 milliseconds = 5 seconds +// }; \ No newline at end of file diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 3efe6b449..851d01bba 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -51,11 +51,4 @@
-
- <% flash.each do |type, msg| %> -
-
- <%= msg %> -
- <% end %> -
+ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4eb753af5..e6d1be105 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,7 +8,6 @@ - <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> @@ -16,6 +15,7 @@ <%= javascript_importmap_tags %> + @@ -23,6 +23,7 @@
<%= display_alerts %> + <%= display_notices %> <%= yield %>
From fdcfa228a056517be94c6edd2606763e4133ece8 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Wed, 15 Nov 2023 11:29:40 -0500 Subject: [PATCH 32/45] sort for all views --- app/controllers/payments_controller.rb | 6 +++++- app/controllers/rentals_controller.rb | 6 +++++- app/controllers/stations_controller.rb | 7 +++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 409bc7d97..dc7585d7b 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -1,6 +1,10 @@ class PaymentsController < ApplicationController def index - @payments = Payment.order(:amount) + if params[:reverse].blank? || params[:reverse] == "0" + @payments = Payment.all.order(id: :asc) + else + @payments = Payment.all.order(id: :desc) + end render :index end diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index f74aaa0fb..1098167ad 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -1,6 +1,10 @@ class RentalsController < ApplicationController def index - @rentals = Rental.order(:rented_at) + if params[:reverse].blank? || params[:reverse] == "0" + @rentals = Rental.all.order(id: :asc) + else + @rentals = Rental.all.order(id: :desc) + end render :index end diff --git a/app/controllers/stations_controller.rb b/app/controllers/stations_controller.rb index 88090af16..2e390606c 100644 --- a/app/controllers/stations_controller.rb +++ b/app/controllers/stations_controller.rb @@ -1,7 +1,10 @@ class StationsController < ApplicationController def index - @stations = Station.all.order(identifier: :asc) + if params[:reverse].blank? || params[:reverse] == "0" + @stations = Station.all.order(identifier: :asc) + else + @stations = Station.all.order(identifier: :desc) + end end - end From 657c5914ca4216a17d1e807e0947d927745b47f7 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Wed, 15 Nov 2023 14:36:37 -0500 Subject: [PATCH 33/45] added search button and added some css --- app/assets/stylesheets/form.css | 6 ++++-- app/controllers/stations_controller.rb | 5 +++++ app/views/stations/index.html.erb | 12 +++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/form.css b/app/assets/stylesheets/form.css index 696b64cef..0c9e01034 100644 --- a/app/assets/stylesheets/form.css +++ b/app/assets/stylesheets/form.css @@ -20,6 +20,7 @@ label { input[type="text"], input[type="password"] { /* Inherits styles from previous CSS */ width: 100%; /* Adjust as necessary */ + color: black; } .form-buttons { @@ -28,5 +29,6 @@ input[type="text"], input[type="password"] { margin-top: 20px; } - /* Inherits .btn and .btn-primary styles from previous CSS */ - \ No newline at end of file +input#search_by_address { + color: black; +} \ No newline at end of file diff --git a/app/controllers/stations_controller.rb b/app/controllers/stations_controller.rb index 88090af16..05bf788b3 100644 --- a/app/controllers/stations_controller.rb +++ b/app/controllers/stations_controller.rb @@ -2,6 +2,11 @@ class StationsController < ApplicationController def index @stations = Station.all.order(identifier: :asc) + + if params[:search_by_address] && params[:search_by_address] != "" + @stations = @stations.where("address LIKE ?", "%#{params[:search_by_address]}%") + end + puts @stations end end diff --git a/app/views/stations/index.html.erb b/app/views/stations/index.html.erb index 95b898f0b..8423383cc 100644 --- a/app/views/stations/index.html.erb +++ b/app/views/stations/index.html.erb @@ -15,14 +15,20 @@ Sort ⬆ <% end %> + + <%= form_tag "/stations", method: "GET" do %> + + <%= text_field_tag :search_by_address, params[:search_by_address], class: "search-control", placeholder: "Search Address" %> + <% end %> +
<%= render(partial: "stations/row", collection: @stations, as: :station) %> <% else %> -
- No stations found. -
+
+ No stations found. +
<% end %>
From 0c2a6d3c4d2816b1c94e20f78691a19c8ec3d64d Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Wed, 15 Nov 2023 17:18:22 -0500 Subject: [PATCH 34/45] rental has user, columns added for that --- app/controllers/rentals_controller.rb | 5 +++++ app/models/rental.rb | 1 + app/models/user.rb | 2 ++ app/views/rentals/_row.html.erb | 1 + db/migrate/20231115165520_add_user_to_rentals.rb | 5 +++++ db/migrate/20231115183533_add_rentals_to_users.rb | 5 +++++ db/migrate/20231115221754_remove_rentedat_from_rentals.rb | 5 +++++ 7 files changed, 24 insertions(+) create mode 100644 db/migrate/20231115165520_add_user_to_rentals.rb create mode 100644 db/migrate/20231115183533_add_rentals_to_users.rb create mode 100644 db/migrate/20231115221754_remove_rentedat_from_rentals.rb diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 1098167ad..15e7a063e 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -15,6 +15,9 @@ def new def create @rental = Rental.new(params.require(:rental).permit(:rental_period, :return_by)) + puts User.find(session[:user_id]) + puts session[:user_id] + @rental.user = User.find(session[:user_id]) if @rental.save flash[:success] = "Rental created" redirect_to rentals_url @@ -38,5 +41,7 @@ def edit def destroy end + private + end diff --git a/app/models/rental.rb b/app/models/rental.rb index 1dc4e4e91..0430584fc 100644 --- a/app/models/rental.rb +++ b/app/models/rental.rb @@ -1,4 +1,5 @@ class Rental < ApplicationRecord validates_presence_of :rental_period, :return_by + belongs_to :user, class_name: :User, foreign_key: :user end diff --git a/app/models/user.rb b/app/models/user.rb index ba95eaa1b..7a15eb112 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,5 +10,7 @@ class User < ApplicationRecord validates_uniqueness_of :email_address + has_many :rentals, class_name: :Rental, foreign_key: :rental + # validates :email_address, format: {with: EMAIL_REGEX, message: "Email invalid" } end diff --git a/app/views/rentals/_row.html.erb b/app/views/rentals/_row.html.erb index 8a4e73b47..162b054a2 100644 --- a/app/views/rentals/_row.html.erb +++ b/app/views/rentals/_row.html.erb @@ -3,5 +3,6 @@ Rental period: <%= rental.rental_period %>

Return by: <%= rental.return_by %> +

User: <%=rental.user.id%>

\ No newline at end of file diff --git a/db/migrate/20231115165520_add_user_to_rentals.rb b/db/migrate/20231115165520_add_user_to_rentals.rb new file mode 100644 index 000000000..3cc3b5c8e --- /dev/null +++ b/db/migrate/20231115165520_add_user_to_rentals.rb @@ -0,0 +1,5 @@ +class AddUserToRentals < ActiveRecord::Migration[7.0] + def change + add_column :rentals, :user, :integer + end +end diff --git a/db/migrate/20231115183533_add_rentals_to_users.rb b/db/migrate/20231115183533_add_rentals_to_users.rb new file mode 100644 index 000000000..1bcc19ea7 --- /dev/null +++ b/db/migrate/20231115183533_add_rentals_to_users.rb @@ -0,0 +1,5 @@ +class AddRentalsToUsers < ActiveRecord::Migration[7.0] + def change + add_column :users, :rental, :integer + end +end diff --git a/db/migrate/20231115221754_remove_rentedat_from_rentals.rb b/db/migrate/20231115221754_remove_rentedat_from_rentals.rb new file mode 100644 index 000000000..d28166f27 --- /dev/null +++ b/db/migrate/20231115221754_remove_rentedat_from_rentals.rb @@ -0,0 +1,5 @@ +class RemoveRentedatFromRentals < ActiveRecord::Migration[7.0] + def change + remove_column :rentals, :rented_at, :datetime + end +end From ede0da94bf148bcb492209372381268686df81db Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Wed, 15 Nov 2023 22:50:51 -0500 Subject: [PATCH 35/45] trying to update association between rental/user --- app/controllers/rentals_controller.rb | 14 +++++++++++--- app/models/user.rb | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 15e7a063e..9ced85ce5 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -15,10 +15,18 @@ def new def create @rental = Rental.new(params.require(:rental).permit(:rental_period, :return_by)) - puts User.find(session[:user_id]) + @current_user = User.find(session[:user_id]) + puts @current_user puts session[:user_id] - @rental.user = User.find(session[:user_id]) - if @rental.save + @rental.user = @current_user + puts @rental.user + puts 'and then...' + + if @rental.save + puts @rental + @current_user.rental = @rental.id + puts @current_user.rental + puts User.find(session[:user_id]).rental flash[:success] = "Rental created" redirect_to rentals_url else diff --git a/app/models/user.rb b/app/models/user.rb index 7a15eb112..741357425 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,7 +10,7 @@ class User < ApplicationRecord validates_uniqueness_of :email_address - has_many :rentals, class_name: :Rental, foreign_key: :rental + has_many :rentals, class_name: :Rental # validates :email_address, format: {with: EMAIL_REGEX, message: "Email invalid" } end From 6ddda7d993b3873b3946c823e0eb26dc6b987c31 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Thu, 16 Nov 2023 16:09:43 -0500 Subject: [PATCH 36/45] has_bikeCantRentMultipleBikes at once. noreturnyet --- app/controllers/rentals_controller.rb | 40 ++++++++++++------- app/controllers/users_controller.rb | 2 + .../20231115183533_add_rentals_to_users.rb | 5 --- ...1115221754_remove_rentedat_from_rentals.rb | 5 --- 4 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 db/migrate/20231115183533_add_rentals_to_users.rb delete mode 100644 db/migrate/20231115221754_remove_rentedat_from_rentals.rb diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 9ced85ce5..16df6562f 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -16,22 +16,34 @@ def new def create @rental = Rental.new(params.require(:rental).permit(:rental_period, :return_by)) @current_user = User.find(session[:user_id]) - puts @current_user - puts session[:user_id] - @rental.user = @current_user - puts @rental.user - puts 'and then...' - - if @rental.save - puts @rental - @current_user.rental = @rental.id - puts @current_user.rental - puts User.find(session[:user_id]).rental - flash[:success] = "Rental created" + puts @current_user.has_bike.nil? + if @current_user.has_bike.nil? + flash[:error] = "Your account has a nil rental currently...setting to false. try again" + @current_user.has_bike=false + @current_user.save + redirect_to new_rental_path + elsif @current_user.has_bike? #if has bike is true + flash[:error] = "Your account has a TRUE rental currently. Cannot rent multiple bikes before returning...that feature soon to be released" redirect_to rentals_url + elsif !@current_user.has_bike #if has bike is false + @current_user.has_bike=true + @current_user.save + @current_user.has_bike = true + @current_user.save + puts @current_user.has_bike? + puts @current_user + puts session[:user_id] + @rental.user = @current_user + puts @rental.user + if @rental.save + flash[:success] = "Rental created" + redirect_to rentals_url + else + flash[:error] = "Rental creation failed" + redirect_to new_rental_path + end else - flash[:error] = "Rental creation failed" - redirect_to new_rental_path + flash[:error] = "Rental creation failed...your rental status is not nil, true, or false. something is majorly wrong" end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 82e3716ed..39d94720f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,6 +21,8 @@ def create logger.info("\n\n*****Set new\n\n") if @user.save session[:user_id] = @user.id + @user.has_bike = false + @user.save flash[:notice] = "Welcome to your new account." redirect_to rentals_path else diff --git a/db/migrate/20231115183533_add_rentals_to_users.rb b/db/migrate/20231115183533_add_rentals_to_users.rb deleted file mode 100644 index 1bcc19ea7..000000000 --- a/db/migrate/20231115183533_add_rentals_to_users.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddRentalsToUsers < ActiveRecord::Migration[7.0] - def change - add_column :users, :rental, :integer - end -end diff --git a/db/migrate/20231115221754_remove_rentedat_from_rentals.rb b/db/migrate/20231115221754_remove_rentedat_from_rentals.rb deleted file mode 100644 index d28166f27..000000000 --- a/db/migrate/20231115221754_remove_rentedat_from_rentals.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RemoveRentedatFromRentals < ActiveRecord::Migration[7.0] - def change - remove_column :rentals, :rented_at, :datetime - end -end From 4d02f799f93ce00554dd608997e3f3d7d9198b6f Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sat, 18 Nov 2023 15:45:16 -0500 Subject: [PATCH 37/45] geolocation done working on calculating distance --- Gemfile | 2 + Gemfile.lock | 2 + app/assets/stylesheets/flash.css | 9 +- app/assets/stylesheets/navbar.css | 39 +++++++- app/assets/stylesheets/pages.css | 7 ++ app/assets/stylesheets/popup.css | 32 +++++++ app/assets/stylesheets/variables.css | 4 +- app/controllers/locations_controller.rb | 78 ++++++++++++++++ app/controllers/stations_controller.rb | 5 + app/helpers/locations_helper.rb | 2 + app/javascript/application.js | 1 + .../controllers/geolocation_controller.js | 31 +++++++ app/models/location.rb | 3 + app/models/station.rb | 3 + app/views/layouts/_navbar.html.erb | 93 +++++++++++-------- app/views/layouts/application.html.erb | 20 ++-- app/views/locations/_form.html.erb | 37 ++++++++ app/views/locations/_location.html.erb | 27 ++++++ app/views/locations/_location.json.jbuilder | 2 + app/views/locations/edit.html.erb | 8 ++ app/views/locations/index.html.erb | 25 +++++ app/views/locations/index.json.jbuilder | 1 + app/views/locations/new.html.erb | 7 ++ app/views/locations/show.html.erb | 12 +++ app/views/locations/show.json.jbuilder | 1 + app/views/stations/_row.html.erb | 13 ++- app/views/stations/index.html.erb | 4 + app/views/stations/show.html.erb | 3 + config/routes.rb | 3 +- db/migrate/20231118192327_create_locations.rb | 14 +++ db/schema.rb | 19 +++- lib/tasks/import_stations.rake | 16 +++- notes/station-data.csv | 12 +-- test/controllers/locations_controller_test.rb | 48 ++++++++++ test/fixtures/locations.yml | 13 +++ test/models/location_test.rb | 7 ++ test/system/locations_test.rb | 47 ++++++++++ 37 files changed, 583 insertions(+), 67 deletions(-) create mode 100644 app/assets/stylesheets/popup.css create mode 100644 app/controllers/locations_controller.rb create mode 100644 app/helpers/locations_helper.rb create mode 100644 app/javascript/controllers/geolocation_controller.js create mode 100644 app/models/location.rb create mode 100644 app/views/locations/_form.html.erb create mode 100644 app/views/locations/_location.html.erb create mode 100644 app/views/locations/_location.json.jbuilder create mode 100644 app/views/locations/edit.html.erb create mode 100644 app/views/locations/index.html.erb create mode 100644 app/views/locations/index.json.jbuilder create mode 100644 app/views/locations/new.html.erb create mode 100644 app/views/locations/show.html.erb create mode 100644 app/views/locations/show.json.jbuilder create mode 100644 app/views/stations/show.html.erb create mode 100644 db/migrate/20231118192327_create_locations.rb create mode 100644 test/controllers/locations_controller_test.rb create mode 100644 test/fixtures/locations.yml create mode 100644 test/models/location_test.rb create mode 100644 test/system/locations_test.rb diff --git a/Gemfile b/Gemfile index a350bc5b0..f83438efe 100644 --- a/Gemfile +++ b/Gemfile @@ -83,3 +83,5 @@ gem 'dotenv-rails' # gem 'paperclip # gem 'uniquify' # gem 'will_paginate' + +gem "geocoder", "~> 1.8" diff --git a/Gemfile.lock b/Gemfile.lock index 5a3beedda..83165da61 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,7 @@ GEM dotenv (= 2.8.1) railties (>= 3.2) erubi (1.11.0) + geocoder (1.8.2) globalid (1.0.0) activesupport (>= 5.0) i18n (1.12.0) @@ -234,6 +235,7 @@ DEPENDENCIES capybara debug dotenv-rails + geocoder (~> 1.8) importmap-rails jbuilder mysql2 (~> 0.5) diff --git a/app/assets/stylesheets/flash.css b/app/assets/stylesheets/flash.css index 4d0ee4958..7279ddfdc 100644 --- a/app/assets/stylesheets/flash.css +++ b/app/assets/stylesheets/flash.css @@ -1,14 +1,19 @@ -#alert, #notice { +.flash{ padding: 20px; color: white; - margin: 0; /* Remove margin to allow full width */ width: 90%; /* Set width to 100% of the parent element */ + opacity: 90%; + margin-left: auto; + margin-right: auto; + } #notice { background-color: var(--green-color); /* Override color for notice */ + border-color: 3px, solid, var(--dark-green-color); } #alert { background-color: var(--red-color); /* Red for alert, green for notice */ + border-color: 3px, solid, var(--dark-green-color); } diff --git a/app/assets/stylesheets/navbar.css b/app/assets/stylesheets/navbar.css index 41d92dadd..075b9e692 100644 --- a/app/assets/stylesheets/navbar.css +++ b/app/assets/stylesheets/navbar.css @@ -1,9 +1,38 @@ /* currently does not work...not invoked or something - ryan */ /* change navbar background color to custom */ -.navbar-custom { - background-color: var(--blue-color); +#navbar { + padding-top: 2%; + padding-bottom: 4%; + z-index: 100; + background-color: var(--blue-color); + height: 5em; +} + +#navbar-content { + height: 3em; + width: 100%; +} + +@media (min-width: 80em){ + #navbar-content { + width: 70em; } + + .logo { + + } +} + - .white-fill { - fill: var(--medium-white-color); - } \ No newline at end of file +.white-fill { + fill: var(--medium-white-color); +} + +.logo { + margin-left: 1em; +} + +.dropdown-menu { + z-index: 1000; /* Adjust the value as needed */ + position: relative; +} \ No newline at end of file diff --git a/app/assets/stylesheets/pages.css b/app/assets/stylesheets/pages.css index 60ad1091b..f2e85b948 100644 --- a/app/assets/stylesheets/pages.css +++ b/app/assets/stylesheets/pages.css @@ -50,6 +50,13 @@ color:aliceblue; } +.fill-block { + display: block; + height: 100%; + width: 100%; + text-decoration: none; +} + /***********************************/ diff --git a/app/assets/stylesheets/popup.css b/app/assets/stylesheets/popup.css new file mode 100644 index 000000000..edc30b656 --- /dev/null +++ b/app/assets/stylesheets/popup.css @@ -0,0 +1,32 @@ +.modal { + position: fixed; + z-index: 1000; + padding: 2em; + + /* Centering */ + left: 50%; + top: 50%; + transform: translate(-50%, -50%); + + overflow: auto; + background-color: rgb(0,0,0); + background-color: rgba(255, 255, 255, 0.1); + border-radius: 5px; + /* Add the drop shadow */ + box-shadow: 0 0 10px 0 rgba(0,0,0,0.2), 0 5px 10px 0 rgba(0,0,0,0.19); +} + +.cancel-button { + background-color: #1530ff; + font-size: 12px; + color: white; + padding: 4px 8px; + border: none; + border-radius: 4px; + cursor: pointer; + float: right; + text-decoration: none; +} +.cancel-button:hover { + background-color: #2640fe; +} \ No newline at end of file diff --git a/app/assets/stylesheets/variables.css b/app/assets/stylesheets/variables.css index 8fdfe8a44..ee122e37e 100644 --- a/app/assets/stylesheets/variables.css +++ b/app/assets/stylesheets/variables.css @@ -11,7 +11,9 @@ --white-color: #FFFFFF; --green-color: #3BD6AF; + --dark-green-color: rgb(23, 84, 4); --orange-color: #F89356; --blue-color: #4B719D; - --red-color: #e00f0f; + --red-color: #db6363; + --dark-red-color: #7e0303; } \ No newline at end of file diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb new file mode 100644 index 000000000..3febffef6 --- /dev/null +++ b/app/controllers/locations_controller.rb @@ -0,0 +1,78 @@ +class LocationsController < ApplicationController + before_action :set_location, only: %i[ show edit update destroy ] + + # GET /locations or /locations.json + def index + if params[:place].present? + @locations = Location.near(params[:place], params[:distance] || 5, order: :distance) + else + @locations = Location.all + end + if !@location.nil? + puts "hello there " + params[:count] = @location.count + end + end + + # GET /locations/1 or /locations/1.json + def show + end + + # GET /locations/new + def new + @location = Location.new + end + + # GET /locations/1/edit + def edit + end + + # POST /locations or /locations.json + def create + @location = Location.new(location_params) + + respond_to do |format| + if @location.save + format.html { redirect_to location_url(@location), notice: "Location was successfully created." } + format.json { render :show, status: :created, location: @location } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @location.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /locations/1 or /locations/1.json + def update + respond_to do |format| + if @location.update(location_params) + format.html { redirect_to location_url(@location), notice: "Location was successfully updated." } + format.json { render :show, status: :ok, location: @location } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @location.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /locations/1 or /locations/1.json + def destroy + @location.destroy + + respond_to do |format| + format.html { redirect_to locations_url, notice: "Location was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_location + @location = Location.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def location_params + params.require(:location).permit(:name, :address, :latitude, :longitude) + end +end diff --git a/app/controllers/stations_controller.rb b/app/controllers/stations_controller.rb index 05bf788b3..bae7365cb 100644 --- a/app/controllers/stations_controller.rb +++ b/app/controllers/stations_controller.rb @@ -8,5 +8,10 @@ def index end puts @stations end + + def show + @station = Station.find_by(identifier: params[:id]) + render :show + end end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb new file mode 100644 index 000000000..46f94288a --- /dev/null +++ b/app/helpers/locations_helper.rb @@ -0,0 +1,2 @@ +module LocationsHelper +end diff --git a/app/javascript/application.js b/app/javascript/application.js index 5485246f6..16ae5d02e 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -2,3 +2,4 @@ import "@hotwired/turbo-rails" import "controllers" + diff --git a/app/javascript/controllers/geolocation_controller.js b/app/javascript/controllers/geolocation_controller.js new file mode 100644 index 000000000..92ab5572a --- /dev/null +++ b/app/javascript/controllers/geolocation_controller.js @@ -0,0 +1,31 @@ +import { Controller } from "@hotwired/stimulus" + +const options = { + enableHighAccuracy: true, + timeout: 5000, + maximumAge: 0 +}; + +// Connects to data-controller="geolocation" +export default class extends Controller { + connect() { + } + + success(pos) { + const crd = pos.coords; + + console.log('Your current position is:'); + console.log(`Latitude : ${crd.latitude}`); + console.log(`Longitude: ${crd.longitude}`); + console.log(`More or less ${crd.accuracy} meters.`); + location.assign(`/locations?place=${crd.latitude},${crd.longitude}`) + } + + error(err) { + console.warn(`ERROR(${err.code}): ${err.message}`); + } + + search () { + navigator.geolocation.getCurrentPosition(this.success, this.error, options); + } +} \ No newline at end of file diff --git a/app/models/location.rb b/app/models/location.rb new file mode 100644 index 000000000..b9c9f488d --- /dev/null +++ b/app/models/location.rb @@ -0,0 +1,3 @@ +class Location < ApplicationRecord + geocoded_by :address +end diff --git a/app/models/station.rb b/app/models/station.rb index 93f60b9a0..58b6f9df4 100644 --- a/app/models/station.rb +++ b/app/models/station.rb @@ -8,3 +8,6 @@ class Station < ApplicationRecord has_many :docked_bikes, class_name: :Bike, foreign_key: :current_station_id end + + + diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 851d01bba..73c61317a 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -1,54 +1,67 @@ - - + +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e6d1be105..51ddf6b29 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,9 +4,14 @@ - - - + + + + + + + + <%= csrf_meta_tags %> <%= csp_meta_tag %> @@ -19,15 +24,18 @@ - <%= render partial: 'layouts/navbar' %> -
-
+ +
+ <%= render partial: 'layouts/navbar' %> +
<%= display_alerts %> <%= display_notices %> + <%= turbo_frame_tag "modal" %> <%= yield %>
+ diff --git a/app/views/locations/_form.html.erb b/app/views/locations/_form.html.erb new file mode 100644 index 000000000..1940cc041 --- /dev/null +++ b/app/views/locations/_form.html.erb @@ -0,0 +1,37 @@ +<%= form_with(model: location, class: "contents") do |form| %> + <% if location.errors.any? %> +
+

<%= pluralize(location.errors.count, "error") %> prohibited this location from being saved:

+ +
    + <% location.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :name %> + <%= form.text_field :name, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.label :address %> + <%= form.text_field :address, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.label :latitude %> + <%= form.text_field :latitude, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.label :longitude %> + <%= form.text_field :longitude, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+<% end %> diff --git a/app/views/locations/_location.html.erb b/app/views/locations/_location.html.erb new file mode 100644 index 000000000..1cf383386 --- /dev/null +++ b/app/views/locations/_location.html.erb @@ -0,0 +1,27 @@ +
+

+ Name: + <%= location.name %> +

+ +

+ Address: + <%= location.address %> +

+ +

+ Latitude: + <%= location.latitude %> +

+ +

+ Longitude: + <%= location.longitude %> +

+ + <% if action_name != "show" %> + <%= link_to "Show this location", location, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to 'Edit this location', edit_location_path(location), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> +
+ <% end %> +
diff --git a/app/views/locations/_location.json.jbuilder b/app/views/locations/_location.json.jbuilder new file mode 100644 index 000000000..a15c32a0a --- /dev/null +++ b/app/views/locations/_location.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! location, :id, :name, :address, :latitude, :longitude, :created_at, :updated_at +json.url location_url(location, format: :json) diff --git a/app/views/locations/edit.html.erb b/app/views/locations/edit.html.erb new file mode 100644 index 000000000..3b050c7c1 --- /dev/null +++ b/app/views/locations/edit.html.erb @@ -0,0 +1,8 @@ +
+

Editing location

+ + <%= render "form", location: @location %> + + <%= link_to "Show this location", @location, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Back to locations", locations_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb new file mode 100644 index 000000000..5a2f76cf7 --- /dev/null +++ b/app/views/locations/index.html.erb @@ -0,0 +1,25 @@ +
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + +
+

Locationsssss

+ +
+ + <%= form_with url: locations_path, method: :get do |form| %> + <%= form.text_field :place, value: params[:place]%> + <%= form.select :distance, [1, 5, 10]%> + <%= form.submit %> + <% end %> + + <% if params[:count].present? %> + <%= params[:count] %> + <% end %> + + +
+ <%= render @locations %> +
+
diff --git a/app/views/locations/index.json.jbuilder b/app/views/locations/index.json.jbuilder new file mode 100644 index 000000000..4644857c3 --- /dev/null +++ b/app/views/locations/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @locations, partial: "locations/location", as: :location diff --git a/app/views/locations/new.html.erb b/app/views/locations/new.html.erb new file mode 100644 index 000000000..f182294d6 --- /dev/null +++ b/app/views/locations/new.html.erb @@ -0,0 +1,7 @@ +
+

New location

+ + <%= render "form", location: @location %> + + <%= link_to 'Back to locations', locations_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb new file mode 100644 index 000000000..23570c055 --- /dev/null +++ b/app/views/locations/show.html.erb @@ -0,0 +1,12 @@ +
+
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + + <%= render @location %> + + <%= link_to 'Edit this location', edit_location_path(@location), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to 'Back to locations', locations_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
+
diff --git a/app/views/locations/show.json.jbuilder b/app/views/locations/show.json.jbuilder new file mode 100644 index 000000000..463e4b23a --- /dev/null +++ b/app/views/locations/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "locations/location", location: @location diff --git a/app/views/stations/_row.html.erb b/app/views/stations/_row.html.erb index f753b1c44..128a37dde 100644 --- a/app/views/stations/_row.html.erb +++ b/app/views/stations/_row.html.erb @@ -1,4 +1,9 @@ -
flexbox vertical stretch"> -
<%= station.identifier %>: <%= station.name %> (<%= station.address %>)
-
<%= station.docked_bikes.count %> bikes
-
\ No newline at end of file + +
+
+ <%= station.identifier %>: <%= station.name %> (<%= station.address %>) + <%= station.docked_bikes.count %> bikes + <%= link_to "Select Station", station_path(id: station.identifier), class: "fill-block"%> +
+
+ diff --git a/app/views/stations/index.html.erb b/app/views/stations/index.html.erb index 8423383cc..c6422f2d5 100644 --- a/app/views/stations/index.html.erb +++ b/app/views/stations/index.html.erb @@ -21,6 +21,10 @@ <%= text_field_tag :search_by_address, params[:search_by_address], class: "search-control", placeholder: "Search Address" %> <% end %> +
+ +
+
<%= render(partial: "stations/row", collection: @stations, as: :station) %> diff --git a/app/views/stations/show.html.erb b/app/views/stations/show.html.erb new file mode 100644 index 000000000..992b5d811 --- /dev/null +++ b/app/views/stations/show.html.erb @@ -0,0 +1,3 @@ + + +

Station Selected: <%= @station.name %>

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ac9252aae..b51ff7f4d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :locations root 'home#index' #homepage get 'home', to: 'home#index' @@ -21,7 +22,7 @@ # end - resources :stations, only: [:index] + resources :stations, only: [:index, :show] resources :bikes, only: [:index] resources :payments, only: [:new] diff --git a/db/migrate/20231118192327_create_locations.rb b/db/migrate/20231118192327_create_locations.rb new file mode 100644 index 000000000..06f40bd25 --- /dev/null +++ b/db/migrate/20231118192327_create_locations.rb @@ -0,0 +1,14 @@ +class CreateLocations < ActiveRecord::Migration[7.0] + def change + create_table :locations do |t| + t.string :name + t.string :address + t.float :latitude + t.float :longitude + + t.timestamps + end + add_index :locations, :latitude + add_index :locations, :longitude + end +end diff --git a/db/schema.rb b/db/schema.rb index 3bcf4d18e..75ed547d3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_11_041347) do +ActiveRecord::Schema[7.0].define(version: 2023_11_18_192327) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -24,6 +24,17 @@ t.datetime "updated_at", null: false end + create_table "locations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "name" + t.string "address" + t.float "latitude" + t.float "longitude" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["latitude"], name: "index_locations_on_latitude" + t.index ["longitude"], name: "index_locations_on_longitude" + end + create_table "memberships", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "type" t.float "cost" @@ -47,6 +58,7 @@ t.datetime "return_by" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "user" end create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| @@ -66,6 +78,11 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "password_digest" + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" end end diff --git a/lib/tasks/import_stations.rake b/lib/tasks/import_stations.rake index 1441dde72..bc18c8e31 100644 --- a/lib/tasks/import_stations.rake +++ b/lib/tasks/import_stations.rake @@ -1,6 +1,6 @@ # This task imports bike data from a CSV file # Use before importing bike data -# Usage: rake db:import_stations["notes/station-data.csv"] +# Usage: namespace :db do @@ -23,8 +23,22 @@ namespace :db do name: item["name"], address: item["address"]}) + location = Location.new({ + name: station["name"], + address: station["address"] + }) + + location.geocode + if station.save puts "Successfully imported: #{item["name"]}\n" + + if location.save + puts "Sussessfuly saved geocordinates for #{item["name"]}" + else + puts "Failed to save geocordinates for #{item["name"]}" + end + else puts "Failed to import: #{item["name"]}\n" end diff --git a/notes/station-data.csv b/notes/station-data.csv index 6f147a8a8..a71dd7439 100644 --- a/notes/station-data.csv +++ b/notes/station-data.csv @@ -1,15 +1,15 @@ identifier,name,has_kiosk,needs_maintenance,dock_count,docked_bike_count,address -21,Florence Bank Station,0,0,7,4,19 Meadow Street Florence MA @ Lilly Library +21,Florence Bank Station,0,0,7,4,19 Meadow St Northampton MA 01062 24,Florence Center,0,0,10,2,31 Main Street Florence MA 30,Jackson Street,0,0,16,8,7A-7D Jackson Street Northampton MA 25,Cooley Dickinson Health Care,0,1,14,6,51 Locust Street Northampton MA -29,State St/Mass Central Rail Trail,0,0,10,4,State Street/Mass Central Rail Trail +29,State St/Mass Central Rail Trail,0,0,10,4,1740 Hardwick Rd New Braintree MA 01531 33,Northampton High School,0,0,15,8,380 Elm Street Northampton MA -20,Village Hill/State Hospital,0,0,14,6,Village Hill/State Hospital -26,John M Greene Hall/Smith College,0,0,16,5,1 Chapin Way Northampton MA @ John M. Greene Hall +20,Village Hill/State Hospital,0,0,14,6,1 Prince St Northampton MA 01060 +26,John M Greene Hall/Smith College,0,0,16,5,60 Elm St Northampton MA 01060 23,Forbes Library,0,0,13,6,20 West Street Northampton MA -27,Pulaski Park/Downtown,1,0,11,3,274 Main Street Northampton MA at Pulaski Park +27,Pulaski Park/Downtown,1,0,11,3,240 Main St Northampton MA 01060 31,Main Street/Court House,0,1,10,3,99 Main Street Northampton MA 28,Northampton Train Station,1,0,13,5,Northampton Train Station 32,Main Street/Bridge Street,0,0,15,8,1 Bridge Street Northampton MA -22,YMCA/Childs Park,0,0,17,8,YMCA/Childs Park \ No newline at end of file +22,YMCA/Childs Park,0,0,17,8,71 N Elm St Northampton MA 01060 \ No newline at end of file diff --git a/test/controllers/locations_controller_test.rb b/test/controllers/locations_controller_test.rb new file mode 100644 index 000000000..98a2973af --- /dev/null +++ b/test/controllers/locations_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class LocationsControllerTest < ActionDispatch::IntegrationTest + setup do + @location = locations(:one) + end + + test "should get index" do + get locations_url + assert_response :success + end + + test "should get new" do + get new_location_url + assert_response :success + end + + test "should create location" do + assert_difference("Location.count") do + post locations_url, params: { location: { address: @location.address, latitude: @location.latitude, longitude: @location.longitude, name: @location.name } } + end + + assert_redirected_to location_url(Location.last) + end + + test "should show location" do + get location_url(@location) + assert_response :success + end + + test "should get edit" do + get edit_location_url(@location) + assert_response :success + end + + test "should update location" do + patch location_url(@location), params: { location: { address: @location.address, latitude: @location.latitude, longitude: @location.longitude, name: @location.name } } + assert_redirected_to location_url(@location) + end + + test "should destroy location" do + assert_difference("Location.count", -1) do + delete location_url(@location) + end + + assert_redirected_to locations_url + end +end diff --git a/test/fixtures/locations.yml b/test/fixtures/locations.yml new file mode 100644 index 000000000..b5fad577e --- /dev/null +++ b/test/fixtures/locations.yml @@ -0,0 +1,13 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + address: MyString + latitude: 1.5 + longitude: 1.5 + +two: + name: MyString + address: MyString + latitude: 1.5 + longitude: 1.5 diff --git a/test/models/location_test.rb b/test/models/location_test.rb new file mode 100644 index 000000000..3c813e8ff --- /dev/null +++ b/test/models/location_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class LocationTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/locations_test.rb b/test/system/locations_test.rb new file mode 100644 index 000000000..54078c6ce --- /dev/null +++ b/test/system/locations_test.rb @@ -0,0 +1,47 @@ +require "application_system_test_case" + +class LocationsTest < ApplicationSystemTestCase + setup do + @location = locations(:one) + end + + test "visiting the index" do + visit locations_url + assert_selector "h1", text: "Locations" + end + + test "should create location" do + visit locations_url + click_on "New location" + + fill_in "Address", with: @location.address + fill_in "Latitude", with: @location.latitude + fill_in "Longitude", with: @location.longitude + fill_in "Name", with: @location.name + click_on "Create Location" + + assert_text "Location was successfully created" + click_on "Back" + end + + test "should update Location" do + visit location_url(@location) + click_on "Edit this location", match: :first + + fill_in "Address", with: @location.address + fill_in "Latitude", with: @location.latitude + fill_in "Longitude", with: @location.longitude + fill_in "Name", with: @location.name + click_on "Update Location" + + assert_text "Location was successfully updated" + click_on "Back" + end + + test "should destroy Location" do + visit location_url(@location) + click_on "Destroy this location", match: :first + + assert_text "Location was successfully destroyed" + end +end From 806e759aeef2946b6e7c7d3ec3de1f668233a652 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Sun, 19 Nov 2023 12:12:08 -0500 Subject: [PATCH 38/45] Flashes will now display errors and successes --- app/helpers/layout_helper.rb | 16 ++++++++++++++++ app/views/layouts/application.html.erb | 2 ++ db/schema.rb | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index 728905b5a..582bb14db 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -17,4 +17,20 @@ def display_notices end end end + + def display_errors + if flash[:error].present? + content_tag(:div, class: "flash", id: "error") do + content_tag(:div, flash[:error], class: "text") + end + end + end + + def display_successes + if flash[:success].present? + content_tag(:div, class: "flash", id: "success") do + content_tag(:div, flash[:success], class: "text") + end + end + end end \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e6d1be105..05e90c95d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -24,6 +24,8 @@
<%= display_alerts %> <%= display_notices %> + <%= display_errors %> + <%= display_successes %> <%= yield %>
diff --git a/db/schema.rb b/db/schema.rb index 3bcf4d18e..801223abd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_11_041347) do +ActiveRecord::Schema[7.0].define(version: 2023_11_15_165520) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -47,6 +47,7 @@ t.datetime "return_by" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "user" end create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| From a9ecffaaa04f3cf9a1338d28708a4a58cc5aa42a Mon Sep 17 00:00:00 2001 From: kemerson-ryan <113268644+kemerson-ryan@users.noreply.github.com> Date: Sun, 19 Nov 2023 12:22:32 -0500 Subject: [PATCH 39/45] Revert "Rentalflashesdisplay" --- app/helpers/layout_helper.rb | 16 ---------------- app/views/layouts/application.html.erb | 2 -- db/schema.rb | 3 +-- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index 582bb14db..728905b5a 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -17,20 +17,4 @@ def display_notices end end end - - def display_errors - if flash[:error].present? - content_tag(:div, class: "flash", id: "error") do - content_tag(:div, flash[:error], class: "text") - end - end - end - - def display_successes - if flash[:success].present? - content_tag(:div, class: "flash", id: "success") do - content_tag(:div, flash[:success], class: "text") - end - end - end end \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 05e90c95d..e6d1be105 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -24,8 +24,6 @@
<%= display_alerts %> <%= display_notices %> - <%= display_errors %> - <%= display_successes %> <%= yield %>
diff --git a/db/schema.rb b/db/schema.rb index 801223abd..3bcf4d18e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_15_165520) do +ActiveRecord::Schema[7.0].define(version: 2023_11_11_041347) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -47,7 +47,6 @@ t.datetime "return_by" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "user" end create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| From e2e120ccff317cd7331e189560b6d285463fce90 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Sun, 19 Nov 2023 12:55:20 -0500 Subject: [PATCH 40/45] rental flashes worknow success and error displayed --- app/controllers/rentals_controller.rb | 16 +++++++++++----- app/models/rental.rb | 2 +- app/models/user.rb | 3 ++- app/views/rentals/_row.html.erb | 19 ++++++++++++++----- app/views/rentals/update.html.erb | 16 ++++++++++++---- config/routes.rb | 4 ++-- ...31119175250_add_current_rental_to_users.rb | 5 +++++ 7 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20231119175250_add_current_rental_to_users.rb diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 16df6562f..8e473b847 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -16,17 +16,17 @@ def new def create @rental = Rental.new(params.require(:rental).permit(:rental_period, :return_by)) @current_user = User.find(session[:user_id]) - puts @current_user.has_bike.nil? if @current_user.has_bike.nil? flash[:error] = "Your account has a nil rental currently...setting to false. try again" @current_user.has_bike=false @current_user.save redirect_to new_rental_path elsif @current_user.has_bike? #if has bike is true - flash[:error] = "Your account has a TRUE rental currently. Cannot rent multiple bikes before returning...that feature soon to be released" + flash[:error] = "You already have an active rental. Cannot rent multiple bikes before returning...that feature soon to be released" redirect_to rentals_url elsif !@current_user.has_bike #if has bike is false @current_user.has_bike=true + @current_user.current_rental=@rental @current_user.save @current_user.has_bike = true @current_user.save @@ -53,6 +53,15 @@ def show end def update + puts "returning rental..." + @current_user = User.find(session[:user_id]) + Rental.find(id: @current_user.current_rental.to_i).returned_at=DateTime.now + puts @current_user.current_rental.returned_at + @current_user.current_rental=nil + puts @current_user.current_rental + @current_rental.has_bike=false + puts @current_rental.has_bike + puts "rental returned...hopefully" end def edit @@ -60,8 +69,5 @@ def edit def destroy end - - private - end diff --git a/app/models/rental.rb b/app/models/rental.rb index 0430584fc..52f6c325f 100644 --- a/app/models/rental.rb +++ b/app/models/rental.rb @@ -1,5 +1,5 @@ class Rental < ApplicationRecord validates_presence_of :rental_period, :return_by - belongs_to :user, class_name: :User, foreign_key: :user + belongs_to :user, class_name: :User, foreign_key: :id, optional:true end diff --git a/app/models/user.rb b/app/models/user.rb index 741357425..15974200d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,7 +10,8 @@ class User < ApplicationRecord validates_uniqueness_of :email_address - has_many :rentals, class_name: :Rental + has_one :current_rental, class_name: :Rental, foreign_key: :id + has_many :rentals, class_name: :Rental, foreign_key: :id # validates :email_address, format: {with: EMAIL_REGEX, message: "Email invalid" } end diff --git a/app/views/rentals/_row.html.erb b/app/views/rentals/_row.html.erb index 162b054a2..e0231de7b 100644 --- a/app/views/rentals/_row.html.erb +++ b/app/views/rentals/_row.html.erb @@ -1,8 +1,17 @@
flexbox vertical stretch"> <%= rental.id %> - Rental period: <%= rental.rental_period %> -
-

Return by: <%= rental.return_by %> -

User: <%=rental.user.id%> - + Rental period: <%= rental.rental_period %> +
+

Return by: <%= rental.return_by %> +

User: <%=rental.user.id%> + <% puts rental.id %> + <% puts User.find(session[:user_id]).current_rental %> + <% if rental.id==User.find(session[:user_id]).current_rental %> + <% puts "current_user.current_rental.id is equal to the rental.id" %> +

+

+ <%= link_to "Return Rental", return_path, class: 'btn btn-primary' %> +

+
+ <%end%>
\ No newline at end of file diff --git a/app/views/rentals/update.html.erb b/app/views/rentals/update.html.erb index 66795b4c0..93836dc4d 100644 --- a/app/views/rentals/update.html.erb +++ b/app/views/rentals/update.html.erb @@ -1,4 +1,12 @@ -
-

Rentals#update

-

Find me in app/views/rentals/update.html.erb

-
+
+
+
+ Return rental +
+
+

+ <%= link_to "Return Rental", return_path, class: 'btn btn-primary' %> +

+
+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ac9252aae..7302e4b5a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,12 +36,12 @@ #Rentals routes - resources :rentals, only: [:index, :new, :create] + resources :rentals, only: [:index, :new, :create, :update] post 'rentals', to: 'rentals#create' + get 'rentals/return', to: 'rentals#update', as: 'return' # below not set up in the controller...but will need to just add the simple thing to the resources list above # get 'rentals/:id' , to: 'rentals#show', as: 'rental' - # get 'rentals/update' # get 'rentals/edit' # get 'rentals/destroy' diff --git a/db/migrate/20231119175250_add_current_rental_to_users.rb b/db/migrate/20231119175250_add_current_rental_to_users.rb new file mode 100644 index 000000000..e30310629 --- /dev/null +++ b/db/migrate/20231119175250_add_current_rental_to_users.rb @@ -0,0 +1,5 @@ +class AddCurrentRentalToUsers < ActiveRecord::Migration[7.0] + def change + add_column :users, :current_rental, :integer + end +end From e6cf5275bef848178cbeb5cb28eab3b406f1d7da Mon Sep 17 00:00:00 2001 From: chel48 Date: Sun, 19 Nov 2023 13:55:34 -0500 Subject: [PATCH 41/45] button class to style all of the buttons, placeholder in payments, validations in rental, different form for rental period --- app/assets/stylesheets/button.css | 5 ++++ app/models/rental.rb | 1 + app/views/payments/_row.html.erb | 2 +- app/views/payments/index.html.erb | 2 +- app/views/payments/new.html.erb | 4 +-- app/views/rentals/index.html.erb | 2 +- app/views/rentals/new.html.erb | 43 ++++++++++++++++++++++++------- app/views/sessions/new.html.erb | 4 +-- 8 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 app/assets/stylesheets/button.css diff --git a/app/assets/stylesheets/button.css b/app/assets/stylesheets/button.css new file mode 100644 index 000000000..9d2756567 --- /dev/null +++ b/app/assets/stylesheets/button.css @@ -0,0 +1,5 @@ + + +.button{ + background-color: rgb(132 204 22); +} \ No newline at end of file diff --git a/app/models/rental.rb b/app/models/rental.rb index 1dc4e4e91..27c4e8eed 100644 --- a/app/models/rental.rb +++ b/app/models/rental.rb @@ -1,4 +1,5 @@ class Rental < ApplicationRecord validates_presence_of :rental_period, :return_by + validates :rental_period, numericality: { only_integer: true } end diff --git a/app/views/payments/_row.html.erb b/app/views/payments/_row.html.erb index 5c7ced441..9a0d7a351 100644 --- a/app/views/payments/_row.html.erb +++ b/app/views/payments/_row.html.erb @@ -2,6 +2,6 @@ <%= payment.id %> Credit card info: <%= payment.credit_card_info %>
-

Amount: <%= payment.amount %> +

Amount: <%= number_to_currency(payment.amount) %>

\ No newline at end of file diff --git a/app/views/payments/index.html.erb b/app/views/payments/index.html.erb index f4616b3e9..4840505b7 100644 --- a/app/views/payments/index.html.erb +++ b/app/views/payments/index.html.erb @@ -5,7 +5,7 @@

- <%= link_to "New Payment", new_payment_path, class: 'btn btn-primary' %> + <%= link_to "New Payment", new_payment_path, class: 'btn button btn-primary' %>

diff --git a/app/views/payments/new.html.erb b/app/views/payments/new.html.erb index 74182fd59..b7dc65350 100644 --- a/app/views/payments/new.html.erb +++ b/app/views/payments/new.html.erb @@ -3,11 +3,11 @@ <%= form_with model: @payment, url: payments_path, method: :post, local:true do |f| %> <%= f.label (:credit_card_info) %> - <%= f.text_field (:credit_card_info) %> + <%= f.text_field (:credit_card_info), placeholder: "0000000000000000" %> <%= f.label (:amount) %> <%= f.text_field (:amount) %> - <%= f.submit %> + <%= f.submit class: "btn button btn-primary"%> <% end %> \ No newline at end of file diff --git a/app/views/rentals/index.html.erb b/app/views/rentals/index.html.erb index c85ef9c20..1ca1a7e45 100644 --- a/app/views/rentals/index.html.erb +++ b/app/views/rentals/index.html.erb @@ -5,7 +5,7 @@

- <%= link_to "Create New Rental", new_rental_path, class: 'btn btn-primary' %> + <%= link_to "Create New Rental", new_rental_path, class: 'btn button btn-primary' %>

diff --git a/app/views/rentals/new.html.erb b/app/views/rentals/new.html.erb index ff6d7110e..cfa22282c 100644 --- a/app/views/rentals/new.html.erb +++ b/app/views/rentals/new.html.erb @@ -1,13 +1,36 @@ -

Create New Rental

+

Create New Rental

-<%= form_with model: @rental, url: rentals_path, method: :post, local:true do |f| %> - <%= f.label (:rental_period) %> - <%= f.text_field (:rental_period) %> +
+ <%= form_with model: @rental, url: rentals_path, method: :post, local:true do |f| %> +
+
- <%= f.label (:return_by) %> - <%= f.date_field (:return_by) %> - - <%= f.submit %> - -<% end %> \ No newline at end of file + + + +<%= f.label (:rental_period) %> +
+ + + + +
+ + + + + + + <%= f.label (:return_by) %> + <%= f.date_field (:return_by) %> + +
+ +
+
+
+ <%= f.submit "Submit", class: "btn button btn-primary"%> + + <% end %> +
\ No newline at end of file diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 353639bfa..1ab1dfa50 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -20,13 +20,13 @@
- <%= submit_tag "Login in", class: 'btn btn-primary', style: 'color: black;' %> + <%= submit_tag "Login in", class: 'btn button btn-primary', style: 'color: black;' %>
<% end %>

Don't have an account?

-

<%= link_to "Create New user", sign_up_path, class: 'btn btn-primary' %>

+

<%= link_to "Create New user", sign_up_path, class: 'btn button btn-primary' %>

\ No newline at end of file From 8bbf4adc44a6962576970021f6bc9cb53bdebac3 Mon Sep 17 00:00:00 2001 From: kemerson-ryan Date: Sun, 19 Nov 2023 14:38:15 -0500 Subject: [PATCH 42/45] to actually display the errors and successes --- app/helpers/layout_helper.rb | 15 +++++++++++++++ app/views/layouts/application.html.erb | 3 +++ 2 files changed, 18 insertions(+) diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index 728905b5a..bb9b712c7 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -17,4 +17,19 @@ def display_notices end end end + def display_errors + if flash[:error].present? + content_tag(:div, class: "flash", id: "error") do + content_tag(:div, flash[:error], class: "text") + end + end + end + + def display_successes + if flash[:success].present? + content_tag(:div, class: "flash", id: "success") do + content_tag(:div, flash[:success], class: "text") + end + end + end end \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e6d1be105..17380df24 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -24,6 +24,9 @@
<%= display_alerts %> <%= display_notices %> + <%= display_errors %> + <%= display_successes %> + <%= yield %>
From ca3e1991201b69f9bb84e77b73af42102be55e4e Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sun, 19 Nov 2023 20:36:44 -0500 Subject: [PATCH 43/45] map basic --- Gemfile | 3 ++ Gemfile.lock | 2 ++ app/javascript/application.js | 5 +++- .../controllers/geolocation_controller.js | 2 ++ app/models/location.rb | 1 + app/views/layouts/application.html.erb | 1 + app/views/locations/_location.html.erb | 2 ++ app/views/locations/index.html.erb | 3 ++ app/views/locations/show.html.erb | 29 ++++++++++++++++++- config/importmap.rb | 1 + config/initializers/mapbox.rb | 2 ++ 11 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 config/initializers/mapbox.rb diff --git a/Gemfile b/Gemfile index f83438efe..6bfc1f339 100644 --- a/Gemfile +++ b/Gemfile @@ -85,3 +85,6 @@ gem 'dotenv-rails' # gem 'will_paginate' gem "geocoder", "~> 1.8" + +# dynamic map +gem "mapkick-rb" diff --git a/Gemfile.lock b/Gemfile.lock index 83165da61..cc0b2c248 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,6 +113,7 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) + mapkick-rb (0.1.5) marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) @@ -238,6 +239,7 @@ DEPENDENCIES geocoder (~> 1.8) importmap-rails jbuilder + mapkick-rb mysql2 (~> 0.5) puma (~> 5.0) rails (~> 7.0.3, >= 7.0.3.1) diff --git a/app/javascript/application.js b/app/javascript/application.js index 16ae5d02e..946ac8d66 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,5 +1,8 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "@hotwired/turbo-rails" import "controllers" +//map +import "mapkick/bundle" - + + diff --git a/app/javascript/controllers/geolocation_controller.js b/app/javascript/controllers/geolocation_controller.js index 92ab5572a..3f3a647e3 100644 --- a/app/javascript/controllers/geolocation_controller.js +++ b/app/javascript/controllers/geolocation_controller.js @@ -28,4 +28,6 @@ export default class extends Controller { search () { navigator.geolocation.getCurrentPosition(this.success, this.error, options); } + + } \ No newline at end of file diff --git a/app/models/location.rb b/app/models/location.rb index b9c9f488d..d86a3a5c9 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,3 +1,4 @@ class Location < ApplicationRecord geocoded_by :address + after_validation :geocode, if: :address_changed? end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 51ddf6b29..e3d3488e3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -18,6 +18,7 @@ <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_importmap_tags %> + diff --git a/app/views/locations/_location.html.erb b/app/views/locations/_location.html.erb index 1cf383386..b0d8be367 100644 --- a/app/views/locations/_location.html.erb +++ b/app/views/locations/_location.html.erb @@ -1,4 +1,6 @@
+ + <%= image_tag "https://api.mapbox.com/styles/v1/mapbox/streets-v12/static/pin-s+555555(#{location.longitude},#{location.latitude})/#{location.longitude},#{location.latitude},13,0/200x200?access_token=pk.eyJ1IjoicGNhbGxlMjAwMyIsImEiOiJjbHA1bXNzeGMwN2t6MnFxazU3cGU1eWgyIn0.S4cnOrUfM5Uh4mbzSCWkJA" %>

Name: <%= location.name %> diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index 5a2f76cf7..f8308a6ba 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -8,6 +8,9 @@

+ + <% js_map [{latitude: 42.3363, longitude: -72.6233}] %> + <%= form_with url: locations_path, method: :get do |form| %> <%= form.text_field :place, value: params[:place]%> <%= form.select :distance, [1, 5, 10]%> diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index 23570c055..cb7f8d4c1 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -8,5 +8,32 @@ <%= link_to 'Edit this location', edit_location_path(@location), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> <%= link_to 'Back to locations', locations_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+ +
+ + +
+ + + +
+
+ Staions nearby <%= @location.name %>: +
    + <% @location.nearbys(0.5).each do |location| %> +
  • + Station: <%= location.name %> + Distance: <%= location.distance_to(@location) %> +
  • +
    + <% end %> +
+ + + + + + + + diff --git a/config/importmap.rb b/config/importmap.rb index 8dce42d40..65ad021a2 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -4,4 +4,5 @@ pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true +pin "mapkick/bundle", to: "mapkick.bundle.js" pin_all_from "app/javascript/controllers", under: "controllers" diff --git a/config/initializers/mapbox.rb b/config/initializers/mapbox.rb new file mode 100644 index 000000000..e059b74ac --- /dev/null +++ b/config/initializers/mapbox.rb @@ -0,0 +1,2 @@ +ENV["MAPBOX_ACCESS_TOKEN"] = "pk.eyJ1IjoicGNhbGxlMjAwMyIsImEiOiJjbHA1bXNzeGMwN2t6MnFxazU3cGU1eWgyIn0.S4cnOrUfM5Uh4mbzSCWkJA" +ENV["MAPS_API_KEY"] = "AIzaSyBjC2E5rdBM0e_deSdd2jnbrw7-DNTeDk4" \ No newline at end of file From 35bde84fb42ae082da306e2dd41c374efd69bca4 Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sun, 19 Nov 2023 20:46:06 -0500 Subject: [PATCH 44/45] nav --- app/assets/stylesheets/navbar.css | 6 +++--- db/schema.rb | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/navbar.css b/app/assets/stylesheets/navbar.css index 41d92dadd..c38b1c8f5 100644 --- a/app/assets/stylesheets/navbar.css +++ b/app/assets/stylesheets/navbar.css @@ -4,6 +4,6 @@ background-color: var(--blue-color); } - .white-fill { - fill: var(--medium-white-color); - } \ No newline at end of file +.white-fill { + fill: var(--medium-white-color); +} \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 3bcf4d18e..918d53ce6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_11_041347) do +ActiveRecord::Schema[7.0].define(version: 2023_11_19_175250) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -47,6 +47,7 @@ t.datetime "return_by" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "user" end create_table "stations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| @@ -66,6 +67,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "password_digest" + t.integer "current_rental" end end From f61e04db900e80d88c90d92375259a8603f972ce Mon Sep 17 00:00:00 2001 From: Paola Calle Date: Sun, 19 Nov 2023 20:48:35 -0500 Subject: [PATCH 45/45] added locations --- app/assets/stylesheets/navbar.css | 2 +- db/schema.rb | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/navbar.css b/app/assets/stylesheets/navbar.css index 075b9e692..36b3c1a55 100644 --- a/app/assets/stylesheets/navbar.css +++ b/app/assets/stylesheets/navbar.css @@ -35,4 +35,4 @@ .dropdown-menu { z-index: 1000; /* Adjust the value as needed */ position: relative; -} \ No newline at end of file +} diff --git a/db/schema.rb b/db/schema.rb index 75ed547d3..81ff0fc38 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_18_192327) do +ActiveRecord::Schema[7.0].define(version: 2023_11_19_175250) do create_table "bikes", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.integer "identifier" t.integer "current_station_id" @@ -78,11 +78,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "password_digest" - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" + t.integer "current_rental" end end