Compare commits
3 commits
788f63597e
...
bf0e764f65
Author | SHA1 | Date | |
---|---|---|---|
|
bf0e764f65 | ||
|
535191d26d | ||
|
14eeab50e2 |
4 changed files with 14 additions and 0 deletions
|
@ -6,6 +6,11 @@ class ReadingsController < ActionController::API
|
||||||
|
|
||||||
# @see {https://docutopia.tupale.co/sutty:nodemecu:api}
|
# @see {https://docutopia.tupale.co/sutty:nodemecu:api}
|
||||||
def create
|
def create
|
||||||
|
if reading_params.empty?
|
||||||
|
head :ok
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
Reading.transaction do
|
Reading.transaction do
|
||||||
reading = raspberry.readings.build reading_params
|
reading = raspberry.readings.build reading_params
|
||||||
reading.id = params[:transaction_uuid]
|
reading.id = params[:transaction_uuid]
|
||||||
|
@ -52,6 +57,8 @@ class ReadingsController < ActionController::API
|
||||||
def sensor_params(sensor)
|
def sensor_params(sensor)
|
||||||
sensor.permit(:timestamp, :type, :value, :unit, :error).tap do |p|
|
sensor.permit(:timestamp, :type, :value, :unit, :error).tap do |p|
|
||||||
p[:local_type] = p.delete :type
|
p[:local_type] = p.delete :type
|
||||||
|
p[:timestamp] = Time.at p[:timestamp]
|
||||||
|
rescue TypeError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,6 @@ class Arduino < ApplicationRecord
|
||||||
belongs_to :raspberry
|
belongs_to :raspberry
|
||||||
belongs_to :reading
|
belongs_to :reading
|
||||||
has_many :sensors
|
has_many :sensors
|
||||||
|
|
||||||
|
validates_presence_of :local_id
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,4 +3,7 @@
|
||||||
class Raspberry < ApplicationRecord
|
class Raspberry < ApplicationRecord
|
||||||
has_many :readings
|
has_many :readings
|
||||||
has_many :arduinos
|
has_many :arduinos
|
||||||
|
|
||||||
|
validates_presence_of :name
|
||||||
|
validates_uniqueness_of :name
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,6 @@
|
||||||
|
|
||||||
class Sensor < ApplicationRecord
|
class Sensor < ApplicationRecord
|
||||||
belongs_to :arduino
|
belongs_to :arduino
|
||||||
|
|
||||||
|
validates_presence_of :timestamp, :local_type, :value, :unit
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue