Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@
.tool-versions

# Ignore ENV variable file
.env
.env

#ignore VS Code workspace
valetbike.code-workspace
8 changes: 7 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -223,6 +227,8 @@ GEM

PLATFORMS
arm64-darwin-20
arm64-darwin-23
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand All @@ -249,4 +255,4 @@ RUBY VERSION
ruby 3.1.2p20

BUNDLED WITH
2.3.18
2.5.18
7 changes: 7 additions & 0 deletions app/controllers/bikes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class BikesController < ApplicationController

def index
@bikes = Bike.all.order(identifier: :asc)
end

end
4 changes: 4 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class HomeController < ApplicationController
def index
end
end
4 changes: 2 additions & 2 deletions app/controllers/stations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class StationsController < ApplicationController

def index
@stations = Station.all.order(identifier: :asc)
end

end
2 changes: 2 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HomeHelper
end
2 changes: 1 addition & 1 deletion app/models/bike.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/models/station.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/views/bikes/_row.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="record-row <%= cycle "odd", "even", name: "row-cycler" %> flexbox vertical stretch">
<%= bike.identifier %>
<%= Station.find_by(id: bike.current_station_id)&.name %>
</div>
17 changes: 17 additions & 0 deletions app/views/bikes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="page-section flexbox vertical stretch">
<div class="section-inner flexbox vertical stretch">
<div class="section-title">
Welcome to ValetBike!
</div>
<div class="flexbox vertical stretch">
<%= link_to "Click here for list of stations", "/stations" %>
<% if @bikes.present? %>
<%= render(partial: "bikes/row", collection: @bikes, as: :bike) %>
<% else %>
<div class="empty">
No bikes found, stay tuned for further improvements!
</div>
<% end %>
</div>
</div>
</div>
11 changes: 11 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="page-section flexbox vertical stretch">
<div class="section-inner flexbox vertical stretch">
<div class="section-title">
Welcome to ValetBike!
</div>
<div class="flexbox vertical stretch">
<%= link_to "Click here for list of stations", "/stations" %>
<%= link_to "Click here for list of bikes", "/bikes" %>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/stations/_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="record-row <%= cycle "odd", "even", name: "row-cycler" %> flexbox vertical stretch">
<%= station.identifier %>: <%= station.name %> (<%= station.address %>)
<%= station.identifier %>: <%= station.name %> (<%= station.address %>), currently contains <%= station.docked_bikes.count %> bikes
</div>
5 changes: 3 additions & 2 deletions app/views/stations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
<div class="section-inner flexbox vertical stretch">
<div class="section-title">
Welcome to ValetBike!
</div>
</div>
<div class="flexbox vertical stretch">
<%= link_to "Click here for list of bikes", "/bikes" %>
<% if @stations.present? %>
<%= render(partial: "stations/row", collection: @stations, as: :station) %>
<% else %>
<div class="empty">
No stations found.
No stations found, stay tuned for further improvements!
</div>
<% end %>
</div>
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions db/bikes.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
identifier,current_station_id
1234,45
5678,
1773,22
3835,45
8563,1776
6 changes: 6 additions & 0 deletions db/stations.csv
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions lib/tasks/import_bike_csv.rake
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lib/tasks/import_station_csv.rake
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/controllers/home_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class HomeControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end