Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-02 14:38:35 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-02 14:38:35 +0400
commitcfd9fd30d60c5a880785acda27e9f3d55b17e4ef (patch)
treed37dd2c0e2243e6c75f443861bc7568bcd8a78a2 /lib/api
parent3b0510a7c124a8511966ad4785757bd4d78998ac (diff)
Move code for issue creation to service.
The goal of suych refactoring is to get rid of observers. Its much easier to test and code when object creation and all other related actions done in one class instead of splited across observers, callbacks etc. Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/issues.rb20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 3d15c35b8cc..169c58b0075 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -48,17 +48,15 @@ module API
# Example Request:
# POST /projects/:id/issues
post ":id/issues" do
- set_current_user_for_thread do
- required_attributes! [:title]
- attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id]
- attrs[:label_list] = params[:labels] if params[:labels].present?
- @issue = user_project.issues.new attrs
- @issue.author = current_user
- if @issue.save
- present @issue, with: Entities::Issue
- else
- not_found!
- end
+ required_attributes! [:title]
+ attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id]
+ attrs[:label_list] = params[:labels] if params[:labels].present?
+ issue = ::Issues::CreateService.new(user_project, current_user, attrs).execute
+
+ if issue.valid?
+ present issue, with: Entities::Issue
+ else
+ not_found!
end
end