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
568590dd
Commit
568590dd
authored
Sep 24, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add batch_event to series & Add soft_delete to series
parent
17f38f46
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
2 deletions
+49
-2
1_create_shotengai_products_and_orders.rb
db/migrate/1_create_shotengai_products_and_orders.rb
+1
-0
base.rb
lib/shotengai/controllers/base.rb
+15
-0
product_series_controller.rb
...otengai/controllers/customer/product_series_controller.rb
+1
-1
product_series_controller.rb
...otengai/controllers/merchant/product_series_controller.rb
+16
-1
products_controller.rb
lib/shotengai/controllers/merchant/products_controller.rb
+1
-0
series.rb
lib/shotengai/series.rb
+15
-0
No files found.
db/migrate/1_create_shotengai_products_and_orders.rb
View file @
568590dd
...
@@ -36,6 +36,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
...
@@ -36,6 +36,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t
.
decimal
:original_price
,
precision:
9
,
scale:
2
t
.
decimal
:original_price
,
precision:
9
,
scale:
2
t
.
decimal
:price
,
precision:
9
,
scale:
2
t
.
decimal
:price
,
precision:
9
,
scale:
2
t
.
integer
:stock
,
default:
-
1
t
.
integer
:stock
,
default:
-
1
t
.
string
:aasm_state
t
.
json
:spec
t
.
json
:spec
# Single Table Inheritance
# Single Table Inheritance
t
.
string
:type
t
.
string
:type
...
...
lib/shotengai/controllers/base.rb
View file @
568590dd
...
@@ -30,6 +30,21 @@ module Shotengai
...
@@ -30,6 +30,21 @@ module Shotengai
def
remove_actions
*
actions
def
remove_actions
*
actions
actions
.
each
{
|
name
|
remove_possible_method
name
}
actions
.
each
{
|
name
|
remove_possible_method
name
}
end
end
# def add_action *actions
# action_methods = {}
# action_methods[:batch_event] = %Q{
# 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
# }
# actions.each { |action| class_eval(action_methods[action]) }
# end
end
end
before_action
:set_resource
,
except:
[
:index
,
:create
]
before_action
:set_resource
,
except:
[
:index
,
:create
]
...
...
lib/shotengai/controllers/customer/product_series_controller.rb
View file @
568590dd
...
@@ -10,7 +10,7 @@ module Shotengai
...
@@ -10,7 +10,7 @@ module Shotengai
remove_actions
:create
,
:update
,
:destroy
remove_actions
:create
,
:update
,
:destroy
def
default_query
resources
def
default_query
resources
resources
.
where
(
resources
.
alive
.
where
(
params
[
:product_id
]
&&
{
shotengai_product_id:
params
[
:product_id
]
}
params
[
:product_id
]
&&
{
shotengai_product_id:
params
[
:product_id
]
}
)
)
end
end
...
...
lib/shotengai/controllers/merchant/product_series_controller.rb
View file @
568590dd
...
@@ -6,13 +6,28 @@ module Shotengai
...
@@ -6,13 +6,28 @@ module Shotengai
self
.
template_dir
=
'shotengai/merchant/series/'
self
.
template_dir
=
'shotengai/merchant/series/'
before_action
:manager_auth
before_action
:manager_auth
# add_actions :batch_event
def
default_query
resources
def
default_query
resources
resources
.
where
(
resources
.
alive
.
where
(
params
[
:product_id
]
&&
{
shotengai_product_id:
params
[
:product_id
]
}
params
[
:product_id
]
&&
{
shotengai_product_id:
params
[
:product_id
]
}
)
)
end
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
private
def
resource_params
def
resource_params
spec
=
params
.
require
(
resource_key
).
fetch
(
:spec
,
nil
).
try
(
:permit!
)
spec
=
params
.
require
(
resource_key
).
fetch
(
:spec
,
nil
).
try
(
:permit!
)
...
...
lib/shotengai/controllers/merchant/products_controller.rb
View file @
568590dd
...
@@ -6,6 +6,7 @@ module Shotengai
...
@@ -6,6 +6,7 @@ module Shotengai
self
.
template_dir
=
'shotengai/merchant/products/'
self
.
template_dir
=
'shotengai/merchant/products/'
skip_before_action
:set_resource
,
only: :batch_event
skip_before_action
:set_resource
,
only: :batch_event
# add_actions :batch_event
def
default_query
resources
def
default_query
resources
resources
.
where
(
@manager
&&
{
manager:
@manager
})
resources
.
where
(
@manager
&&
{
manager:
@manager
})
...
...
lib/shotengai/series.rb
View file @
568590dd
...
@@ -7,6 +7,7 @@ module Shotengai
...
@@ -7,6 +7,7 @@ module Shotengai
# original_price :decimal(9, 2)
# original_price :decimal(9, 2)
# price :decimal(9, 2)
# price :decimal(9, 2)
# stock :integer default(-1)
# stock :integer default(-1)
# state :string(255)
# spec :json
# spec :json
# type :string(255)
# type :string(255)
# meta :json
# meta :json
...
@@ -41,6 +42,20 @@ module Shotengai
...
@@ -41,6 +42,20 @@ module Shotengai
end
end
}
}
include
AASM_DLC
aasm
column: :aasm_state
do
state
:alive
,
initial:
true
state
:deleted
event
:soft_delete
do
transitions
from: :alive
,
to: :deleted
end
event
:relive
do
transitions
from: :deleted
,
to: :alive
end
end
class
<<
self
class
<<
self
def
inherited
subclass
def
inherited
subclass
product_name
=
/^(.+)Series$/
.
match
(
subclass
.
name
)[
1
]
product_name
=
/^(.+)Series$/
.
match
(
subclass
.
name
)[
1
]
...
...
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