debian-mirror-gitlab/app/services/users/saved_replies/create_service.rb
2022-05-07 20:08:51 +05:30

29 lines
674 B
Ruby

# frozen_string_literal: true
module Users
module SavedReplies
class CreateService
def initialize(current_user:, name:, content:)
@current_user = current_user
@name = name
@content = content
end
def execute
saved_reply = saved_replies.build(name: name, content: content)
if saved_reply.save
ServiceResponse.success(payload: { saved_reply: saved_reply })
else
ServiceResponse.error(message: saved_reply.errors.full_messages)
end
end
private
attr_reader :current_user, :name, :content
delegate :saved_replies, to: :current_user
end
end
end