Add the attribute for a avatar image url for Author.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 3 months ago
parent 100d8ba39a
commit 7d0a098a47

@ -58,6 +58,7 @@ defmodule DecentralisedBookIndex.Metadata do
define :get_author_alternative_names, args: [:author], action: :get_alternative_names define :get_author_alternative_names, args: [:author], action: :get_alternative_names
define :search_author, action: :search, args: [:name] define :search_author, action: :search, args: [:name]
define :update_author, action: :update define :update_author, action: :update
define :assign_author_avatar_image, args: [:avatar_url], action: :assign_avatar_image
define :destroy_author, action: :destroy define :destroy_author, action: :destroy
end end

@ -108,6 +108,10 @@ defmodule DecentralisedBookIndex.Metadata.Author do
pagination offset?: true, default_limit: 10 pagination offset?: true, default_limit: 10
end end
update :assign_avatar_image do
accept [:avatar_url]
end
end end
attributes do attributes do
@ -123,6 +127,11 @@ defmodule DecentralisedBookIndex.Metadata.Author do
public? true public? true
end end
attribute :avatar_url, :string do
allow_nil? true
public? true
end
timestamps() timestamps()
end end

@ -0,0 +1,21 @@
defmodule DecentralisedBookIndex.Repo.Migrations.UpdateAuthorToAddAvatarUrl do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_postgres.generate_migrations`
"""
use Ecto.Migration
def up do
alter table(:authors) do
add :avatar_url, :text
end
end
def down do
alter table(:authors) do
remove :avatar_url
end
end
end

@ -0,0 +1,108 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "fragment(\"gen_random_uuid()\")",
"generated?": false,
"primary_key?": true,
"references": null,
"size": null,
"source": "id",
"type": "uuid"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "name",
"type": "text"
},
{
"allow_nil?": false,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "description",
"type": "text"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "avatar_url",
"type": "text"
},
{
"allow_nil?": false,
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "inserted_at",
"type": "utc_datetime_usec"
},
{
"allow_nil?": false,
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")",
"generated?": false,
"primary_key?": false,
"references": null,
"size": null,
"source": "updated_at",
"type": "utc_datetime_usec"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"primary_key?": false,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "authors_author_alias_registry_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "author_alias_registries"
},
"size": null,
"source": "author_alias_registry_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "0B4CCF358A5DFEC0FB98A664FC575AA12A5E851C61722E7AC620FCA5D97FFCF8",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.DecentralisedBookIndex.Repo",
"schema": null,
"table": "authors"
}

@ -24,4 +24,16 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRolesTest do
refute author_role.role refute author_role.role
end end
end end
describe "author's avatar image" do
test "update avatar image" do
avatar_url = "/images/avatar.avif"
{:ok, author} = Metadata.create_author("Author", "An description")
assert {:ok, author} = Metadata.assign_author_avatar_image(author, avatar_url)
assert author.avatar_url == avatar_url
end
end
end end

Loading…
Cancel
Save