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
4b811198
Commit
4b811198
authored
Sep 21, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add merchant/products/batch_event
parent
93c26b73
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
5 deletions
+49
-5
controllers_generator.rb
lib/generators/shotengai/controllers_generator.rb
+4
-0
product_spec.rb
...nerators/templates/spec/requests/merchant/product_spec.rb
+21
-0
base.rb
lib/shotengai/controllers/base.rb
+3
-2
products_controller.rb
lib/shotengai/controllers/merchant/products_controller.rb
+17
-3
product.rb
lib/shotengai/product.rb
+4
-0
No files found.
lib/generators/shotengai/controllers_generator.rb
View file @
4b811198
...
...
@@ -87,6 +87,10 @@ module Shotengai
member do
post :put_on_shelf
post :sold_out
post :relive
end
collection do
post :batch_event
end
resources :
#{
product
}
_series
end
...
...
lib/generators/templates/spec/requests/merchant/product_spec.rb
View file @
4b811198
...
...
@@ -118,6 +118,27 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
end
end
path
"/
#{
namespace
}
/products/batch_event"
do
post
(
summary:
'商户 批量处理商品(put_on_shelf, sold_out, soft_delete, relive)'
)
do
parameter
:ids
,
in: :query
,
type: :string
parameter
:event
,
in: :query
,
type: :string
let
(
:ids
)
{
@products
.
first
(
2
).
map
(
&
:id
)
}
let
(
:event
)
{
'put_on_shelf'
}
parameter
:manager_type
,
in: :query
,
type: :string
parameter
:manager_id
,
in: :query
,
type: :integer
let
(
:manager_id
)
{
@merchant
.
id
}
let
(
:manager_type
)
{
@merchant
.
class
.
name
}
produces
'application/json'
consumes
'application/json'
response
(
200
,
description:
'successful'
)
do
it
{
expect
(
Product
.
where
(
status:
'on_sale'
).
map
(
&
:id
).
sort
).
to
eq
(
@products
.
first
(
2
).
map
(
&
:id
).
sort
)
}
end
end
end
path
"/
#{
namespace
}
/products/{id}"
do
parameter
'id'
,
in: :path
,
type: :string
let
(
:id
)
{
@product_1
.
id
}
...
...
lib/shotengai/controllers/base.rb
View file @
4b811198
...
...
@@ -9,7 +9,8 @@ module Shotengai
def
base_resources
=
resources
class_eval
%Q{
def add_base_resources
@base_resources = ::
#{
resources
}
@base_resources =
ActiveRecord::Relation ===
#{
resources
}
?
#{
resources
}
: ::
#{
resources
}
end
}
end
...
...
@@ -39,7 +40,7 @@ module Shotengai
respond_to
:json
rescue_from
::
Shotengai
::
WebError
do
|
e
|
render
json:
{
error:
e
.
message
},
status:
e
.
status
render
json:
{
error:
e
.
message
,
code:
e
.
code
},
status:
e
.
status
end
rescue_from
ActiveRecord
::
RecordInvalid
do
|
e
|
...
...
lib/shotengai/controllers/merchant/products_controller.rb
View file @
4b811198
...
...
@@ -5,15 +5,15 @@ module Shotengai
self
.
base_resources
=
Product
self
.
template_dir
=
'shotengai/merchant/products/'
skip_before_action
:set_resource
,
only: :batch_event
def
default_query
resources
resources
.
where
(
@manager
&&
{
manager:
@manager
})
end
def
index_query
resources
p
params
p
params
[
:status
]
(
params
[
:catalog_list
]
?
params
[
:catalog_list
]
?
resources
.
tagged_with
(
params
[:
catalog_list
],
on: :catalogs
)
:
resources
).
where
(
...
...
@@ -31,11 +31,25 @@ module Shotengai
respond_with
@resource
,
template:
"
#{
@template_dir
}
/show"
,
status:
200
end
def
relive
@resource
.
relive!
respond_with
@resource
,
template:
"
#{
@template_dir
}
/show"
,
status:
200
end
def
destroy
@resource
.
soft_delete!
head
204
end
def
batch_event
# params[ids] params[:event]
event
=
(
@base_resources
.
where
(
nil
).
klass
.
aasm
.
events
.
map
(
&
:name
)
&
Array
[
params
[
:event
].
to_sym
]).
first
raise
::
Shotengai
::
WebError
.
new
(
'Invaild event'
,
'-1'
,
400
)
unless
event
ActiveRecord
::
Base
.
transaction
do
default_resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
end
head
200
end
private
def
resource_params
# QUESTION: need these ?
...
...
lib/shotengai/product.rb
View file @
4b811198
...
...
@@ -49,6 +49,10 @@ module Shotengai
event
:soft_delete
do
transitions
from:
[
:on_sale
,
:not_on
],
to: :deleted
end
event
:relive
do
transitions
from: :deleted
,
to: :not_on
end
end
def
status_zh
...
...
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