Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
93c26b73
Commit
93c26b73
authored
Sep 21, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add status filter to GET merhcant/products
parent
c39315e4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
10 deletions
+22
-10
product_spec.rb
...nerators/templates/spec/requests/merchant/product_spec.rb
+8
-2
products_controller.rb
lib/shotengai/controllers/merchant/products_controller.rb
+9
-3
product.rb
lib/shotengai/product.rb
+5
-5
No files found.
lib/generators/templates/spec/requests/merchant/product_spec.rb
View file @
93c26b73
...
@@ -28,6 +28,7 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
...
@@ -28,6 +28,7 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
parameter
:page
,
in: :query
,
type: :string
parameter
:page
,
in: :query
,
type: :string
parameter
:per_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
parameter
:catalog_list
,
in: :query
,
type: :array
let
(
:page
)
{
1
}
let
(
:page
)
{
1
}
...
@@ -40,10 +41,15 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
...
@@ -40,10 +41,15 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
end
end
response
(
200
,
description:
'filter by catalog'
)
do
response
(
200
,
description:
'filter by catalog'
)
do
let
(
:catalog_list
)
{
@product_1
.
catalog_list
}
let
(
:catalog_list
)
{
@product_1
.
catalog_list
}
it
{
expect
(
JSON
.
parse
(
response
.
body
)[
'products'
].
count
).
to
eq
(
1
)
}
it
{
expect
(
JSON
.
parse
(
response
.
body
)[
'products'
].
count
).
to
eq
(
1
)
}
end
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
end
post
(
summary:
'管理员新建商品'
)
do
post
(
summary:
'管理员新建商品'
)
do
...
@@ -57,7 +63,7 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
...
@@ -57,7 +63,7 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
product:
{
product:
{
type: :object
,
properties:
{
type: :object
,
properties:
{
title:
{
type: :string
},
title:
{
type: :string
},
default_series_id:
{
type: :integer
},
#
default_series_id: { type: :integer },
need_express:
{
type: :boolean
},
need_express:
{
type: :boolean
},
need_time_attr:
{
type: :boolean
},
need_time_attr:
{
type: :boolean
},
cover_image:
{
type: :string
},
cover_image:
{
type: :string
},
...
...
lib/shotengai/controllers/merchant/products_controller.rb
View file @
93c26b73
...
@@ -10,9 +10,15 @@ module Shotengai
...
@@ -10,9 +10,15 @@ module Shotengai
end
end
def
index_query
resources
def
index_query
resources
params
[
:catalog_list
]
?
p
params
resources
.
tagged_with
(
params
[:
catalog_list
],
on: :catalogs
)
:
p
params
[
:status
]
resources
(
params
[
:catalog_list
]
?
resources
.
tagged_with
(
params
[:
catalog_list
],
on: :catalogs
)
:
resources
).
where
(
params
[
:status
].
blank?
.!
&&
{
status:
params
[
:status
]
}
)
end
end
def
put_on_shelf
def
put_on_shelf
...
...
lib/shotengai/product.rb
View file @
93c26b73
...
@@ -35,25 +35,25 @@ module Shotengai
...
@@ -35,25 +35,25 @@ module Shotengai
include
AASM_DLC
include
AASM_DLC
aasm
column: :status
do
aasm
column: :status
do
state
:no_on
,
initial:
true
state
:no
t
_on
,
initial:
true
state
:on_sale
,
:deleted
state
:on_sale
,
:deleted
event
:put_on_shelf
do
event
:put_on_shelf
do
transitions
from: :no_on
,
to: :on_sale
transitions
from: :no
t
_on
,
to: :on_sale
end
end
event
:sold_out
do
event
:sold_out
do
transitions
from: :on_sale
,
to: :no_on
transitions
from: :on_sale
,
to: :no
t
_on
end
end
event
:soft_delete
do
event
:soft_delete
do
transitions
from:
[
:on_sale
,
:no_on
],
to: :deleted
transitions
from:
[
:on_sale
,
:no
t
_on
],
to: :deleted
end
end
end
end
def
status_zh
def
status_zh
{
{
no_on:
'未上架'
,
no
t
_on:
'未上架'
,
on_sale:
'已上架'
,
on_sale:
'已上架'
,
deleted:
'已删除'
deleted:
'已删除'
}[
status
.
to_sym
]
}[
status
.
to_sym
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment