Files
wanderer/lib/wanderer_app/api/user_activity.ex
Dmitry Popov 4136aaad76 Initial commit
2024-09-18 01:55:30 +04:00

120 lines
2.4 KiB
Elixir

defmodule WandererApp.Api.UserActivity do
@moduledoc false
use Ash.Resource,
domain: WandererApp.Api,
data_layer: AshPostgres.DataLayer
postgres do
repo(WandererApp.Repo)
table("user_activity_v1")
end
code_interface do
define(:new, action: :new)
define(:read, action: :read)
end
actions do
default_accept [
:entity_id,
:entity_type,
:event_type,
:event_data
]
defaults [:create, :update, :destroy]
read :read do
primary?(true)
pagination(offset?: true, keyset?: true)
end
create :new do
accept [:entity_id, :entity_type, :event_type, :event_data]
primary?(true)
argument :user_id, :uuid, allow_nil?: false
argument :character_id, :uuid, allow_nil?: true
change manage_relationship(:user_id, :user, on_lookup: :relate, on_no_match: nil)
change manage_relationship(:character_id, :character, on_lookup: :relate, on_no_match: nil)
end
destroy :archive do
soft? false
end
end
attributes do
uuid_primary_key :id
attribute :entity_id, :string do
allow_nil? false
end
attribute :entity_type, :atom do
default "map"
constraints(
one_of: [
:map,
:access_list
]
)
allow_nil?(false)
end
attribute :event_type, :atom do
default "custom"
constraints(
one_of: [
:custom,
:hub_added,
:hub_removed,
:system_added,
:systems_removed,
:system_updated,
:character_added,
:character_removed,
:character_updated,
:map_added,
:map_removed,
:map_updated,
:map_acl_added,
:map_acl_removed,
:map_acl_updated,
:map_acl_member_added,
:map_acl_member_removed,
:map_acl_member_updated,
:map_connection_added,
:map_connection_updated,
:map_connection_removed
]
)
allow_nil?(false)
end
attribute :event_data, :string
create_timestamp(:inserted_at)
update_timestamp(:updated_at)
end
relationships do
belongs_to :character, WandererApp.Api.Character do
allow_nil? true
attribute_writable? true
end
belongs_to :user, WandererApp.Api.User do
primary_key? true
allow_nil? false
attribute_writable? true
end
end
end