Sha256: b65195c80ea6eaf389303d7d5f76fc47f8ea2593731ea32ad277832356c8f78c

Contents?: true

Size: 1016 Bytes

Versions: 3

Compression:

Stored size: 1016 Bytes

Contents

# 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 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rider-kick-0.0.10 lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt
rider-kick-0.0.9 lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt
rider-kick-0.0.8 lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt