Sha256: 4b2af47f70711f37d64091ae82b750ca59209dec24308c137d164b7f3d1890e0

Contents?: true

Size: 970 Bytes

Versions: 4

Compression:

Stored size: 970 Bytes

Contents

module RestPack::Activity::Service::Commands::Activity
  class Create < RestPack::Service::Command
    required do
      integer :application_id
      integer :user_id
      string  :content
    end

    optional do
      string  :title, empty: true
      string  :tags, empty: true
      string  :access, empty: true
      float   :latitude
      float   :longitude
    end

    def init
      inputs[:data] = raw_inputs[:data] if raw_inputs[:data]

      if latitude.present? || longitude.present?
        if latitude.present? != longitude.present?
          service_error "Both Latitude and Longitude are required"
        end
      end

      if title == "error"
        service_error "This is a service error"
      end

      if title == "custom"
        field_error :title, "Title should not be 'custom'"
      end
    end

    def execute
      activity = Models::Activity.create(inputs)
      Serializers::ActivitySerializer.as_json(activity)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
restpack_activity_service-0.0.10 lib/restpack_activity_service/services/activity/create.rb
restpack_activity_service-0.0.9 lib/restpack_activity_service/services/activity/create.rb
restpack_activity_service-0.0.8 lib/restpack_activity_service/services/activity/create.rb
restpack_activity_service-0.0.7 lib/restpack_activity_service/services/activity/create.rb