feat: allow completing tasks

This commit is contained in:
Moritz Böhme 2025-04-06 12:15:48 +02:00
parent fe40fbf6b2
commit 4066a4f0b2
3 changed files with 13 additions and 16 deletions

View file

@ -82,7 +82,7 @@ defmodule Putzplan.Accounts.User do
end end
attributes do attributes do
attribute :id, :uuid, allow_nil?: false, primary_key?: true uuid_primary_key :id, writable?: true, default: nil
attribute :name, :string, allow_nil?: false attribute :name, :string, allow_nil?: false
end end
end end

View file

@ -3,6 +3,15 @@ defmodule Putzplan.Tasks.CompletedTask do
actions do actions do
defaults [:read] defaults [:read]
create :create do
argument :user, :map, allow_nil?: false
argument :task, :map, allow_nil?: false
change set_attribute(:completion, &Date.utc_today/0)
change manage_relationship(:user, :users, type: :append)
change manage_relationship(:task, :tasks, type: :append)
end
end end
attributes do attributes do
@ -11,23 +20,17 @@ defmodule Putzplan.Tasks.CompletedTask do
attribute :completion, :date do attribute :completion, :date do
allow_nil? false allow_nil? false
end end
attribute :user_id, :uuid do
allow_nil? false
end
attribute :task_id, :uuid do
allow_nil? false
end
end end
relationships do relationships do
belongs_to :users, Putzplan.Accounts.User do belongs_to :users, Putzplan.Accounts.User do
allow_nil? false allow_nil? false
source_attribute :user_id
end end
belongs_to :tasks, Putzplan.Tasks.Task do belongs_to :tasks, Putzplan.Tasks.Task do
allow_nil? false allow_nil? false
source_attribute :task_id
end end
end end

View file

@ -5,13 +5,7 @@ defmodule Putzplan.Tasks.Task do
data_layer: AshSqlite.DataLayer data_layer: AshSqlite.DataLayer
actions do actions do
# Use the default implementation of the :read action defaults [:read, create: :*]
defaults [:read]
# and a create action, which we'll customize later
create :create do
accept [:description, :repetition_days]
end
end end
sqlite do sqlite do