Skip to content

Commit

Permalink
Run workshop_script (#9)
Browse files Browse the repository at this point in the history
* Run fullstack script

* Run workshop_script

* Fix linters
  • Loading branch information
santiagodiaz authored Aug 7, 2024
1 parent deed66a commit 5442e7b
Show file tree
Hide file tree
Showing 29 changed files with 410 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/admin/categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

ActiveAdmin.register Category do
permit_params :name

filter :id
end
23 changes: 23 additions & 0 deletions app/admin/products.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

ActiveAdmin.register Product do
permit_params :name, :description, :unit_price, :status, :stock, :category_id, :picture

form do |f|
f.inputs do
f.input :category
f.input :name
f.input :description
f.input :unit_price
f.input :status
f.input :stock
f.input :picture, as: :file
end

f.actions

div image_tag @resource.picture if @resource.picture.attached?
end

filter :id
end
1 change: 1 addition & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class ApplicationRecord < ActiveRecord::Base
include ActiveStorageSupport::SupportForBase64
include Ransackable
RANSACK_ATTRIBUTES = ['id'].freeze

self.abstract_class = true
end
4 changes: 4 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Category < ApplicationRecord
end
7 changes: 7 additions & 0 deletions app/models/line_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class LineItem < ApplicationRecord
belongs_to :shopping_cart
belongs_to :product
belongs_to :order
end
5 changes: 5 additions & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Order < ApplicationRecord
belongs_to :user
end
7 changes: 7 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class Product < ApplicationRecord
enum status: { used: 0, brand_new: 1, other: 2 }
belongs_to :category
has_one_attached :picture
end
5 changes: 5 additions & 0 deletions app/models/shipping_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ShippingAddress < ApplicationRecord
belongs_to :order
end
5 changes: 5 additions & 0 deletions app/models/shopping_cart.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ShoppingCart < ApplicationRecord
belongs_to :user
end
12 changes: 12 additions & 0 deletions db/migrate/20240729174528_create_categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class CreateCategories < ActiveRecord::Migration[7.1]
def change
create_table :categories do |t|
t.string :name
t.text :description

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20240729174541_create_shopping_carts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class CreateShoppingCarts < ActiveRecord::Migration[7.1]
def change
create_table :shopping_carts do |t|
t.references :user, null: false, foreign_key: true

t.timestamps
end
end
end
16 changes: 16 additions & 0 deletions db/migrate/20240729174554_create_products.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class CreateProducts < ActiveRecord::Migration[7.1]
def change
create_table :products do |t|
t.string :name
t.text :description
t.decimal :unit_price
t.integer :status
t.integer :stock
t.references :category, null: false, foreign_key: true

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20240729174607_create_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class CreateOrders < ActiveRecord::Migration[7.1]
def change
create_table :orders do |t|
t.references :user, null: false, foreign_key: true
t.decimal :total_price

t.timestamps
end
end
end
16 changes: 16 additions & 0 deletions db/migrate/20240729174619_create_line_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class CreateLineItems < ActiveRecord::Migration[7.1]
def change
create_table :line_items do |t|
t.references :shopping_cart, null: false, foreign_key: true
t.references :product, null: false, foreign_key: true
t.references :order, null: false, foreign_key: true
t.integer :quantity
t.decimal :unit_price
t.decimal :total_price

t.timestamps
end
end
end
17 changes: 17 additions & 0 deletions db/migrate/20240729174632_create_shipping_addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class CreateShippingAddresses < ActiveRecord::Migration[7.1]
def change
create_table :shipping_addresses do |t|
t.string :country
t.string :city
t.string :state
t.string :line1
t.string :line2
t.string :postal_code
t.references :order, null: false, foreign_key: true

t.timestamps
end
end
end
70 changes: 69 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_01_09_165800) do
ActiveRecord::Schema[7.1].define(version: 2024_07_29_174632) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -61,6 +61,13 @@
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end

create_table "categories", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "delayed_jobs", id: :serial, force: :cascade do |t|
t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false
Expand Down Expand Up @@ -92,6 +99,40 @@
t.index ["feature_key", "key", "value"], name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true
end

create_table "line_items", force: :cascade do |t|
t.bigint "shopping_cart_id", null: false
t.bigint "product_id", null: false
t.bigint "order_id", null: false
t.integer "quantity"
t.decimal "unit_price"
t.decimal "total_price"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["order_id"], name: "index_line_items_on_order_id"
t.index ["product_id"], name: "index_line_items_on_product_id"
t.index ["shopping_cart_id"], name: "index_line_items_on_shopping_cart_id"
end

create_table "orders", force: :cascade do |t|
t.bigint "user_id", null: false
t.decimal "total_price"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_orders_on_user_id"
end

create_table "products", force: :cascade do |t|
t.string "name"
t.text "description"
t.decimal "unit_price"
t.integer "status"
t.integer "stock"
t.bigint "category_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["category_id"], name: "index_products_on_category_id"
end

create_table "settings", force: :cascade do |t|
t.string "key", null: false
t.string "value"
Expand All @@ -100,6 +141,26 @@
t.index ["key"], name: "index_settings_on_key", unique: true
end

create_table "shipping_addresses", force: :cascade do |t|
t.string "country"
t.string "city"
t.string "state"
t.string "line1"
t.string "line2"
t.string "postal_code"
t.bigint "order_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["order_id"], name: "index_shipping_addresses_on_order_id"
end

create_table "shopping_carts", force: :cascade do |t|
t.bigint "user_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_shopping_carts_on_user_id"
end

create_table "users", id: :serial, force: :cascade do |t|
t.string "email"
t.string "encrypted_password", default: "", null: false
Expand All @@ -125,4 +186,11 @@
end

add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "line_items", "orders"
add_foreign_key "line_items", "products"
add_foreign_key "line_items", "shopping_carts"
add_foreign_key "orders", "users"
add_foreign_key "products", "categories"
add_foreign_key "shipping_addresses", "orders"
add_foreign_key "shopping_carts", "users"
end
8 changes: 8 additions & 0 deletions spec/factories/categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

FactoryBot.define do
factory :category do
name { 'MyString' }
description { 'MyText' }
end
end
12 changes: 12 additions & 0 deletions spec/factories/line_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

FactoryBot.define do
factory :line_item do
shopping_cart { nil }
product { nil }
order { nil }
quantity { 1 }
unit_price { '9.99' }
total_price { '9.99' }
end
end
8 changes: 8 additions & 0 deletions spec/factories/orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

FactoryBot.define do
factory :order do
user { nil }
total_price { '9.99' }
end
end
13 changes: 13 additions & 0 deletions spec/factories/products.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

FactoryBot.define do
factory :product do
name { 'MyString' }
description { 'MyText' }
unit_price { '9.99' }
status { 1 }
stock { 1 }
category { nil }
picture { nil }
end
end
13 changes: 13 additions & 0 deletions spec/factories/shipping_addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

FactoryBot.define do
factory :shipping_address do
country { 'MyString' }
city { 'MyString' }
state { 'MyString' }
line1 { 'MyString' }
line2 { 'MyString' }
postal_code { 'MyString' }
order { nil }
end
end
7 changes: 7 additions & 0 deletions spec/factories/shopping_carts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

FactoryBot.define do
factory :shopping_cart do
user { nil }
end
end
7 changes: 7 additions & 0 deletions spec/models/category_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Category do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/models/line_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe LineItem do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/models/order_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Order do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/models/product_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Product do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/models/shipping_address_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe ShippingAddress do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/models/shopping_cart_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe ShoppingCart do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading

0 comments on commit 5442e7b

Please sign in to comment.