Structuring projects - this ok?

You are close. However, what do you want to happen when the answer of LeageAPI.data(league_id) is {:error, some_error}? And are there other steps, where you only want to continue if they all are OK?

So I’d suggest either adding an {:error, some_error}-clause (or multiple clauses for various kinds of errors) to the case-statement, or instead use a with statement:

with {:ok, league} <- LeagueAPI.data(league_id),
       # ... maybe some other steps,
  do
    Repo.insert(league, on_conflict: :nothing)
  else 
    # Handle error somehow
end

(And side note: Many developers find a simple function call more readable than a pipeline of only one function. I suggest using credo to get some tips about common ways to structure code and pitfalls to avoid, especially while still starting out. Of course many of the tips are somewhat subjective, but they are a great baseline for a starting Elixir developer.)

2 Likes