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
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
end
end

View file

@ -3,6 +3,15 @@ defmodule Putzplan.Tasks.CompletedTask do
actions do
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
attributes do
@ -11,23 +20,17 @@ defmodule Putzplan.Tasks.CompletedTask do
attribute :completion, :date do
allow_nil? false
end
attribute :user_id, :uuid do
allow_nil? false
end
attribute :task_id, :uuid do
allow_nil? false
end
end
relationships do
belongs_to :users, Putzplan.Accounts.User do
allow_nil? false
source_attribute :user_id
end
belongs_to :tasks, Putzplan.Tasks.Task do
allow_nil? false
source_attribute :task_id
end
end

View file

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