HabitatMap/AirCasting

View on GitHub
app/controllers/api/mobile/autocomplete_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage
module Api
  class Mobile::AutocompleteController < ApplicationController
    def tags
      GoogleAnalyticsWorker::RegisterEvent.async_call(
        'Autocomplete Mobile#tags'
      )
      q = params.to_unsafe_hash[:q].symbolize_keys

      q[:time_from] = Time.strptime(q[:time_from].to_s, '%s')
      q[:time_to] = Time.strptime(q[:time_to].to_s, '%s')

      form =
        Api::ParamsForm.new(
          params: q,
          schema: Api::MobileTagsParams::Schema,
          struct: Api::MobileTagsParams::Struct
        )

      result = Api::ToMobileTags.new(form: form).call

      if result.success?
        render json: result.value, status: :ok
      else
        render json: result.errors, status: :bad_request
      end
    end
  end
end