Setting up Posts and Posts.Tweet
This commit is contained in:
60
lib/mixer/posts/tweet.ex
Normal file
60
lib/mixer/posts/tweet.ex
Normal 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
|
||||
Reference in New Issue
Block a user