diff --git a/.gitignore b/.gitignore
index 8ac3419f0..3e5addac6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,4 +37,7 @@
.tool-versions
# Ignore ENV variable file
-.env
\ No newline at end of file
+.env
+
+#ignore VS Code workspace
+valetbike.code-workspace
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
index c3e104938..ef5466895 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -135,6 +135,8 @@ GEM
nio4r (2.5.8)
nokogiri (1.13.8-arm64-darwin)
racc (~> 1.4)
+ nokogiri (1.13.8-x86_64-darwin)
+ racc (~> 1.4)
nokogiri (1.13.8-x86_64-linux)
racc (~> 1.4)
public_suffix (5.0.0)
@@ -194,6 +196,8 @@ GEM
strscan (3.0.4)
tailwindcss-rails (2.0.12-arm64-darwin)
railties (>= 6.0.0)
+ tailwindcss-rails (2.0.12-x86_64-darwin)
+ railties (>= 6.0.0)
tailwindcss-rails (2.0.12-x86_64-linux)
railties (>= 6.0.0)
thor (1.2.1)
@@ -223,6 +227,8 @@ GEM
PLATFORMS
arm64-darwin-20
+ arm64-darwin-23
+ x86_64-darwin-23
x86_64-linux
DEPENDENCIES
@@ -249,4 +255,4 @@ RUBY VERSION
ruby 3.1.2p20
BUNDLED WITH
- 2.3.18
+ 2.5.18
diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb
new file mode 100644
index 000000000..3e4b2aef1
--- /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/controllers/stations_controller.rb b/app/controllers/stations_controller.rb
index 88090af16..94fc9b301 100644
--- a/app/controllers/stations_controller.rb
+++ b/app/controllers/stations_controller.rb
@@ -1,7 +1,7 @@
class StationsController < ApplicationController
-
+
def index
@stations = Station.all.order(identifier: :asc)
end
-
+
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/models/bike.rb b/app/models/bike.rb
index f3648e343..841f84abc 100644
--- a/app/models/bike.rb
+++ b/app/models/bike.rb
@@ -1,7 +1,7 @@
class Bike < ApplicationRecord
validates_presence_of :identifier
validates_uniqueness_of :identifier
-
+
belongs_to :current_station, class_name: :Station, foreign_key: :current_station_id, optional: true
end
diff --git a/app/models/station.rb b/app/models/station.rb
index 64b9eaada..b257bba8c 100644
--- a/app/models/station.rb
+++ b/app/models/station.rb
@@ -3,7 +3,7 @@ class Station < ApplicationRecord
:name,
:address
validates_uniqueness_of :identifier
-
+
has_many :docked_bikes, class_name: :Bike, foreign_key: :current_station_id
-
+
end
diff --git a/app/views/bikes/_row.html.erb b/app/views/bikes/_row.html.erb
new file mode 100644
index 000000000..3761c4164
--- /dev/null
+++ b/app/views/bikes/_row.html.erb
@@ -0,0 +1,4 @@
+
flexbox vertical stretch">
+ <%= bike.identifier %>
+ <%= Station.find_by(id: bike.current_station_id)&.name %>
+
\ 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..f7c646d06
--- /dev/null
+++ b/app/views/bikes/index.html.erb
@@ -0,0 +1,17 @@
+
+
+
+ Welcome to ValetBike!
+
+
+ <%= link_to "Click here for list of stations", "/stations" %>
+ <% if @bikes.present? %>
+ <%= render(partial: "bikes/row", collection: @bikes, as: :bike) %>
+ <% else %>
+
+ No bikes found, stay tuned for further improvements!
+
+ <% end %>
+
+
+
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
new file mode 100644
index 000000000..251043125
--- /dev/null
+++ b/app/views/home/index.html.erb
@@ -0,0 +1,11 @@
+
+
+
+ Welcome to ValetBike!
+
+
+ <%= link_to "Click here for list of stations", "/stations" %>
+ <%= link_to "Click here for list of bikes", "/bikes" %>
+
+
+
\ No newline at end of file
diff --git a/app/views/stations/_row.html.erb b/app/views/stations/_row.html.erb
index 68a74d983..1d8f143ea 100644
--- a/app/views/stations/_row.html.erb
+++ b/app/views/stations/_row.html.erb
@@ -1,3 +1,3 @@
flexbox vertical stretch">
- <%= station.identifier %>: <%= station.name %> (<%= station.address %>)
+ <%= station.identifier %>: <%= station.name %> (<%= station.address %>), currently contains <%= station.docked_bikes.count %> 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..1503f11be 100644
--- a/app/views/stations/index.html.erb
+++ b/app/views/stations/index.html.erb
@@ -2,13 +2,14 @@
Welcome to ValetBike!
-
+
+ <%= link_to "Click here for list of bikes", "/bikes" %>
<% if @stations.present? %>
<%= render(partial: "stations/row", collection: @stations, as: :station) %>
<% else %>
- No stations found.
+ No stations found, stay tuned for further improvements!
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index f1eb0a0d8..1c480ea01 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,3 +1,8 @@
Rails.application.routes.draw do
- root to: "stations#index"
+ root to: "home#index"
+ get "/home", to: "home#index"
+ get "/stations", to: "stations#index"
+ get "/bikes", to: "bikes#index"
+ # root to: "stations#index"
+ # root to: "bikes#index"
end
\ No newline at end of file
diff --git a/db/bikes.csv b/db/bikes.csv
new file mode 100644
index 000000000..74624f3b0
--- /dev/null
+++ b/db/bikes.csv
@@ -0,0 +1,6 @@
+identifier,current_station_id
+1234,45
+5678,
+1773,22
+3835,45
+8563,1776
\ No newline at end of file
diff --git a/db/stations.csv b/db/stations.csv
new file mode 100644
index 000000000..df251e28d
--- /dev/null
+++ b/db/stations.csv
@@ -0,0 +1,6 @@
+identifier,name,address
+45,Neu Station,123 Novel Lane
+99,Ye Olde Statione,101 Historic Way
+1776,White House,1600 Pennsylvania Avenue
+22,Smith College Campus Center,1 Chapin Way
+82,State Street Fruit Store,51 State Street
\ No newline at end of file
diff --git a/lib/tasks/import_bike_csv.rake b/lib/tasks/import_bike_csv.rake
new file mode 100644
index 000000000..be1fde3d4
--- /dev/null
+++ b/lib/tasks/import_bike_csv.rake
@@ -0,0 +1,26 @@
+require 'csv'
+
+desc "Import bikes from csv file"
+task :importbikes => [:environment] do
+
+ file = "db/bikes.csv"
+
+ CSV.foreach(file, :headers => true) do |row|
+ s = Station.find_by(identifier: row[1])
+ if s == nil
+ b = Bike.create(identifier: row[0])
+ else
+ id = s.id
+ b = Bike.create(identifier: row[0], current_station: s)
+ puts "#{s}, #{id}"
+ puts "#{b.identifier}, #{b.current_station_id}, #{b.current_station}"
+ puts "#{b.attributes}"
+ end
+
+ end
+
+end
+ # s = Station.find_by(identifier: row[1])
+ # unless s == nil
+ # b.current_station = s
+ # end
\ No newline at end of file
diff --git a/lib/tasks/import_station_csv.rake b/lib/tasks/import_station_csv.rake
new file mode 100644
index 000000000..1b582b12e
--- /dev/null
+++ b/lib/tasks/import_station_csv.rake
@@ -0,0 +1,12 @@
+require 'csv'
+
+desc "Import stations from csv file"
+task :importstations => [:environment] do
+
+ file = "db/stations.csv"
+
+ CSV.foreach(file, headers: true) do |row|
+ Station.create(identifier: row[0], name: row[1], address: row[2])
+ end
+
+end
\ No newline at end of file
diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb
new file mode 100644
index 000000000..eac0e3360
--- /dev/null
+++ b/test/controllers/home_controller_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class HomeControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end