Files
growstuff/app/resources/harvest_resource.rb
T
Brenda Wallace 1135c763de Tidy API resources: read_only and owned macros, private hook helpers
Declare read-only resources and the owner relationship once each, make
the resource hook helpers private, simplify token auth, and cache the
generated API docs for an hour.
2026-10-25 11:48:28 +13:00

28 lines
754 B
Ruby

# frozen_string_literal: true
class HarvestResource < ApplicationResource
self.model = Harvest
attribute :harvested_at, :date
attribute :description, :string
attribute :unit, :string
attribute :weight_quantity, :big_decimal
attribute :weight_unit, :string
attribute :si_weight, :float, writable: false
attribute :crop_id, :integer, readable: false
attribute :planting_id, :integer, readable: false
filter_only :plant_part_id, :integer
belongs_to :crop
belongs_to :planting
owned
photos_of 'Harvest'
before_save do |harvest|
harvest.crop_id = harvest.planting.crop_id if harvest.planting_id
harvest.harvested_at = Time.zone.now if harvest.harvested_at.blank?
harvest.plant_part ||= PlantPart.first
end
end