50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
module Api
|
|
module V1
|
|
module Admin
|
|
class GatewaysController < ApplicationController
|
|
include ApiAuthenticatable
|
|
|
|
# GET /api/v1/admin/gateways
|
|
def index
|
|
gateways = ::Gateway.order(created_at: :desc)
|
|
|
|
render json: {
|
|
gateways: gateways.map { |gateway|
|
|
{
|
|
id: gateway.id,
|
|
device_id: gateway.device_id,
|
|
name: gateway.name,
|
|
status: gateway.status,
|
|
last_heartbeat_at: gateway.last_heartbeat_at,
|
|
messages_sent_today: gateway.messages_sent_today,
|
|
messages_received_today: gateway.messages_received_today,
|
|
total_messages_sent: gateway.total_messages_sent,
|
|
total_messages_received: gateway.total_messages_received,
|
|
active: gateway.active,
|
|
priority: gateway.priority,
|
|
metadata: gateway.metadata,
|
|
created_at: gateway.created_at
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
# POST /api/v1/admin/gateways/:id/toggle
|
|
def toggle
|
|
gateway = ::Gateway.find(params[:id])
|
|
gateway.update!(active: !gateway.active)
|
|
|
|
render json: {
|
|
success: true,
|
|
gateway: {
|
|
id: gateway.id,
|
|
device_id: gateway.device_id,
|
|
active: gateway.active
|
|
}
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|