Commit 3ab9ea8d authored by Robert Schilling's avatar Robert Schilling

Make staring API more restful

parent ea2193aa
...@@ -493,8 +493,8 @@ Parameters: ...@@ -493,8 +493,8 @@ Parameters:
### Star a project ### Star a project
Stars a given project. Returns status code 201 and the project on success and Stars a given project. Returns status code `201` and the project on success and
304 if the project is already starred. `304` if the project is already starred.
``` ```
POST /projects/:id/star POST /projects/:id/star
...@@ -556,11 +556,11 @@ Example response: ...@@ -556,11 +556,11 @@ Example response:
### Unstar a project ### Unstar a project
Unstars a given project. Returns status code 201 and the project on success Unstars a given project. Returns status code `200` and the project on success
and 304 if the project is already unstarred. and `304` if the project is not starred.
``` ```
POST /projects/:id/unstar DELETE /projects/:id/star
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
...@@ -568,7 +568,7 @@ POST /projects/:id/unstar ...@@ -568,7 +568,7 @@ POST /projects/:id/unstar
| `id` | integer | yes | The ID of the project | | `id` | integer | yes | The ID of the project |
```bash ```bash
curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/unstar" curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/star"
``` ```
Example response: Example response:
......
...@@ -279,13 +279,12 @@ module API ...@@ -279,13 +279,12 @@ module API
# Example Request: # Example Request:
# POST /projects/:id/star # POST /projects/:id/star
post ':id/star' do 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) current_user.toggle_star(user_project)
user_project.reload user_project.reload
present user_project, with: Entities::Project present user_project, with: Entities::Project
else
not_modified!
end end
end end
...@@ -294,8 +293,8 @@ module API ...@@ -294,8 +293,8 @@ module API
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# Example Request: # Example Request:
# POST /projects/:id/unstar # DELETE /projects/:id/unstar
post ':id/unstar' do delete ':id/star' do
if current_user.starred?(user_project) if current_user.starred?(user_project)
current_user.toggle_star(user_project) current_user.toggle_star(user_project)
user_project.reload user_project.reload
......
...@@ -1045,7 +1045,7 @@ describe API::API, api: true do ...@@ -1045,7 +1045,7 @@ describe API::API, api: true do
end end
end end
describe 'POST /projects/:id/unstar' do describe 'DELETE /projects/:id/star' do
context 'on a starred project' do context 'on a starred project' do
before do before do
user.toggle_star(project) user.toggle_star(project)
...@@ -1053,16 +1053,16 @@ describe API::API, api: true do ...@@ -1053,16 +1053,16 @@ describe API::API, api: true do
end end
it 'unstars the project' do it 'unstars the project' do
post api("/projects/#{project.id}/unstar", user) delete api("/projects/#{project.id}/star", user)
expect(response.status).to eq(201) expect(response.status).to eq(200)
expect(json_response['star_count']).to eq(0) expect(json_response['star_count']).to eq(0)
end end
end end
context 'on an unstarred project' do context 'on an unstarred project' do
it 'does not modify the star count' do it 'does not modify the star count' do
post api("/projects/#{project.id}/unstar", user) delete api("/projects/#{project.id}/star", user)
expect(response.status).to eq(304) expect(response.status).to eq(304)
expect(project.star_count).to eq(0) expect(project.star_count).to eq(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment