Skip to content

Check for existing project asset before adding it#234

Open
robertlong wants to merge 1 commit into
masterfrom
fix/unique-project_assets2
Open

Check for existing project asset before adding it#234
robertlong wants to merge 1 commit into
masterfrom
fix/unique-project_assets2

Conversation

@robertlong
Copy link
Copy Markdown
Contributor

@robertlong robertlong commented Sep 6, 2019

Sorry for the sloppy code. I wasn't really sure how to write this in a cleaner way. Also I thought about using an upsert instead, but couldn't figure out how to use insert_or_update

Copy link
Copy Markdown
Contributor

@gfodor gfodor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, some refactoring suggested

render(conn, "show.json", asset: asset)
%Asset{} = asset <- Asset.asset_by_sid_for_account(asset_sid, account) do

project_asset = Repo.get_by(ProjectAsset, [project_id: project.project_id, asset_id: asset.asset_id])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd do something like:

if Repo.get_by(...) do
  render_asset(asset)
else
  case Project.add_asset_to_project(..) do
    { :error } -> ...
    _ -> render_asset(asset)
end

defp render_asset(asset)
  render(conn, "show.json", asset: asset |> Repo.preload([:asset_owned_file, :thumbnail_owned_file])
end

@robertlong robertlong self-assigned this Feb 18, 2021
@emstanley
Copy link
Copy Markdown

We may want to change this to "Remove project assets." Robert to confirm with team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants