completed SMS gateway project
This commit is contained in:
37
app/controllers/admin/logs_controller.rb
Normal file
37
app/controllers/admin/logs_controller.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
module Admin
|
||||
class LogsController < BaseController
|
||||
def index
|
||||
@pagy, @messages = pagy(
|
||||
apply_filters(SmsMessage).order(created_at: :desc),
|
||||
items: 50
|
||||
)
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user