From bcf913991ff8102f38783e3abd8544aa2f997239 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Fri, 27 Apr 2018 11:49:59 -0500 Subject: [PATCH] WIP --- app/controllers/api/devices_controller.rb | 8 +++- app/mutations/devices/dump.rb | 46 ++++++++++++----------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/app/controllers/api/devices_controller.rb b/app/controllers/api/devices_controller.rb index a19274878..6b7f97c0e 100644 --- a/app/controllers/api/devices_controller.rb +++ b/app/controllers/api/devices_controller.rb @@ -25,7 +25,13 @@ module Api end def dump - mutate Devices::Dump.run(device: current_device) + raise "Need to write tests for this and `dump_status`" + Devices::Dump.run_by_id(current_device.id) + render json: {ok: "OK"} + end + + def dump_status + raise "Need a way to check the status of the job." end end end diff --git a/app/mutations/devices/dump.rb b/app/mutations/devices/dump.rb index 7ab172e0d..1dbecc95f 100644 --- a/app/mutations/devices/dump.rb +++ b/app/mutations/devices/dump.rb @@ -1,33 +1,35 @@ module Devices - # DO NOT USE THIS IN YOUR APPLICATION! = = = = = = - # Download all your account data as a single JSON document. Used by the dev - # team to debug data related issues (especially those that are specific to a - # particular server or database). - # DO NOT USE THIS IN YOUR APPLICATION! = = = = = = class Dump < Mutations::Command - RESOURCES = [ - Pair[:images, ImageSerializer], - Pair[:regimens, RegimenSerializer], - Pair[:peripherals, PeripheralSerializer], - # Pair[:sequences, SequenceSerializer], - Pair[:farm_events, FarmEventSerializer], - # Pair[:tools, ToolSerializer], - # Pair[:points, PointSerializer], - Pair[:users, UserSerializer], - Pair[:webcam_feeds, WebcamFeedSerializer] - ] + RESOURCES = { + farm_events: FarmEventSerializer, + images: ImageSerializer, + peripherals: PeripheralSerializer, + points: PointSerializer, + regimens: RegimenSerializer, + sequences: SequenceSerializer, + tools: ToolSerializer, + users: UserSerializer, + webcam_feeds: WebcamFeedSerialize + } - required do - model :device, class: Device + def self.run_by_id(id) + Devices::Dump.delay.run(device_id: current_device) end + required { model :device_id, class: number } + def execute output = { device: DeviceSerializer.new(device).as_json } - RESOURCES.map do |pair| - list = device.send(pair.head) - output[pair.head] = list.map { |x| pair.tail.new(x).as_json } + RESOURCES.map do |(name, serializer)| + list = device.send(name) + output[name] = list.map { |x| serializer.new(x).as_json } end output end - end + + private + + def device + @device ||= Device.find(device_id) + end end