Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for existing project asset before adding it #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robertlong
Copy link
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
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
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

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