From b996f09f42a097ec012260fb2f0bc8764d9393de Mon Sep 17 00:00:00 2001 From: JW Date: Mon, 3 Aug 2020 15:29:36 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=EC=88=98=EC=A0=95:=20=EC=85=80=EB=9F=AC?= =?UTF-8?q?=EC=A6=88=20API=20/=20=EA=B4=80=EC=8B=AC=20=ED=83=B5=EA=B7=B8?= =?UTF-8?q?=20=EB=B0=8F=20=EC=85=80=EB=9F=AC=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/interest_tag.rb | 12 +++++++++++- app/models/sellers/seller_info.rb | 5 +++++ .../20200803013753_add_country_to_interest_tag.rb | 5 +++++ ...14024_add_classification_field_to_interest_tag.rb | 5 +++++ .../20200803014409_add_columns_to_seller_info.rb | 7 +++++++ test/fixtures/interest_tags.yml | 10 ++++++++++ test/fixtures/sellers/seller_infos.yml | 3 +++ test/models/interest_tag_test.rb | 10 ++++++++++ test/models/sellers/seller_info_test.rb | 3 +++ 9 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 db/migrate/interest_tag/20200803013753_add_country_to_interest_tag.rb create mode 100644 db/migrate/interest_tag/20200803014024_add_classification_field_to_interest_tag.rb create mode 100644 db/migrate/sellers/20200803014409_add_columns_to_seller_info.rb diff --git a/app/models/interest_tag.rb b/app/models/interest_tag.rb index c59178c2..68500659 100644 --- a/app/models/interest_tag.rb +++ b/app/models/interest_tag.rb @@ -3,9 +3,19 @@ # Table name: interest_tags # # id :bigint not null, primary key +# created_by :string(255) # name :json # created_at :datetime not null # updated_at :datetime not null +# country_id :bigint # -class InterestTag < ApplicationRecord +# Indexes +# +# index_interest_tags_on_country_id (country_id) +# +# Foreign Keys +# +# fk_rails_... (country_id => countries.id) +# +class InterestTag < NationRecord end diff --git a/app/models/sellers/seller_info.rb b/app/models/sellers/seller_info.rb index 108d424a..d104a5de 100644 --- a/app/models/sellers/seller_info.rb +++ b/app/models/sellers/seller_info.rb @@ -6,11 +6,14 @@ # cumulative_amount :integer default(0) # cumulative_profit :integer default(0) # present_profit :integer default(0) +# purpose :text(65535) +# sns_name :string(255) # withdrawable_profit :integer default(0) # created_at :datetime not null # updated_at :datetime not null # grade_id :bigint not null # seller_id :bigint not null +# sns_id :string(255) # # Indexes # @@ -27,6 +30,8 @@ class SellerInfo < ApplicationRecord belongs_to :seller has_one :store_info, class_name: 'Sellers::StoreInfo', dependent: :destroy has_one :account_info, class_name: 'Sellers::AccountInfo', dependent: :destroy + has_many :user_interest_tags, class_name: 'UserInterestTag', dependent: :delete_all + has_many :interest_tags, through: :user_interest_tags belongs_to :grade, class_name: 'Sellers::Grade' has_many :permit_change_lists, class_name: 'Sellers::PermitChangeList', dependent: :destroy diff --git a/db/migrate/interest_tag/20200803013753_add_country_to_interest_tag.rb b/db/migrate/interest_tag/20200803013753_add_country_to_interest_tag.rb new file mode 100644 index 00000000..12d2df59 --- /dev/null +++ b/db/migrate/interest_tag/20200803013753_add_country_to_interest_tag.rb @@ -0,0 +1,5 @@ +class AddCountryToInterestTag < ActiveRecord::Migration[6.0] + def change + add_reference :interest_tags, :country, foreign_key: true + end +end diff --git a/db/migrate/interest_tag/20200803014024_add_classification_field_to_interest_tag.rb b/db/migrate/interest_tag/20200803014024_add_classification_field_to_interest_tag.rb new file mode 100644 index 00000000..13cf438d --- /dev/null +++ b/db/migrate/interest_tag/20200803014024_add_classification_field_to_interest_tag.rb @@ -0,0 +1,5 @@ +class AddClassificationFieldToInterestTag < ActiveRecord::Migration[6.0] + def change + add_column :interest_tags, :created_by, :string + end +end diff --git a/db/migrate/sellers/20200803014409_add_columns_to_seller_info.rb b/db/migrate/sellers/20200803014409_add_columns_to_seller_info.rb new file mode 100644 index 00000000..94ebee20 --- /dev/null +++ b/db/migrate/sellers/20200803014409_add_columns_to_seller_info.rb @@ -0,0 +1,7 @@ +class AddColumnsToSellerInfo < ActiveRecord::Migration[6.0] + def change + add_column :sellers_seller_infos, :sns_name, :string + add_column :sellers_seller_infos, :sns_id, :string + add_column :sellers_seller_infos, :purpose, :text + end +end diff --git a/test/fixtures/interest_tags.yml b/test/fixtures/interest_tags.yml index 198cc887..99df6b67 100644 --- a/test/fixtures/interest_tags.yml +++ b/test/fixtures/interest_tags.yml @@ -3,9 +3,19 @@ # Table name: interest_tags # # id :bigint not null, primary key +# created_by :string(255) # name :json # created_at :datetime not null # updated_at :datetime not null +# country_id :bigint +# +# Indexes +# +# index_interest_tags_on_country_id (country_id) +# +# Foreign Keys +# +# fk_rails_... (country_id => countries.id) # one: diff --git a/test/fixtures/sellers/seller_infos.yml b/test/fixtures/sellers/seller_infos.yml index e680bd05..7caa19b7 100644 --- a/test/fixtures/sellers/seller_infos.yml +++ b/test/fixtures/sellers/seller_infos.yml @@ -6,11 +6,14 @@ # cumulative_amount :integer default(0) # cumulative_profit :integer default(0) # present_profit :integer default(0) +# purpose :text(65535) +# sns_name :string(255) # withdrawable_profit :integer default(0) # created_at :datetime not null # updated_at :datetime not null # grade_id :bigint not null # seller_id :bigint not null +# sns_id :string(255) # # Indexes # diff --git a/test/models/interest_tag_test.rb b/test/models/interest_tag_test.rb index 561cec19..2eeffcd7 100644 --- a/test/models/interest_tag_test.rb +++ b/test/models/interest_tag_test.rb @@ -3,9 +3,19 @@ # Table name: interest_tags # # id :bigint not null, primary key +# created_by :string(255) # name :json # created_at :datetime not null # updated_at :datetime not null +# country_id :bigint +# +# Indexes +# +# index_interest_tags_on_country_id (country_id) +# +# Foreign Keys +# +# fk_rails_... (country_id => countries.id) # require 'test_helper' diff --git a/test/models/sellers/seller_info_test.rb b/test/models/sellers/seller_info_test.rb index b2d6abcf..c455f97a 100644 --- a/test/models/sellers/seller_info_test.rb +++ b/test/models/sellers/seller_info_test.rb @@ -6,11 +6,14 @@ # cumulative_amount :integer default(0) # cumulative_profit :integer default(0) # present_profit :integer default(0) +# purpose :text(65535) +# sns_name :string(255) # withdrawable_profit :integer default(0) # created_at :datetime not null # updated_at :datetime not null # grade_id :bigint not null # seller_id :bigint not null +# sns_id :string(255) # # Indexes # From c61cd2a0eab0102eca5b814182d9604cf183d670 Mon Sep 17 00:00:00 2001 From: JW Date: Mon, 3 Aug 2020 15:30:23 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=EC=88=98=EC=A0=95:=20annotate=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20(=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=82=AD=EC=A0=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/adjustment_product_item.rb | 5 ----- app/models/barcode.rb | 5 ----- app/models/barcode_option.rb | 5 ----- test/fixtures/jwt_denylists.yml | 1 - 4 files changed, 16 deletions(-) diff --git a/app/models/adjustment_product_item.rb b/app/models/adjustment_product_item.rb index 890fa099..32f41b12 100644 --- a/app/models/adjustment_product_item.rb +++ b/app/models/adjustment_product_item.rb @@ -13,11 +13,6 @@ # index_adjustment_product_items_on_adjustment_id (adjustment_id) # index_adjustment_product_items_on_product_item_id (product_item_id) # -# Foreign Keys -# -# fk_rails_... (adjustment_id => adjustments.id) -# fk_rails_... (product_item_id => product_items.id) -# class AdjustmentProductItem < ApplicationRecord belongs_to :adjustment belongs_to :product_item diff --git a/app/models/barcode.rb b/app/models/barcode.rb index 7ff6b7b5..e17a0098 100644 --- a/app/models/barcode.rb +++ b/app/models/barcode.rb @@ -14,11 +14,6 @@ # index_barcodes_on_cart_item_id (cart_item_id) # index_barcodes_on_product_id (product_id) # -# Foreign Keys -# -# fk_rails_... (cart_item_id => cart_items.id) -# fk_rails_... (product_id => products.id) -# class Barcode < ApplicationRecord belongs_to :product, dependent: :destroy diff --git a/app/models/barcode_option.rb b/app/models/barcode_option.rb index 3434b8f1..b7e93466 100644 --- a/app/models/barcode_option.rb +++ b/app/models/barcode_option.rb @@ -13,11 +13,6 @@ # index_barcode_options_on_barcode_id (barcode_id) # index_barcode_options_on_product_option_id (product_option_id) # -# Foreign Keys -# -# fk_rails_... (barcode_id => barcodes.id) -# fk_rails_... (product_option_id => product_options.id) -# class BarcodeOption < ApplicationRecord belongs_to :barcode, dependent: :destroy belongs_to :product_option, dependent: :destroy diff --git a/test/fixtures/jwt_denylists.yml b/test/fixtures/jwt_denylists.yml index e25b945f..906f54a5 100644 --- a/test/fixtures/jwt_denylists.yml +++ b/test/fixtures/jwt_denylists.yml @@ -10,7 +10,6 @@ # # index_jwt_denylist_on_jti (jti) # -# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # This model initially had no columns defined. If you add columns to the # model remove the '{}' from the fixture names and add the columns immediately From a0e3ca8be22b88183dcfa9c3d94ed0b729d880f1 Mon Sep 17 00:00:00 2001 From: Bran <40688044+june20516@users.noreply.github.com> Date: Mon, 3 Aug 2020 15:45:33 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=EC=88=98=EC=A0=95=20:=20sold=20paper=20?= =?UTF-8?q?=EC=9D=98=20=EB=8B=A8=EC=9C=84=EB=A5=BC=20order=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20item=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20#68?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/cart_item.rb | 2 + app/models/order_info.rb | 7 ++++ app/models/sellers/item_sold_paper.rb | 14 +++++++ app/models/sellers/seller_info.rb | 38 +++++++++---------- db/data/20200730032746_set_item_sold_paper.rb | 19 ++++++++++ ...0032112_create_sellers_item_sold_papers.rb | 13 +++++++ ...0050325_remove_sellers_order_sold_paper.rb | 5 +++ test/fixtures/sellers/item_sold_papers.yml | 15 ++++++++ test/models/sellers/item_sold_paper_test.rb | 7 ++++ 9 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 app/models/sellers/item_sold_paper.rb create mode 100644 db/data/20200730032746_set_item_sold_paper.rb create mode 100644 db/migrate/20200730032112_create_sellers_item_sold_papers.rb create mode 100644 db/migrate/20200730050325_remove_sellers_order_sold_paper.rb create mode 100644 test/fixtures/sellers/item_sold_papers.yml create mode 100644 test/models/sellers/item_sold_paper_test.rb diff --git a/app/models/cart_item.rb b/app/models/cart_item.rb index f8ff1f4e..578e2509 100644 --- a/app/models/cart_item.rb +++ b/app/models/cart_item.rb @@ -54,6 +54,8 @@ class CartItem < ApplicationRecord has_one :order_info, through: :cart + has_one :item_sold_paper, class_name: 'Sellers::ItemSoldPaper', foreign_key: :item_id, dependent: :destroy + scope :cancelled, -> { where(cancelled_tag: CartItemCancelledTag.all) } scope :not_cancelled, -> { where.not(cancelled_tag: CartItemCancelledTag.all) } diff --git a/app/models/order_info.rb b/app/models/order_info.rb index 76b689c4..a10db260 100644 --- a/app/models/order_info.rb +++ b/app/models/order_info.rb @@ -34,6 +34,7 @@ class OrderInfo < NationRecord has_many :items, through: :cart has_many :product_options, through: :items, source: :product_option has_many :adjustments, class_name: 'Adjustment' + has_many :sellers_papers, through: :items, source: :item_sold_paper # =============================================== has_many :order_info_brands, class_name: 'OrderInfoBrand', dependent: :delete_all @@ -43,6 +44,7 @@ class OrderInfo < NationRecord validates_presence_of :cart_id, :enc_id validates_uniqueness_of :cart_id, :enc_id + delegate :order_status, to: :cart # alias_attribute :status, :order_status delegate :delivery_amount, to: :ship_info, allow_nil: true @@ -53,6 +55,7 @@ class OrderInfo < NationRecord scope :sold, -> { includes(:cart).where(cart: Cart.where(order_status: Cart::SOLD_STATUSES)) } scope :eager_index, -> { includes(:payment, :ship_info) } scope :stage_in, ->(stage) { includes(:cart).where(cart: Cart.send((stage || :all).to_sym)) } + scope :sellers_order, -> { includes(:items).where(cart: Cart.where(items: CartItem.sold_by_seller)) } def self.gen_enc_id [ @@ -77,4 +80,8 @@ def first_product def quantity cart.items.sum(:barcode_count) end + + def sellers_items + items.filter(&:item_sold_paper) + end end diff --git a/app/models/sellers/item_sold_paper.rb b/app/models/sellers/item_sold_paper.rb new file mode 100644 index 00000000..fc03aec8 --- /dev/null +++ b/app/models/sellers/item_sold_paper.rb @@ -0,0 +1,14 @@ +module Sellers + class ItemSoldPaper < ApplicationRecord + belongs_to :item, class_name: 'CartItem' + belongs_to :seller_info, class_name: 'Sellers::SellerInfo' + + def paid? + paid + end + + def pay! + update(paid: true, paid_at: DateTime.now) + end + end +end diff --git a/app/models/sellers/seller_info.rb b/app/models/sellers/seller_info.rb index d104a5de..33465178 100644 --- a/app/models/sellers/seller_info.rb +++ b/app/models/sellers/seller_info.rb @@ -39,12 +39,12 @@ class SellerInfo < ApplicationRecord has_one :permit_status, through: :permission, class_name: 'Sellers::PermitStatus' has_many :settlement_statements, class_name: 'Sellers::SettlementStatement', dependent: :destroy - has_many :order_sold_papers, class_name: 'Sellers::OrderSoldPaper', dependent: :destroy + has_many :item_sold_papers, class_name: 'Sellers::ItemSoldPaper', dependent: :destroy + has_many :items, through: :item_sold_papers + has_many :order_infos, -> { distinct }, through: :items - has_many :order_infos, through: :order_sold_papers - - scope :permitted, -> { where(permission: PermitChangeList.where(permit_status: PermitStatus.permitted)) } - scope :applied, -> { where(permission: PermitChangeList.where(permit_status: PermitStatus.applied)) } + scope :permitted, -> { where(permission: Sellers::PermitChangeList.where(permit_status: Sellers::PermitStatus.permitted)) } + scope :applied, -> { where(permission: Sellers::PermitChangeList.where(permit_status: Sellers::PermitStatus.applied)) } delegate :name, to: :seller delegate :email, to: :seller @@ -53,43 +53,43 @@ class SellerInfo < ApplicationRecord def permitted? update_status_cache - permit_status == PermitStatus.permitted + permit_status == Sellers::PermitStatus.permitted end def play_permit!(reason = nil) - permit_change_lists << PermitChangeList.new( - permit_status: PermitStatus.permitted, + permit_change_lists << Sellers::PermitChangeList.new( + permit_status: Sellers::PermitStatus.permitted, reason: reason ) update_status_cache end def play_stop!(reason) - permit_change_lists << PermitChangeList.new( - permit_status: PermitStatus.stopped, + permit_change_lists << Sellers::PermitChangeList.new( + permit_status: Sellers::PermitStatus.stopped, reason: reason ) update_status_cache end def init_permit_status! - permit_change_lists << PermitChangeList.new( - permit_status: PermitStatus.applied + permit_change_lists << Sellers::PermitChangeList.new( + permit_status: Sellers::PermitStatus.applied ) update_status_cache end - def update_counter_cache(order_sold_paper = nil) - if order_sold_paper.nil? + def update_counter_cache(item_sold_paper = nil) + if item_sold_paper.nil? update_columns( - cumulative_amount: order_infos.map(&:payment).sum(&:total_price_sum), - cumulative_profit: order_sold_papers.sum(&:adjusted_profit) + cumulative_amount: items.sum(&:captured_retail_price), + cumulative_profit: item_sold_papers.sum(&:adjusted_profit) ) else - order_info = order_sold_paper.order_info + cart_item = item_sold_paper.cart_item update_columns( - cumulative_amount: cumulative_amount + order_info.payment.total_price_sum, - cumulative_profit: cumulative_profit + order_sold_paper.adjusted_profit + cumulative_amount: cumulative_amount + cart_item.captured_retail_price, + cumulative_profit: cumulative_profit + item_sold_paper.adjusted_profit ) end end diff --git a/db/data/20200730032746_set_item_sold_paper.rb b/db/data/20200730032746_set_item_sold_paper.rb new file mode 100644 index 00000000..900925e0 --- /dev/null +++ b/db/data/20200730032746_set_item_sold_paper.rb @@ -0,0 +1,19 @@ +class SetItemSoldPaper < ActiveRecord::Migration[6.0] + def up + Sellers::OrderSoldPaper.all.each do |paper| + order = paper.order_info + seller_info = paper.seller_info + order.items.each do |item| + Sellers::ItemSoldPaper.create( + item: item, + seller_info: seller_info, + adjusted_profit: (item.result_price * item.option_count * seller_info.commission_rate) + ) + end + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20200730032112_create_sellers_item_sold_papers.rb b/db/migrate/20200730032112_create_sellers_item_sold_papers.rb new file mode 100644 index 00000000..acaa0954 --- /dev/null +++ b/db/migrate/20200730032112_create_sellers_item_sold_papers.rb @@ -0,0 +1,13 @@ +class CreateSellersItemSoldPapers < ActiveRecord::Migration[6.0] + def change + create_table :sellers_item_sold_papers do |t| + t.references :item, null: false, foreign_key: { to_table: :cart_items } + t.references :seller_info, null: false, foreign_key: { to_table: :sellers_seller_infos } + t.boolean :paid, default: false + t.datetime :paid_at + t.integer :adjusted_profit, default: 0 + + t.timestamps + end + end +end diff --git a/db/migrate/20200730050325_remove_sellers_order_sold_paper.rb b/db/migrate/20200730050325_remove_sellers_order_sold_paper.rb new file mode 100644 index 00000000..09f91550 --- /dev/null +++ b/db/migrate/20200730050325_remove_sellers_order_sold_paper.rb @@ -0,0 +1,5 @@ +class RemoveSellersOrderSoldPaper < ActiveRecord::Migration[6.0] + def change + drop_table :sellers_order_sold_papers + end +end diff --git a/test/fixtures/sellers/item_sold_papers.yml b/test/fixtures/sellers/item_sold_papers.yml new file mode 100644 index 00000000..a0141669 --- /dev/null +++ b/test/fixtures/sellers/item_sold_papers.yml @@ -0,0 +1,15 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + item_info: one + seller_info: one + paid: false + paid_at: 2020-07-30 12:21:13 + adjusted_profit: 1 + +two: + item_info: two + seller_info: two + paid: false + paid_at: 2020-07-30 12:21:13 + adjusted_profit: 1 diff --git a/test/models/sellers/item_sold_paper_test.rb b/test/models/sellers/item_sold_paper_test.rb new file mode 100644 index 00000000..d07e0c92 --- /dev/null +++ b/test/models/sellers/item_sold_paper_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class Sellers::ItemSoldPaperTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From f204757e2366eb7f666d54de83ea8261e403b56d Mon Sep 17 00:00:00 2001 From: "Yonghyun Kim (Fred)" Date: Mon, 3 Aug 2020 17:14:33 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=EC=88=98=EC=A0=95:=20=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=84=A0=EC=96=B8=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EA=B2=B0=EA=B3=BC=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/sellers/seller_info.rb | 4 ++-- app/models/user_interest_tag.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/sellers/seller_info.rb b/app/models/sellers/seller_info.rb index 33465178..c2d1d53d 100644 --- a/app/models/sellers/seller_info.rb +++ b/app/models/sellers/seller_info.rb @@ -30,7 +30,7 @@ class SellerInfo < ApplicationRecord belongs_to :seller has_one :store_info, class_name: 'Sellers::StoreInfo', dependent: :destroy has_one :account_info, class_name: 'Sellers::AccountInfo', dependent: :destroy - has_many :user_interest_tags, class_name: 'UserInterestTag', dependent: :delete_all + has_many :user_interest_tags, class_name: 'UserInterestTag', dependent: :destroy has_many :interest_tags, through: :user_interest_tags belongs_to :grade, class_name: 'Sellers::Grade' @@ -41,7 +41,7 @@ class SellerInfo < ApplicationRecord has_many :settlement_statements, class_name: 'Sellers::SettlementStatement', dependent: :destroy has_many :item_sold_papers, class_name: 'Sellers::ItemSoldPaper', dependent: :destroy has_many :items, through: :item_sold_papers - has_many :order_infos, -> { distinct }, through: :items + has_many :order_infos, -> { distinct }, class_name: 'OrderInfo', through: :items scope :permitted, -> { where(permission: Sellers::PermitChangeList.where(permit_status: Sellers::PermitStatus.permitted)) } scope :applied, -> { where(permission: Sellers::PermitChangeList.where(permit_status: Sellers::PermitStatus.applied)) } diff --git a/app/models/user_interest_tag.rb b/app/models/user_interest_tag.rb index 00b94ee5..8914af8b 100644 --- a/app/models/user_interest_tag.rb +++ b/app/models/user_interest_tag.rb @@ -19,4 +19,5 @@ # fk_rails_... (user_id => users.id) # class UserInterestTag < ApplicationRecord + belongs_to :interest_tag end From 5d5ffabf1a4b2e0b95d7902b0e08799c0892de39 Mon Sep 17 00:00:00 2001 From: "Yonghyun Kim (Fred)" Date: Mon, 3 Aug 2020 17:15:46 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=EA=B8=B0=EB=8A=A5:=20CORS=20=EC=97=90=20?= =?UTF-8?q?=ED=97=88=EC=9A=A9=20=EA=B0=80=EB=8A=A5=ED=95=9C=20=ED=97=A4?= =?UTF-8?q?=EB=8D=94=20=EC=B6=94=EA=B0=80=20(Authorization)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/cors.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index ad0785ee..92132ec2 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -4,7 +4,8 @@ resource( '*', headers: :any, - methods: %i[get post put patch delete options head] + methods: %i[get post put patch delete options head], + expose: %w[Authorization] ) end end From 40ed5ed333cf4634783d990170c7be383aa1f6b4 Mon Sep 17 00:00:00 2001 From: "Yonghyun Kim (Fred)" Date: Mon, 3 Aug 2020 17:18:24 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=EA=B8=B0=EB=8A=A5:=20API=20=EC=9D=98=20?= =?UTF-8?q?=EB=AA=A8=EB=93=A0=20=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=EC=97=90=20=EA=B8=B0=EB=B3=B8=20=ED=8F=AC=EB=A9=A7?= =?UTF-8?q?=EC=9D=84=20json=20=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index e00701c6..21e6af63 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,18 +1,20 @@ Rails.application.routes.draw do - devise_for :users, controllers: { - sessions: 'users/sessions', - registrations: 'users/registrations', - passwords: 'users/passwords' - } - # global file crud (active_storage) resources :files, only: %i[show create destroy] - - draw :partner_center_routes - draw :gomisa_routes - draw :common_routes - draw :sellers_routes + constraints format: :json do + devise_for :users, controllers: { + sessions: 'users/sessions', + registrations: 'users/registrations', + passwords: 'users/passwords' + } + + draw :partner_center_routes + draw :gomisa_routes + + draw :common_routes + draw :sellers_routes + end namespace :haravan do namespace :settlement do From 4802fd5e08a5950fe56b370ad9100fe46ad74f16 Mon Sep 17 00:00:00 2001 From: JW Date: Mon, 3 Aug 2020 18:46:40 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=EC=88=98=EC=A0=95:=20=EC=85=80=EB=9F=AC?= =?UTF-8?q?=EC=A6=88=20API=20/=20=EC=9E=90=EC=8B=A0=EC=9D=98=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20API?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/sellers/sessions_controller.rb | 10 ++++++++++ app/views/sellers/sessions/show.json.jbuilder | 1 + config/routes/sellers_routes.rb | 3 +++ test/controllers/sellers/sessions_controller_test.rb | 7 +++++++ 4 files changed, 21 insertions(+) create mode 100644 app/controllers/sellers/sessions_controller.rb create mode 100644 app/views/sellers/sessions/show.json.jbuilder create mode 100644 test/controllers/sellers/sessions_controller_test.rb diff --git a/app/controllers/sellers/sessions_controller.rb b/app/controllers/sellers/sessions_controller.rb new file mode 100644 index 00000000..a0dc7ae7 --- /dev/null +++ b/app/controllers/sellers/sessions_controller.rb @@ -0,0 +1,10 @@ +module Sellers + class SessionsController < BaseController + before_action :authenticate_user! + + # = GET /sellers/user + def show + # = show.json.jbuilder + end + end +end diff --git a/app/views/sellers/sessions/show.json.jbuilder b/app/views/sellers/sessions/show.json.jbuilder new file mode 100644 index 00000000..d02455b2 --- /dev/null +++ b/app/views/sellers/sessions/show.json.jbuilder @@ -0,0 +1 @@ +json.current_user current_user diff --git a/config/routes/sellers_routes.rb b/config/routes/sellers_routes.rb index d93f84c9..61991a2e 100644 --- a/config/routes/sellers_routes.rb +++ b/config/routes/sellers_routes.rb @@ -1,4 +1,7 @@ namespace :sellers, except: %i[new edit] do + # get 'user', controller: 'users' + resource :user, only: :show, controller: :sessions + # === 유저 API # resources :users do diff --git a/test/controllers/sellers/sessions_controller_test.rb b/test/controllers/sellers/sessions_controller_test.rb new file mode 100644 index 00000000..9e21b3fc --- /dev/null +++ b/test/controllers/sellers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class Sellers::SessionsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end