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
52 changes: 26 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ GEM
specs:
ansi (1.5.0)
ast (2.4.2)
diff-lcs (1.4.4)
diff-lcs (1.5.0)
docile (1.4.0)
parallel (1.20.1)
parser (3.0.2.0)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
pg (1.3.5)
rainbow (3.0.0)
regexp_parser (2.1.1)
pg (1.5.3)
rainbow (3.1.1)
regexp_parser (2.8.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.20.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
Expand All @@ -34,10 +34,10 @@ GEM
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
rubocop-ast (1.28.1)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
Expand All @@ -46,13 +46,13 @@ GEM
simplecov
terminal-table
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
terminal-table (3.0.1)
simplecov_json_formatter (0.1.4)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.0.0)
unicode-display_width (2.4.2)

PLATFORMS
ruby
x86_64-darwin-19

DEPENDENCIES
pg (~> 1.3)
Expand All @@ -65,4 +65,4 @@ RUBY VERSION
ruby 3.0.2p107

BUNDLED WITH
2.2.26
2.2.22
108 changes: 108 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
require_relative 'lib/database_connection'
require_relative 'lib/orders_repo'
require_relative 'lib/item_repo.rb'

# We need to give the database name to the method `connect`.
DatabaseConnection.connect('database_orders')

# Perform a SQL query on the database and get the result set.
order_repository = OrderRepository.new
item_repository = ItemRepository.new

class Application
def initialize(io, order_repository, item_repository)
@io = io
@order_repository = order_repository
@item_repository = item_repository
end

def run
@io.puts <<-TEXT
Welcome to the shop management program!
What do you want to do?
1 = list all shop items
2 = create a new item
3 = list all orders
4 = create a new order
TEXT

user_input = @io.gets.chomp

case user_input
when '1'
@io.puts "Here is a list of all shop items:"
@item_repository.all.each do |item|
@io.puts <<-TEXT
Name: #{item.name}
Unit Price: #{item.unit_price}
Quantity: #{item.quantity}
Order ID: #{item.order_id}

TEXT
end

when '2'
@io.puts "Create a new item"
@io.puts "Type name of item:"
name = @io.gets.chomp
@io.puts "Type unit price of item:"
unit_price = @io.gets.chomp
@io.puts "Type quantity:"
quantity = @io.gets.chomp

@item_repository.create(name, unit_price, quantity)

when '3'
@io.puts 'Here is a list of all shop orders:'
@order_repository.all.each do |order|
@io.puts <<-TEXT
Customer Name: #{order.customer_name}
Date of Order: #{order.date_of_order}

TEXT
end

when '4'
@io.puts 'Create a new order'
@io.puts "Type customer name:"
customer_name = @io.gets.chomp
@io.puts "Type date of order"
date_of_order = @io.gets.chomp

@order_repository.create(customer_name, date_of_order)
end
end

if __FILE__ == $0
app = Application.new(
Kernel,
OrderRepository.new,
ItemRepository.new,
)
app.run
end
end

# Print out each record from the result set.

=begin
order_repository.all.each do |order|
p "Customer #{order.customer_name}, made an order #{order.date_of_order}"
end

#item_repository.all.each do |item|
#p ""
#end

order = order_repository.find(1)
puts order.customer_name

RSpec.describe Application do

it 'returns a list of all shop items'
io = double : io
expect(io).to receive(:puts). with("Here is a list of all shop items:")
expect(items_repository).to recieve(:gets).and_return()
end

=end
Empty file added app_spec.rb
Empty file.
Loading