summaryrefslogtreecommitdiff
path: root/app/services/milestones
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-10 18:07:52 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-10 18:07:52 +0300
commitc4b02642d2ca74f463e64dd591796aabe5c54af9 (patch)
tree51556478ddc29fd51e16b8f2b8e3512e5cc168d7 /app/services/milestones
parentf8ea52c3a0fe29daf76fbd7a0e65399c09c95f5a (diff)
downloadgitlab-ce-c4b02642d2ca74f463e64dd591796aabe5c54af9.tar.gz
Replace milestone observer with services
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services/milestones')
-rw-r--r--app/services/milestones/base_service.rb4
-rw-r--r--app/services/milestones/close_service.rb11
-rw-r--r--app/services/milestones/create_service.rb13
-rw-r--r--app/services/milestones/reopen_service.rb11
-rw-r--r--app/services/milestones/update_service.rb20
5 files changed, 59 insertions, 0 deletions
diff --git a/app/services/milestones/base_service.rb b/app/services/milestones/base_service.rb
new file mode 100644
index 00000000000..176ab9f1ab5
--- /dev/null
+++ b/app/services/milestones/base_service.rb
@@ -0,0 +1,4 @@
+module Milestones
+ class BaseService < ::BaseService
+ end
+end
diff --git a/app/services/milestones/close_service.rb b/app/services/milestones/close_service.rb
new file mode 100644
index 00000000000..608fc49d766
--- /dev/null
+++ b/app/services/milestones/close_service.rb
@@ -0,0 +1,11 @@
+module Milestones
+ class CloseService < Milestones::BaseService
+ def execute(milestone)
+ if milestone.close
+ event_service.close_milestone(milestone, current_user)
+ end
+
+ milestone
+ end
+ end
+end
diff --git a/app/services/milestones/create_service.rb b/app/services/milestones/create_service.rb
new file mode 100644
index 00000000000..b8e08c9f1eb
--- /dev/null
+++ b/app/services/milestones/create_service.rb
@@ -0,0 +1,13 @@
+module Milestones
+ class CreateService < Milestones::BaseService
+ def execute
+ milestone = project.milestones.new(params)
+
+ if milestone.save
+ event_service.open_milestone(milestone, current_user)
+ end
+
+ milestone
+ end
+ end
+end
diff --git a/app/services/milestones/reopen_service.rb b/app/services/milestones/reopen_service.rb
new file mode 100644
index 00000000000..ff1ba23bdb2
--- /dev/null
+++ b/app/services/milestones/reopen_service.rb
@@ -0,0 +1,11 @@
+module Milestones
+ class ReopenService < Milestones::BaseService
+ def execute(milestone)
+ if milestone.reopen
+ event_service.reopen_milestone(milestone, current_user)
+ end
+
+ milestone
+ end
+ end
+end
diff --git a/app/services/milestones/update_service.rb b/app/services/milestones/update_service.rb
new file mode 100644
index 00000000000..69254a79670
--- /dev/null
+++ b/app/services/milestones/update_service.rb
@@ -0,0 +1,20 @@
+module Milestones
+ class UpdateService < Milestones::BaseService
+ def execute(milestone)
+ state = params.delete('state_event')
+
+ case state
+ when 'reopen'
+ Milestones::ReopenService.new(project, current_user, {}).execute(milestone)
+ when 'close'
+ Milestones::CloseService.new(project, current_user, {}).execute(milestone)
+ end
+
+ if params.present?
+ milestone.update_attributes(params)
+ end
+
+ milestone
+ end
+ end
+end