Setting up Posts and Posts.Tweet

This commit is contained in:
2026-03-30 01:41:36 -04:00
parent 934879f95f
commit dcca583461
7 changed files with 570 additions and 1 deletions

60
lib/mixer/posts/tweet.ex Normal file
View File

@@ -0,0 +1,60 @@
defmodule Mixer.Posts.Tweet do
use Ash.Resource,
otp_app: :mixer,
domain: Mixer.Posts,
data_layer: AshPostgres.DataLayer,
authorizers: [Ash.Policy.Authorizer],
extensions: [AshStateMachine, AshTypescript.Resource]
postgres do
table "tweets"
repo Mixer.Repo
end
typescript do
type_name "tweets"
end
state_machine do
initial_states [:drafted]
default_initial_state :drafted
transitions do
transition :create, from: :*, to: :posted
end
end
actions do
defaults [:read, :destroy, update: :*]
create :create do
upsert? true
accept [:content]
change relate_actor(:user)
change transition_state(:posted)
end
end
attributes do
uuid_primary_key :id
attribute :content, :string do
allow_nil? false
public? true
end
attribute :user_id, :uuid do
allow_nil? false
public? true
end
end
relationships do
belongs_to :user, Mixer.Accounts.User do
attribute_type :uuid
attribute_writable? true
allow_nil? false
public? true
end
end
end