Commit 93c26b73 by ivan Lan

Add status filter to GET merhcant/products

parent c39315e4
......@@ -28,6 +28,7 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
parameter :page, in: :query, type: :string
parameter :per_page, in: :query, type: :string
parameter :status, in: :query, type: :string
parameter :catalog_list, in: :query, type: :array
let(:page) { 1 }
......@@ -40,10 +41,15 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
end
response(200, description: 'filter by catalog') do
let(:catalog_list) { @product_1.catalog_list }
it { expect(JSON.parse(response.body)['products'].count).to eq(1) }
end
response(200, description: 'filter by status') do
before { @product_1.put_on_shelf! }
let(:status) { 'on_sale' }
it { expect(JSON.parse(response.body)['products'].count).to eq(1) }
end
end
post(summary: '管理员新建商品') do
......@@ -57,7 +63,7 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
product: {
type: :object, properties: {
title: { type: :string },
default_series_id: { type: :integer },
# default_series_id: { type: :integer },
need_express: { type: :boolean },
need_time_attr: { type: :boolean },
cover_image: { type: :string },
......
......@@ -10,9 +10,15 @@ module Shotengai
end
def index_query resources
params[:catalog_list] ?
resources.tagged_with(params[:catalog_list], on: :catalogs) :
resources
p params
p params[:status]
(
params[:catalog_list] ?
resources.tagged_with(params[:catalog_list], on: :catalogs) :
resources
).where(
params[:status].blank?.! && { status: params[:status] }
)
end
def put_on_shelf
......
......@@ -35,25 +35,25 @@ module Shotengai
include AASM_DLC
aasm column: :status do
state :no_on, initial: true
state :not_on, initial: true
state :on_sale, :deleted
event :put_on_shelf do
transitions from: :no_on, to: :on_sale
transitions from: :not_on, to: :on_sale
end
event :sold_out do
transitions from: :on_sale, to: :no_on
transitions from: :on_sale, to: :not_on
end
event :soft_delete do
transitions from: [:on_sale, :no_on], to: :deleted
transitions from: [:on_sale, :not_on], to: :deleted
end
end
def status_zh
{
no_on: '未上架',
not_on: '未上架',
on_sale: '已上架',
deleted: '已删除'
}[ status.to_sym ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment