Commit 1ef911f0 authored by Robert Schilling's avatar Robert Schilling

API: Use POST requests to mark todos as done

parent b596dd8f
---
title: 'API: Use POST requests to mark todos as done'
merge_request: 9410
author: Robert Schilling
...@@ -184,7 +184,7 @@ Marks a single pending todo given by its ID for the current user as done. The ...@@ -184,7 +184,7 @@ Marks a single pending todo given by its ID for the current user as done. The
todo marked as done is returned in the response. todo marked as done is returned in the response.
``` ```
DELETE /todos/:id POST /todos/:id/mark_as_done
``` ```
Parameters: Parameters:
...@@ -194,7 +194,7 @@ Parameters: ...@@ -194,7 +194,7 @@ Parameters:
| `id` | integer | yes | The ID of a todo | | `id` | integer | yes | The ID of a todo |
```bash ```bash
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/todos/130 curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/todos/130/mark_as_done
``` ```
Example Response: Example Response:
...@@ -277,20 +277,15 @@ Example Response: ...@@ -277,20 +277,15 @@ Example Response:
## Mark all todos as done ## Mark all todos as done
Marks all pending todos for the current user as done. It returns the number of marked todos. Marks all pending todos for the current user as done. It returns the HTTP status code `204` with an empty response.
``` ```
DELETE /todos POST /todos/mark_as_done
``` ```
```bash ```bash
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/todos curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/todos/donmark_as_donee
``` ```
Example Response:
```json
3
```
[ce-3188]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3188 [ce-3188]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3188
...@@ -24,9 +24,9 @@ changes are in V4: ...@@ -24,9 +24,9 @@ changes are in V4:
- `/gitlab_ci_ymls/:key` - `/gitlab_ci_ymls/:key`
- `/dockerfiles/:key` - `/dockerfiles/:key`
- Moved `/projects/fork/:id` to `/projects/:id/fork` - Moved `/projects/fork/:id` to `/projects/:id/fork`
- Moved `DELETE /todos` to `POST /todos/mark_as_done` and `DELETE /todos/:todo_id` to `POST /todos/:todo_id/mark_as_done`
- Endpoints `/projects/owned`, `/projects/visible`, `/projects/starred` & `/projects/all` are consolidated into `/projects` using query parameters - Endpoints `/projects/owned`, `/projects/visible`, `/projects/starred` & `/projects/all` are consolidated into `/projects` using query parameters
- Return pagination headers for all endpoints that return an array - Return pagination headers for all endpoints that return an array
- Removed `DELETE projects/:id/deploy_keys/:key_id/disable`. Use `DELETE projects/:id/deploy_keys/:key_id` instead - Removed `DELETE projects/:id/deploy_keys/:key_id/disable`. Use `DELETE projects/:id/deploy_keys/:key_id` instead
- Moved `PUT /users/:id/(block|unblock)` to `POST /users/:id/(block|unblock)` - Moved `PUT /users/:id/(block|unblock)` to `POST /users/:id/(block|unblock)`
- Labels filter on `projects/:id/issues` and `/issues` now matches only issues containing all labels (i.e.: Logical AND, not OR) - Labels filter on `projects/:id/issues` and `/issues` now matches only issues containing all labels (i.e.: Logical AND, not OR)
...@@ -58,7 +58,7 @@ def find_todos ...@@ -58,7 +58,7 @@ def find_todos
params do params do
requires :id, type: Integer, desc: 'The ID of the todo being marked as done' requires :id, type: Integer, desc: 'The ID of the todo being marked as done'
end end
delete ':id' do post ':id/mark_as_done' do
todo = current_user.todos.find(params[:id]) todo = current_user.todos.find(params[:id])
TodoService.new.mark_todos_as_done([todo], current_user) TodoService.new.mark_todos_as_done([todo], current_user)
...@@ -66,9 +66,11 @@ def find_todos ...@@ -66,9 +66,11 @@ def find_todos
end end
desc 'Mark all todos as done' desc 'Mark all todos as done'
delete do post '/mark_as_done' do
todos = find_todos todos = find_todos
TodoService.new.mark_todos_as_done(todos, current_user) TodoService.new.mark_todos_as_done(todos, current_user)
no_content!
end end
end end
end end
......
...@@ -107,46 +107,47 @@ ...@@ -107,46 +107,47 @@
end end
end end
describe 'DELETE /todos/:id' do describe 'POST /todos/:id/mark_as_done' do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'returns authentication error' do it 'returns authentication error' do
delete api("/todos/#{pending_1.id}") post api("/todos/#{pending_1.id}/mark_as_done")
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'marks a todo as done' do it 'marks a todo as done' do
delete api("/todos/#{pending_1.id}", john_doe) post api("/todos/#{pending_1.id}/mark_as_done", john_doe)
expect(response.status).to eq(200) expect(response).to have_http_status(201)
expect(json_response['id']).to eq(pending_1.id)
expect(json_response['state']).to eq('done')
expect(pending_1.reload).to be_done expect(pending_1.reload).to be_done
end end
it 'updates todos cache' do it 'updates todos cache' do
expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original
delete api("/todos/#{pending_1.id}", john_doe) post api("/todos/#{pending_1.id}/mark_as_done", john_doe)
end end
end end
end end
describe 'DELETE /todos' do describe 'POST /mark_as_done' do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'returns authentication error' do it 'returns authentication error' do
delete api('/todos') post api('/todos/mark_as_done')
expect(response.status).to eq(401) expect(response).to have_http_status(401)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'marks all todos as done' do it 'marks all todos as done' do
delete api('/todos', john_doe) post api('/todos/mark_as_done', john_doe)
expect(response.status).to eq(200) expect(response).to have_http_status(204)
expect(response.body).to eq('3')
expect(pending_1.reload).to be_done expect(pending_1.reload).to be_done
expect(pending_2.reload).to be_done expect(pending_2.reload).to be_done
expect(pending_3.reload).to be_done expect(pending_3.reload).to be_done
...@@ -155,7 +156,7 @@ ...@@ -155,7 +156,7 @@
it 'updates todos cache' do it 'updates todos cache' do
expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original expect_any_instance_of(User).to receive(:update_todos_count_cache).and_call_original
delete api("/todos", john_doe) post api("/todos/mark_as_done", john_doe)
end end
end end
end end
......
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