module Api module V1 module Gateway class HeartbeatsController < BaseController def create current_gateway.heartbeat! # Update metadata with device info metadata = { battery_level: params[:battery_level], signal_strength: params[:signal_strength], messages_in_queue: params[:messages_in_queue] }.compact current_gateway.update(metadata: metadata) if metadata.any? # Get count of pending messages for this gateway pending_count = SmsMessage.pending .where(gateway_id: [nil, current_gateway.id]) .count render json: { success: true, pending_messages: pending_count } end end end end end