Files
MySMSAPio/app/controllers/admin/logs_controller.rb
Min Zeya Phyo 1fdff55544
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
SMS gateway api service for android application
2026-01-27 11:24:16 +06:30

41 lines
1.1 KiB
Ruby

module Admin
class LogsController < BaseController
def index
items_per_page = params[:items]&.to_i || 50
items_per_page = 50 unless [10, 25, 50, 100].include?(items_per_page)
@pagy, @messages = pagy(
apply_filters(SmsMessage).order(created_at: :desc),
items: items_per_page
)
respond_to do |format|
format.html
format.turbo_stream
end
end
private
def apply_filters(scope)
scope = scope.where(direction: params[:direction]) if params[:direction].present?
scope = scope.where(status: params[:status]) if params[:status].present?
scope = scope.where(gateway_id: params[:gateway_id]) if params[:gateway_id].present?
if params[:phone_number].present?
scope = scope.where("phone_number LIKE ?", "%#{params[:phone_number]}%")
end
if params[:start_date].present?
scope = scope.where("created_at >= ?", Time.parse(params[:start_date]))
end
if params[:end_date].present?
scope = scope.where("created_at <= ?", Time.parse(params[:end_date]).end_of_day)
end
scope
end
end
end