# frozen_string_literal: true class Core::Repositories::<%= @scope_class %>::<%= @repository_class%> < Core::Repositories::AbstractRepository def initialize(params:) @params = prepare! params, sanitize: true build_pagination_variable! @params end def call(builder: true) <% if @resource_owner_id.present? -%> resources = <%= @model_class %>.where(<%=@resource_owner_id%>: @params.<%=@resource_owner_id%>) <% else -%> resources = <%= @model_class %> <% end -%> if @search.present? resources = resources.where('<%= @search_able.map { |field| "LOWER(#{field}) LIKE :search" }.join(' OR ')%>', search: "%#{search}%") end return Success Success Hashie::Mash.new(response: [], meta: {}) unless resources.present? pagy, results = pagy(resources.order(created_at: :desc), limit: @per_page, page: @page) response = results.map { |result| Core::Builders::<%= @subject_class %>.new(result).build } Success Hashie::Mash.new(response: response, meta: paginate!(pagy)) end end