defmodule Consola.Database.ShortUrl do
use Ash.Resource, domain: Consola.Database, data_layer: AshPostgres.DataLayer
postgres do
table "short_urls"
repo Consola.Repo
end
actions do
default_accept :*
defaults [:create, :read, :update, :destroy]
create :create_with_full_url do
default_accept [:related_full_urls, :short_url, :expires_at]
end
end
attributes do
uuid_primary_key :id
attribute :short_url, :string do
allow_nil? false
public? true
end
attribute :expires_at, :string do
allow_nil? false
public? true
end
create_timestamp :created_at
update_timestamp :updated_at
end
relationships do
many_to_many :related_full_urls, Consola.Database.FullUrl do
through Consola.Database.UrlMapping
public? true
writable? true
source_attribute :id
source_attribute_on_join_resource :short_url_id
destination_attribute :id
destination_attribute_on_join_resource :full_url_id
end
end
end
defmodule Consola.Database.ShortUrl do
use Ash.Resource, domain: Consola.Database, data_layer: AshPostgres.DataLayer
postgres do
table "short_urls"
repo Consola.Repo
end
actions do
default_accept :*
defaults [:create, :read, :update, :destroy]
create :create_with_full_url do
default_accept [:related_full_urls, :short_url, :expires_at]
end
end
attributes do
uuid_primary_key :id
attribute :short_url, :string do
allow_nil? false
public? true
end
attribute :expires_at, :string do
allow_nil? false
public? true
end
create_timestamp :created_at
update_timestamp :updated_at
end
relationships do
many_to_many :related_full_urls, Consola.Database.FullUrl do
through Consola.Database.UrlMapping
public? true
writable? true
source_attribute :id
source_attribute_on_join_resource :short_url_id
destination_attribute :id
destination_attribute_on_join_resource :full_url_id
end
end
end