Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Michael #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
100 changes: 100 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
54 changes: 52 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app/models/buyer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Buyer <ActiveRecord::Base

end
3 changes: 3 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Products <ActiveRecord::Base

end
3 changes: 3 additions & 0 deletions app/models/seller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Seller <ActiveRecord::Base

end
10 changes: 10 additions & 0 deletions db/migrate/20221108072722_create_sellers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateSellers < ActiveRecord::Migration[6.1]
def change
create_table :sellers do |t|
t.string :name
t.text :email
t.text :password
t.timestamps
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20221108072947_create_buyers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateBuyers < ActiveRecord::Migration[6.1]
def change
create_table :buyers do |t|
t.string :name
t.text :email
t.text :password
t.timestamps
end
end
end
31 changes: 31 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2022_11_08_072947) do

create_table "buyers", force: :cascade do |t|
t.string "name"
t.text "email"
t.text "password"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "sellers", force: :cascade do |t|
t.string "name"
t.text "email"
t.text "password"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end