forked from shibao/cannery
fix container tag changeset
This commit is contained in:
parent
5b5fd7173b
commit
57b5cb432d
@ -173,14 +173,11 @@ defmodule Cannery.Containers do
|
||||
"""
|
||||
@spec add_tag!(Container.t(), Tag.t(), User.t()) :: ContainerTag.t()
|
||||
def add_tag!(
|
||||
%Container{id: container_id, user_id: user_id},
|
||||
%Tag{id: tag_id, user_id: user_id},
|
||||
%Container{user_id: user_id} = container,
|
||||
%Tag{user_id: user_id} = tag,
|
||||
%User{id: user_id}
|
||||
) do
|
||||
%ContainerTag{}
|
||||
|> ContainerTag.changeset(%{"container_id" => container_id, "tag_id" => tag_id})
|
||||
|> Repo.insert!()
|
||||
end
|
||||
),
|
||||
do: %ContainerTag{} |> ContainerTag.create_changeset(tag, container) |> Repo.insert!()
|
||||
|
||||
@doc """
|
||||
Removes a tag from a container
|
||||
|
@ -31,10 +31,16 @@ defmodule Cannery.Containers.ContainerTag do
|
||||
@type id :: UUID.t()
|
||||
|
||||
@doc false
|
||||
@spec changeset(new_container_tag(), attrs :: map()) :: Changeset.t(new_container_tag())
|
||||
def changeset(container_tag, attrs) do
|
||||
@spec create_changeset(new_container_tag(), Tag.t(), Container.t()) ::
|
||||
Changeset.t(new_container_tag())
|
||||
def create_changeset(
|
||||
container_tag,
|
||||
%Tag{id: tag_id, user_id: user_id},
|
||||
%Container{id: container_id, user_id: user_id}
|
||||
) do
|
||||
container_tag
|
||||
|> cast(attrs, [:tag_id, :container_id])
|
||||
|> change(tag_id: tag_id)
|
||||
|> change(container_id: container_id)
|
||||
|> validate_required([:tag_id, :container_id])
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user