From c2e9bc129851434cdbad0e348f0687f47b4f1234 Mon Sep 17 00:00:00 2001 From: github username Date: Fri, 8 Nov 2019 01:02:35 -0500 Subject: [PATCH] Done. --- app/application.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/application.rb b/app/application.rb index 7e25e25c7..27057addc 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,6 +1,7 @@ class Application @@items = ["Apples","Carrots","Pears"] + @@cart = [] def call(env) resp = Rack::Response.new @@ -13,6 +14,19 @@ def call(env) elsif req.path.match(/search/) search_term = req.params["q"] resp.write handle_search(search_term) + elsif req.path.match(/cart/) #creates a new cart route + @@cart.each do |cart| + resp.write "#{cart}\n" + end + resp.write "Your cart is empty" + elsif req.path.match(/add/) #creates an add route + search_term = req.params["item"] + if @@items.include?(search_term) + @@cart << search_term + resp.write "added #{search_term}" + else + resp.write "We don't have that item" + end else resp.write "Path Not Found" end @@ -27,4 +41,6 @@ def handle_search(search_term) return "Couldn't find #{search_term}" end end + end +