I have the following Task
resource which is used in a To-Do-List application. I want to make sure that one can not populate the started_at
and ended_at
fields with :create
or :update
. I don’t want the user to manipulate those values.
- How can I do that?
- How can I add an action
:start
which populates the current server time tostarted_at
?
defmodule App.Desk.Task do
use Ash.Resource, data_layer: Ash.DataLayer.Ets
attributes do
uuid_primary_key :id
attribute :name, :string
attribute :started_at, :utc_datetime
attribute :ended_at, :utc_datetime
end
actions do
defaults [:create, :read, :update, :destroy]
end
code_interface do
define_for App.Desk
define :create
define :read
define :by_id, get_by: [:id], action: :read
define :by_name, get_by: [:name], action: :read
define :update
define :destroy
end
end