class Api::V1::Users::Feedbacks::CreateService < ApplicationService 
  include ActiveModel::Model 

  attr_reader :user, :content
  attr_accessor :feedback

  validates :content, presence: true

  def initialize(user, params)
    @user = user 
    @content = params[:content]
  end

  def call 
    raise Error, errors.full_messages.join(",") unless valid? 

    begin
      @feedback = Feedback.new(user: user, content: content)
      @feedback.save!

      return @feedback.valid? ? @feedback : nil
    rescue
      raise Error, "服务器错误，请联系系统管理员！"
    end
  end
end