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
11ba283c
Commit
11ba283c
authored
Aug 26, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish the spec for merchant product controller
parent
a6c14536
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
63 additions
and
40 deletions
+63
-40
.rspec_status
.rspec_status
+16
-16
index.json.jbuilder
...ators/templates/views/merchant/orders/index.json.jbuilder
+4
-2
index.json.jbuilder
...ors/templates/views/merchant/products/index.json.jbuilder
+1
-1
index.json.jbuilder
...ators/templates/views/merchant/series/index.json.jbuilder
+1
-1
index.json.jbuilder
...rs/templates/views/merchant/snapshots/index.json.jbuilder
+1
-1
_product.json.jbuilder
lib/generators/templates/views/share/_product.json.jbuilder
+3
-0
catalog.rb
lib/shotengai/catalog.rb
+1
-0
base.rb
lib/shotengai/controllers/base.rb
+15
-6
products_controller.rb
lib/shotengai/controllers/merchant/products_controller.rb
+19
-12
product.rb
lib/shotengai/product.rb
+2
-1
No files found.
.rspec_status
View file @
11ba283c
example_id | status | run_time |
------------------------------------------ | ------ | --------------- |
./spec/shotengai/models_spec.rb[1:1:1:1] | passed | 0.
4458
2 seconds |
./spec/shotengai/models_spec.rb[1:1:1:2] | passed | 0.
20555 seconds
|
./spec/shotengai/models_spec.rb[1:1:2:1] | passed | 0.
20124
seconds |
./spec/shotengai/models_spec.rb[1:1:2:2] | passed | 0.
17955
seconds |
./spec/shotengai/models_spec.rb[1:1:2:3] | passed | 0.
17157
seconds |
./spec/shotengai/models_spec.rb[1:1:3:1] | passed | 0.
19801
seconds |
./spec/shotengai/models_spec.rb[1:1:3:2] | passed | 0.
18172
seconds |
./spec/shotengai/models_spec.rb[1:1:3:3] | passed | 0.
1799
8 seconds |
./spec/shotengai/models_spec.rb[1:1:4:1] | passed | 0.
23986
seconds |
./spec/shotengai/models_spec.rb[1:1:5:1] | passed | 0.
17938
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:1] | passed | 0.
24027
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:2] | passed | 0.
21941
seconds |
./spec/shotengai/models_spec.rb[1:2:1:1] | passed | 0.
20203
seconds |
./spec/shotengai/models_spec.rb[1:2:1:2] | passed | 0.
21369 seconds
|
./spec/shotengai/models_spec.rb[1:2:2:1] | passed | 0.
43436
seconds |
./spec/shotengai/models_spec.rb[1:2:2:2] | passed | 0.
28966
seconds |
./spec/shotengai/models_spec.rb[1:1:1:1] | passed | 0.
5876
2 seconds |
./spec/shotengai/models_spec.rb[1:1:1:2] | passed | 0.
3368 seconds
|
./spec/shotengai/models_spec.rb[1:1:2:1] | passed | 0.
32969
seconds |
./spec/shotengai/models_spec.rb[1:1:2:2] | passed | 0.
32811
seconds |
./spec/shotengai/models_spec.rb[1:1:2:3] | passed | 0.
34035
seconds |
./spec/shotengai/models_spec.rb[1:1:3:1] | passed | 0.
32973
seconds |
./spec/shotengai/models_spec.rb[1:1:3:2] | passed | 0.
33056
seconds |
./spec/shotengai/models_spec.rb[1:1:3:3] | passed | 0.
3382
8 seconds |
./spec/shotengai/models_spec.rb[1:1:4:1] | passed | 0.
35822
seconds |
./spec/shotengai/models_spec.rb[1:1:5:1] | passed | 0.
33872
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:1] | passed | 0.
36586
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:2] | passed | 0.
36069
seconds |
./spec/shotengai/models_spec.rb[1:2:1:1] | passed | 0.
34614
seconds |
./spec/shotengai/models_spec.rb[1:2:1:2] | passed | 0.
3256 seconds
|
./spec/shotengai/models_spec.rb[1:2:2:1] | passed | 0.
62601
seconds |
./spec/shotengai/models_spec.rb[1:2:2:2] | passed | 0.
45201
seconds |
lib/generators/templates/views/merchant/orders/index.json.jbuilder
View file @
11ba283c
json.current_page @orders.current_page
json.total_pages @orders.total_pages
json.send(@orders.first.class.model_name.collection) @orders, partial: 'shotengai/share/order_simple', as: :order
\ No newline at end of file
json.set! @resources.klass.model_name.collection do
json.array! @resources, partial: 'shotengai/share/order_simple', as: :order
end
\ No newline at end of file
lib/generators/templates/views/merchant/products/index.json.jbuilder
View file @
11ba283c
json.current_page @resources.current_page
json.total_pages @resources.total_pages
json.set! @resources.
first.c
lass.model_name.collection do
json.set! @resources.
k
lass.model_name.collection do
json.array! @resources, partial: 'shotengai/share/product_simple', as: :product
end
lib/generators/templates/views/merchant/series/index.json.jbuilder
View file @
11ba283c
json.current_page @resources.current_page
json.total_pages @resources.total_pages
json.set! @resources.
first.c
lass.model_name.collection do
json.set! @resources.
k
lass.model_name.collection do
json.array! @resources, partial: 'shotengai/share/product_simple', as: :products
end
lib/generators/templates/views/merchant/snapshots/index.json.jbuilder
View file @
11ba283c
json.current_page @resources.current_page
json.total_pages @resources.total_pages
json.set! @resources.
first.c
lass.model_name.collection do
json.set! @resources.
k
lass.model_name.collection do
json.array! @resources, partial: 'shotengai/share/snapshot_simple', as: :snapshot
end
lib/generators/templates/views/share/_product.json.jbuilder
View file @
11ba283c
json.extract! product, :id, :title, :status, :need_express, :need_time_attr,
:cover_image, :banners, :spec, :detail, :meta
# TODO: NOTE: catalog_list is only vaild in the template example
json.catalog_list product.catalog_list
json.default_series product.default_series, partial: 'shotengai/share/series_simple', as: :series
\ No newline at end of file
lib/shotengai/catalog.rb
View file @
11ba283c
...
...
@@ -35,6 +35,7 @@ module Shotengai
end
def
validate_name_chain
name_ary
,
order
=
'desc'
return
nil
unless
name_ary
ary
=
order
.
downcase
.
eql?
(
'asc'
)
?
name_ary
.
reverse
:
name_ary
where
(
name:
ary
.
last
).
each
do
|
bottom_catalog
|
return
name_ary
if
bottom_catalog
.
name_chain
.
eql?
(
ary
)
...
...
lib/shotengai/controllers/base.rb
View file @
11ba283c
module
Shotengai
module
Controller
class
Base
<
ApplicationController
#
# The resources of this controller
# ActiveRecord::Relation or ActiveRecord::Base
#
cattr_accessor
:resources
#
# The view template dir
# respond_with @products, template: "#{self.class.template_dir}/index"
#
cattr_accessor
:template_dir
class
<<
self
# Add the index query to custom the @@index_resouces on the base of @@resources
# Foe example:
#
# index_query do |klass|
# index_query do |klass
, params
|
# klass.where(product: params[:product_id]).order('desc')
# end
#
def
index_query
&
block
#
为了保证 self 为Controller instance variable ?? 才能有params 方法??
#
could not get params here
@@index_query
=
block
# self.index_resouces = block.call(self.resources)
end
def
remove_methods
*
method_names
...
...
@@ -43,6 +46,11 @@ module Shotengai
before_action
:set_resource
,
except:
[
:index
,
:create
]
respond_to
:json
# TODO: could not catch the exception
# rescue_from Shotengai::WebError do |e|
# render json: { error: e.message }, status: e.status
# end
def
index
page
=
params
[
:page
]
||
1
per_page
=
params
[
:per_page
]
||
10
...
...
@@ -55,8 +63,9 @@ module Shotengai
end
def
create
default_resources
.
create!
(
resource_params
)
head
201
@resource
=
default_resources
.
create!
(
resource_params
)
# head 201
respond_with
@resource
,
template:
"
#{
@@template_dir
}
/show"
,
status:
201
end
def
update
...
...
@@ -71,7 +80,7 @@ module Shotengai
private
def
index_resources
@@index_query
&
.
call
(
default_resources
)
||
default_resources
@@index_query
&
.
call
(
default_resources
,
params
)
||
default_resources
end
def
default_resources
...
...
lib/shotengai/controllers/merchant/products_controller.rb
View file @
11ba283c
...
...
@@ -2,22 +2,23 @@ module Shotengai
module
Controller
module
Merchant
class
ProductsController
<
Shotengai
::
Controller
::
Base
self
.
resources
=
::
Product
self
.
template_dir
=
'sho
u
tengai/merchant/products/'
self
.
resources
=
'Product'
self
.
template_dir
=
'shotengai/merchant/products/'
index_query
do
|
resource
|
# params[:catalogs] nil 返回所有
resource
.
tagged_with
(
params
[
:catalogs
])
index_query
do
|
resource
,
params
|
params
[
:catalog_list
]
?
resource
.
tagged_with
(
params
[:
catalog_list
],
on: :catalogs
)
:
resource
end
def
put_on_shelf
@resource
.
put_on_shelf!
head
200
respond_with
@resource
,
template:
"
#{
@@template_dir
}
/show"
,
status:
200
end
def
sold_out
@resource
.
sold_out!
head
200
respond_with
@resource
,
template:
"
#{
@@template_dir
}
/show"
,
status:
200
end
def
destroy
...
...
@@ -27,20 +28,26 @@ module Shotengai
private
def
resource_params
resource_key
=
self
.
resource
.
model_name
.
singular
.
to_sym
# QUESTION: need these ?
spec
=
params
.
require
(
resource_key
).
fetch
(
:spec
,
nil
).
try
(
:permit!
)
d
atail
=
params
.
require
(
resource_key
).
fetch
(
:da
tail
,
nil
).
try
(
:permit!
)
d
etail
=
params
.
require
(
resource_key
).
fetch
(
:de
tail
,
nil
).
try
(
:permit!
)
meta
=
params
.
require
(
resource_key
).
fetch
(
:meta
,
nil
).
try
(
:permit!
)
params
.
requ
rie
(
).
permit
(
# NOTE: :catalog_list is a default catalog list for template example, maybe should move it to the template controller, but it need add controller template for every controller
params
.
requ
ire
(
resource_key
).
permit
(
:title
,
:default_series_id
,
:need_express
,
:need_time_attr
,
:cover_image
,
:need_express
,
:need_time_attr
,
:cover_image
,
catalog_list:
[],
banners:
[]
).
merge
(
{
spec:
spec
,
detail:
detail
,
meta:
meta
}
).
merge
(
other_resource_params
)
end
# rewrite this to add more custom column
def
other_resource_params
params
.
require
(
resource_key
).
permit
()
end
end
end
end
...
...
lib/shotengai/product.rb
View file @
11ba283c
...
...
@@ -73,9 +73,10 @@ module Shotengai
# tagger_with('xx', on: "#{tag_name}.to_sym): tag_name is plural
def
join_catalog_system
catalog_class_name
,
options
=
{}
catalog_class
=
catalog_class_name
.
constantize
tag_name
=
options
[
:as
]
||
catalog_class
.
model_name
.
collection
tag_name
=
options
[
:as
]
||
catalog_class
.
model_name
.
singular
acts_as_taggable_on
tag_name
.
to_sym
# 只有完整替换(只属于一个分类)的时候才进行验证,add remove 暂时未添加
# Just ctalogs_list = have a validation
class_eval
do
define_method
(
"
#{
tag_name
}
_list="
)
{
|
value
|
super
catalog_class
.
validate_name_chain
(
value
)
...
...
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