diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2016-06-28 18:04:44 +0200 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2016-07-01 14:52:04 +0200 |
commit | 87ac9c9850d602fd18654498ab3fa005d2b85ac7 (patch) | |
tree | b9fe37acee0d9dae2f931504ebdf3ff7a2ec06e2 /lib/api/todos.rb | |
parent | 3942621329b20307c1676d60324c8f47ea1e1b37 (diff) | |
download | gitlab-ce-87ac9c9850d602fd18654498ab3fa005d2b85ac7.tar.gz |
Support creating a todo on issuables via APItodos-api
Diffstat (limited to 'lib/api/todos.rb')
-rw-r--r-- | lib/api/todos.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/api/todos.rb b/lib/api/todos.rb index 8334baad1b9..2a6bfa98ca4 100644 --- a/lib/api/todos.rb +++ b/lib/api/todos.rb @@ -3,6 +3,36 @@ module API class Todos < Grape::API before { authenticate! } + ISSUABLE_TYPES = { + 'merge_requests' => ->(id) { user_project.merge_requests.find(id) }, + 'issues' => ->(id) { find_project_issue(id) } + } + + resource :projects do + ISSUABLE_TYPES.each do |type, finder| + type_id_str = "#{type.singularize}_id".to_sym + + # Create a todo on an issuable + # + # Parameters: + # id (required) - The ID of a project + # issuable_id (required) - The ID of an issuable + # Example Request: + # POST /projects/:id/issues/:issuable_id/todo + # POST /projects/:id/merge_requests/:issuable_id/todo + post ":id/#{type}/:#{type_id_str}/todo" do + issuable = instance_exec(params[type_id_str], &finder) + todo = TodoService.new.mark_todo(issuable, current_user).first + + if todo + present todo, with: Entities::Todo, current_user: current_user + else + not_modified! + end + end + end + end + resource :todos do helpers do def find_todos |