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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
3ab9ea8d
Commit
3ab9ea8d
authored
Apr 12, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make staring API more restful
parent
ea2193aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
16 deletions
+15
-16
doc/api/projects.md
doc/api/projects.md
+6
-6
lib/api/projects.rb
lib/api/projects.rb
+5
-6
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+4
-4
No files found.
doc/api/projects.md
View file @
3ab9ea8d
...
...
@@ -493,8 +493,8 @@ Parameters:
### Star a project
Stars a given project. Returns status code
201
and the project on success and
304
if the project is already starred.
Stars a given project. Returns status code
`201`
and the project on success and
`304`
if the project is already starred.
```
POST /projects/:id/star
...
...
@@ -556,11 +556,11 @@ Example response:
### Unstar a project
Unstars a given project. Returns status code
201
and the project on success
and
304 if the project is already un
starred.
Unstars a given project. Returns status code
`200`
and the project on success
and
`304`
if the project is not
starred.
```
POST /projects/:id/un
star
DELETE /projects/:id/
star
```
| Attribute | Type | Required | Description |
...
...
@@ -568,7 +568,7 @@ POST /projects/:id/unstar
|
`id`
| integer | yes | The ID of the project |
```
bash
curl
-X
POST
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
"https://gitlab.example.com/api/v3/projects/5/un
star"
curl
-X
DELETE
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
"https://gitlab.example.com/api/v3/projects/5/
star"
```
Example response:
...
...
lib/api/projects.rb
View file @
3ab9ea8d
...
...
@@ -279,13 +279,12 @@ module API
# Example Request:
# POST /projects/:id/star
post
':id/star'
do
if
!
current_user
.
starred?
(
user_project
)
if
current_user
.
starred?
(
user_project
)
not_modified!
else
current_user
.
toggle_star
(
user_project
)
user_project
.
reload
present
user_project
,
with:
Entities
::
Project
else
not_modified!
end
end
...
...
@@ -294,8 +293,8 @@ module API
# Parameters:
# id (required) - The ID of a project
# Example Request:
#
POST
/projects/:id/unstar
post
':id/un
star'
do
#
DELETE
/projects/:id/unstar
delete
':id/
star'
do
if
current_user
.
starred?
(
user_project
)
current_user
.
toggle_star
(
user_project
)
user_project
.
reload
...
...
spec/requests/api/projects_spec.rb
View file @
3ab9ea8d
...
...
@@ -1045,7 +1045,7 @@ describe API::API, api: true do
end
end
describe
'
POST /projects/:id/un
star'
do
describe
'
DELETE /projects/:id/
star'
do
context
'on a starred project'
do
before
do
user
.
toggle_star
(
project
)
...
...
@@ -1053,16 +1053,16 @@ describe API::API, api: true do
end
it
'unstars the project'
do
post
api
(
"/projects/
#{
project
.
id
}
/un
star"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/
star"
,
user
)
expect
(
response
.
status
).
to
eq
(
20
1
)
expect
(
response
.
status
).
to
eq
(
20
0
)
expect
(
json_response
[
'star_count'
]).
to
eq
(
0
)
end
end
context
'on an unstarred project'
do
it
'does not modify the star count'
do
post
api
(
"/projects/
#{
project
.
id
}
/un
star"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/
star"
,
user
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
project
.
star_count
).
to
eq
(
0
)
...
...
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