mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 02:35:42 +00:00
126 lines
2.6 KiB
Elixir
126 lines
2.6 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")
|
|
|
|
custom_indexes do
|
|
index [:entity_id, :event_type, :inserted_at], unique: true
|
|
end
|
|
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,
|
|
:signatures_added,
|
|
:signatures_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
|