module RedmineEventOutbox
  module Hooks
    class IssuesHook < Redmine::Hook::ViewListener
      def controller_issues_new_after_save(context = {})
        return unless context[:issue]

        RedmineEventOutbox::Event.record_issue_created(
          context[:issue],
          User.current
        )
      end

      def controller_issues_edit_after_save(context = {})
        return unless context[:issue]

        RedmineEventOutbox::Event.record_issue_updated(
          context[:issue],
          context[:journal],
          User.current
        )
      end
    end
  end
end
