# encoding: utf-8 module Okei # Controllers for public JSON API routes. module Api # API v.1 controllers. module V1 # Controller for getting units class UnitsController < Responder # Returns either all units of measure or units of given measure. def index run_case GetUnits, with: :measure end # Finds a unit of measure by uuid. def show run_case GetUnit, with: :uuid end # Finds a unit of measure by text def search run_case FindUnit, with: :text end private # Initializes a corresponding use case (service) with allowed params, # subscribes for its results and then runs a use case. # # After running, the use case will call a method defined in the # `Responder` parent class. # def run_case(klass, with:) use_case = klass.new params.permit(*with) use_case.subscribe self, prefix: :on use_case.run end end end end end