Check for existing project asset before adding it#234
Open
robertlong wants to merge 1 commit into
Open
Conversation
gfodor
approved these changes
Sep 6, 2019
Contributor
gfodor
left a comment
There was a problem hiding this comment.
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]) |
Contributor
There was a problem hiding this comment.
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
|
We may want to change this to "Remove project assets." Robert to confirm with team. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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