diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..e0e606c --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,100 @@ +GEM + remote: https://rubygems.org/ + specs: + activemodel (6.1.7) + activesupport (= 6.1.7) + activerecord (6.1.7) + activemodel (= 6.1.7) + activesupport (= 6.1.7) + activesupport (6.1.7) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + coderay (1.1.3) + concurrent-ruby (1.1.10) + database_cleaner (2.0.1) + database_cleaner-active_record (~> 2.0.0) + database_cleaner-active_record (2.0.1) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) + diff-lcs (1.5.0) + faker (2.23.0) + i18n (>= 1.8.11, < 2) + ffi (1.15.5) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + listen (3.7.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + method_source (1.0.0) + minitest (5.16.3) + mustermann (2.0.2) + ruby2_keywords (~> 0.0.1) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + rack (2.2.4) + rack-contrib (2.3.0) + rack (~> 2.0) + rack-protection (2.2.2) + rack + rack-test (1.1.0) + rack (>= 1.0, < 3) + rake (13.0.6) + rb-fsevent (0.11.2) + rb-inotify (0.10.1) + ffi (~> 1.0) + require_all (3.0.0) + rerun (0.13.1) + listen (~> 3.0) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + ruby2_keywords (0.0.5) + sinatra (2.2.2) + mustermann (~> 2.0) + rack (~> 2.2) + rack-protection (= 2.2.2) + tilt (~> 2.0) + sinatra-activerecord (2.0.26) + activerecord (>= 4.1) + sinatra (>= 1.0) + sqlite3 (1.5.3-x86_64-linux) + tilt (2.0.11) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + zeitwerk (2.6.5) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + activerecord (~> 6.1) + database_cleaner + faker (~> 2.18) + pry + rack-contrib (~> 2.3) + rack-test (~> 1.1) + rake + require_all + rerun + rspec + sinatra (~> 2.1) + sinatra-activerecord + sqlite3 (~> 1.4) + +BUNDLED WITH + 2.3.19 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cf1fcf2..f795a69 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,55 @@ class ApplicationController < Sinatra::Base - get '/' do # this is the root route of the application (the homepage) but you can have as many routes as you want - {hello: "Just a starting code 😃"}.to_json + set :default_content_type, "application/json" + before do + response.headers["Access-Control-Allow-Origin"]="*" end + + options "*" do + response.headers["Access-Control-Allow-Methods"]="GET,POST,PUT,PATCH,DELETE,OPTIONS" + end + + # to get all buyers + get "/buyers" do + Buyer.all.to_json + end + + # to get all sellers + get "/sellers" do + Seller.all.to_json + end + + +# POST IN buyers + post "/buyers" do + buyers=Buyer.create( + name: params[:name], + email: params[:email], + password: params[:password] + ) + buyers.to_json + end + +# DELETE IN Buyers + delete "/buyers/:id" do + buyers = Buyer.find(params[:id]) + buyers.destroy + {message: "Buyer '#{buyers.name}' has been deleted."}.to_json + end + +# POST in sellers + post "/sellers" do + sellers=Seller.create( + name: params[:name], + email: params[:email], + password: params[:password] + ) + sellers.to_json + end +# DELETE IN SELLERS + delete "/sellers/:id" do + sellers=Seller.find(params[:id]) + sellers.destroy + {message: "seller '#{sellers.name}' has been deleted."}.to_json + end + end \ No newline at end of file diff --git a/app/models/buyer.rb b/app/models/buyer.rb new file mode 100644 index 0000000..3a98619 --- /dev/null +++ b/app/models/buyer.rb @@ -0,0 +1,3 @@ +class Buyer