Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
7f735ea4
Commit
7f735ea4
authored
8 years ago
by
Giovanne Marcelo
Browse files
Options
Downloads
Patches
Plain Diff
fix collection params
parent
47028120
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/v1/collections_controller.rb
+10
-14
10 additions, 14 deletions
app/controllers/v1/collections_controller.rb
app/models/collection.rb
+7
-0
7 additions, 0 deletions
app/models/collection.rb
with
17 additions
and
14 deletions
app/controllers/v1/collections_controller.rb
+
10
−
14
View file @
7f735ea4
...
...
@@ -7,7 +7,7 @@ class V1::CollectionsController < ApplicationController
include
::
Paginator
before_action
:set_collection
,
only:
[
:show
,
:update
,
:destroy
,
:add_object
,
:set_collection_items
]
before_action
:set_collection
,
only:
[
:show
,
:update
,
:destroy
,
:add_object
]
before_action
:authenticate_user!
,
only:
[
:create
,
:update
,
:destroy
]
# GET /v1/collections
...
...
@@ -27,9 +27,10 @@ class V1::CollectionsController < ApplicationController
# POST /v1/collection.json
def
create
collection
=
Collection
.
new
(
collection_params
)
set_collection_items
if
collection
.
save
collection
.
add_items
(
items_params
[
:items
])
render
json:
collection
,
status: :created
else
render
json:
collection
.
errors
,
status: :unprocessable_entity
...
...
@@ -40,9 +41,8 @@ class V1::CollectionsController < ApplicationController
# PUT/PATCH /v1/users/1.json
def
update
set_collection_items
if
@collection
.
update
(
collection_params
)
@collection
.
add_items
(
items_params
[
:items
])
render
json:
@collection
,
status: :ok
else
render
json:
@collection
.
errors
,
status: :unprocessable_entity
...
...
@@ -59,7 +59,7 @@ class V1::CollectionsController < ApplicationController
# POST /v1/collections/!/items
def
add_object
render
nothing:
true
,
status: :unprocessable_entity
if
params
.
nil?
set_
collection_items
@
collection
.
add
_items
(
items_params
[
:items
])
render
json:
@collection
,
status: :ok
end
...
...
@@ -77,17 +77,13 @@ class V1::CollectionsController < ApplicationController
@collection
||=
Collection
.
find
(
params
[
:id
])
end
def
set_collection_items
items
=
collection_params
[
:items
]
collection_items
=
items
.
map
{
|
item
|
CollectionItem
.
new
(
collection:
@collection
,
collectionable:
item
[
:type
].
constantize
.
find
(
item
[
:id
]),
order:
item
[
:order
])}
CollectionItem
.
import
collection_items
,
on_duplicate_key_update:
{
conflict_target:
[
:collection_id
,
:collectionable_id
,
:collectionable_type
]}
end
# Never trust parameters from the scary internet, only allow the white list through.
def
collection_params
params
.
require
(
:collection
).
permit
(
:name
,
:description
,
:owner_id
,
:owner_type
,
:privacy
,
tags:
[],
items:
[
:type
,
:id
])
params
.
require
(
:collection
).
permit
(
:name
,
:description
,
:owner_id
,
:owner_type
,
:privacy
,
tags:
[])
end
def
items_params
params
.
require
(
:collection
).
permit
(
items:
[
:type
,
:id
,
:order
])
end
end
This diff is collapsed.
Click to expand it.
app/models/collection.rb
+
7
−
0
View file @
7f735ea4
...
...
@@ -74,6 +74,13 @@ class Collection < ApplicationRecord
privacy
==
'private'
end
def
add_items
(
items
)
collection_items
=
items
.
map
{
|
item
|
CollectionItem
.
new
(
collection:
self
,
collectionable:
item
[
:type
].
constantize
.
find
(
item
[
:id
]),
order:
item
[
:order
])}
CollectionItem
.
import
collection_items
,
on_duplicate_key_update:
{
conflict_target:
[
:collection_id
,
:collectionable_id
,
:collectionable_type
],
columns:
[
:order
]}
end
## score methods
def
user_category
owner
.
try
(
'user_category'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment