Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
39426213
Commit
39426213
authored
Jun 22, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose target, filter by state as string
parent
fd9cd5ae
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
377 additions
and
120 deletions
+377
-120
app/finders/todos_finder.rb
app/finders/todos_finder.rb
+21
-0
doc/api/todos.md
doc/api/todos.md
+337
-110
lib/api/entities.rb
lib/api/entities.rb
+4
-4
lib/api/todos.rb
lib/api/todos.rb
+3
-3
spec/requests/api/todos_spec.rb
spec/requests/api/todos_spec.rb
+12
-3
No files found.
app/finders/todos_finder.rb
View file @
39426213
...
...
@@ -25,6 +25,7 @@ class TodosFinder
def
execute
items
=
current_user
.
todos
items
=
by_action_id
(
items
)
items
=
by_action
(
items
)
items
=
by_author
(
items
)
items
=
by_project
(
items
)
items
=
by_state
(
items
)
...
...
@@ -43,6 +44,18 @@ class TodosFinder
params
[
:action_id
]
end
def
to_action_id
Todo
::
ACTION_NAMES
.
key
(
action
.
to_sym
)
end
def
action?
action
.
present?
&&
to_action_id
end
def
action
params
[
:action
]
end
def
author?
params
[
:author_id
].
present?
end
...
...
@@ -96,6 +109,14 @@ class TodosFinder
params
[
:type
]
end
def
by_action
(
items
)
if
action?
items
=
items
.
where
(
action:
to_action_id
)
end
items
end
def
by_action_id
(
items
)
if
action_id?
items
=
items
.
where
(
action:
action_id
)
...
...
doc/api/todos.md
View file @
39426213
This diff is collapsed.
Click to expand it.
lib/api/entities.rb
View file @
39426213
...
...
@@ -277,16 +277,16 @@ module API
expose
:project
,
using:
Entities
::
BasicProjectDetails
expose
:author
,
using:
Entities
::
UserBasic
expose
:action_name
expose
:target_id
expose
:target_type
expose
:target_reference
do
|
todo
,
options
|
todo
.
target
.
to_reference
expose
:target
do
|
todo
,
options
|
Entities
.
const_get
(
todo
.
target_type
).
represent
(
todo
.
target
,
options
)
end
expose
:target_url
do
|
todo
,
options
|
target_type
=
todo
.
target_type
.
underscore
target_url
=
"namespace_project_
#{
target_type
}
_url"
target_anchor
=
"note_
#{
todo
.
note_id
}
"
if
todo
.
note
.
present
?
target_anchor
=
"note_
#{
todo
.
note_id
}
"
if
todo
.
note
_id
?
Gitlab
::
Application
.
routes
.
url_helpers
.
public_send
(
target_url
,
todo
.
project
.
namespace
,
todo
.
project
,
todo
.
target
,
anchor:
target_anchor
)
...
...
lib/api/todos.rb
View file @
39426213
...
...
@@ -18,7 +18,7 @@ module API
get
do
todos
=
find_todos
present
paginate
(
todos
),
with:
Entities
::
Todo
present
paginate
(
todos
),
with:
Entities
::
Todo
,
current_user:
current_user
end
# Mark a todo as done
...
...
@@ -33,7 +33,7 @@ module API
todo
=
current_user
.
todos
.
find
(
params
[
:id
])
todo
.
done
present
todo
,
with:
Entities
::
Todo
present
todo
,
with:
Entities
::
Todo
,
current_user:
current_user
end
# Mark all todos as done
...
...
@@ -45,7 +45,7 @@ module API
todos
=
find_todos
todos
.
each
(
&
:done
)
present
paginate
(
Kaminari
.
paginate_array
(
todos
)),
with:
Entities
::
Todo
present
paginate
(
Kaminari
.
paginate_array
(
todos
)),
with:
Entities
::
Todo
,
current_user:
current_user
end
end
end
...
...
spec/requests/api/todos_spec.rb
View file @
39426213
...
...
@@ -9,7 +9,7 @@ describe API::Todos, api: true do
let
(
:author_2
)
{
create
(
:user
)
}
let
(
:john_doe
)
{
create
(
:user
,
username:
'john_doe'
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project_1
)
}
let!
(
:pending_1
)
{
create
(
:todo
,
project:
project_1
,
author:
author_1
,
user:
john_doe
)
}
let!
(
:pending_1
)
{
create
(
:todo
,
:mentioned
,
project:
project_1
,
author:
author_1
,
user:
john_doe
)
}
let!
(
:pending_2
)
{
create
(
:todo
,
project:
project_2
,
author:
author_2
,
user:
john_doe
)
}
let!
(
:pending_3
)
{
create
(
:todo
,
project:
project_1
,
author:
author_2
,
user:
john_doe
,
target:
merge_request
)
}
let!
(
:done
)
{
create
(
:todo
,
:done
,
project:
project_1
,
author:
author_1
,
user:
john_doe
)
}
...
...
@@ -38,9 +38,8 @@ describe API::Todos, api: true do
expect
(
json_response
[
0
][
'id'
]).
to
eq
(
pending_3
.
id
)
expect
(
json_response
[
0
][
'project'
]).
to
be_a
Hash
expect
(
json_response
[
0
][
'author'
]).
to
be_a
Hash
expect
(
json_response
[
0
][
'target_id'
]).
to
be_present
expect
(
json_response
[
0
][
'target_type'
]).
to
be_present
expect
(
json_response
[
0
][
'target
_reference'
]).
to
be_present
expect
(
json_response
[
0
][
'target
'
]).
to
be_a
Hash
expect
(
json_response
[
0
][
'target_url'
]).
to
be_present
expect
(
json_response
[
0
][
'body'
]).
to
be_present
expect
(
json_response
[
0
][
'state'
]).
to
eq
(
'pending'
)
...
...
@@ -87,6 +86,16 @@ describe API::Todos, api: true do
expect
(
json_response
.
length
).
to
eq
(
1
)
end
end
context
'and using the action filter'
do
it
'filters based on action param'
do
get
api
(
'/todos'
,
john_doe
),
{
action:
'mentioned'
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
end
end
end
end
...
...
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