mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 18:56:01 +00:00
83 lines
1.3 KiB
Elixir
83 lines
1.3 KiB
Elixir
defmodule WandererApp.Api.User do
|
|
@moduledoc false
|
|
|
|
use Ash.Resource,
|
|
domain: WandererApp.Api,
|
|
data_layer: AshPostgres.DataLayer,
|
|
extensions: [AshCloak]
|
|
|
|
postgres do
|
|
repo(WandererApp.Repo)
|
|
table("user_v1")
|
|
end
|
|
|
|
code_interface do
|
|
define(:by_id,
|
|
get_by: [:id],
|
|
action: :read
|
|
)
|
|
|
|
define(:by_hash,
|
|
get_by: [:hash],
|
|
action: :read
|
|
)
|
|
|
|
define(:update_last_map,
|
|
action: :update_last_map
|
|
)
|
|
|
|
define(:update_balance,
|
|
action: :update_balance
|
|
)
|
|
end
|
|
|
|
actions do
|
|
default_accept [
|
|
:name,
|
|
:hash
|
|
]
|
|
|
|
defaults [:create, :read, :update, :destroy]
|
|
|
|
update :update_last_map do
|
|
accept([:last_map_id])
|
|
end
|
|
|
|
update :update_balance do
|
|
require_atomic? false
|
|
|
|
accept([:balance])
|
|
end
|
|
end
|
|
|
|
cloak do
|
|
vault(WandererApp.Vault)
|
|
|
|
attributes([:balance])
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
|
|
attribute :name, :string
|
|
attribute :hash, :string
|
|
attribute :last_map_id, :uuid
|
|
|
|
attribute :balance, :float do
|
|
default 0.0
|
|
|
|
allow_nil?(true)
|
|
end
|
|
end
|
|
|
|
relationships do
|
|
has_many :characters, WandererApp.Api.Character
|
|
end
|
|
|
|
identities do
|
|
identity :unique_hash, [:hash] do
|
|
pre_check?(false)
|
|
end
|
|
end
|
|
end
|