Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-07-08 00:41:31 +02:00
parent 5d80b634f0
commit c56a11af84
3 changed files with 3 additions and 2 deletions

View file

@ -74,8 +74,8 @@ def get_or_create_by_names(names) when is_list(names) do
def changeset(%Hashtag{} = struct, params) do
struct
|> cast(params, [:name])
|> update_change(:name, &normalize_name/1)
|> put_preferred_name
|> update_change(:name, &normalize_name/1)
|> validate_required([:name])
|> unique_constraint(:name)
end

View file

@ -193,6 +193,7 @@ defp array_of_hashtags() do
type: :object,
properties: %{
name: %Schema{type: :string},
preferred_name: %Schema{type: :string},
use_count: %Schema{type: :integer}
}
}

View file

@ -180,7 +180,7 @@ def all_hashtags(conn, _params) do
|> json(
hashtags
|> Enum.map(fn %{hashtag: hashtag, use_count: use_count} ->
%{name: hashtag.name, use_count: use_count}
%{name: hashtag.name, preferred_name: hashtag.preferred_name, use_count: use_count}
end)
)
else