prop/lib/microwaveprop/terrain.ex
Graham McIntire 51e390959c Add dialyzer specs and types across the codebase
277 @spec/@type annotations added to 58 files covering all public
APIs: contexts (propagation, radio, weather, terrain, beacons,
commercial), GRIB2 decoders, terrain analysis, duct detection,
rain scatter, CSV/ADIF import, weather clients, and all Ecto
schemas. Dialyzer passes with 0 errors.
2026-04-12 08:55:04 -05:00

30 lines
818 B
Elixir

defmodule Microwaveprop.Terrain do
@moduledoc false
import Ecto.Query
alias Microwaveprop.Repo
alias Microwaveprop.Terrain.TerrainProfile
@spec upsert_terrain_profile(map()) :: {:ok, TerrainProfile.t()} | {:error, Ecto.Changeset.t()}
def upsert_terrain_profile(attrs) do
%TerrainProfile{}
|> TerrainProfile.changeset(attrs)
|> Repo.insert(
on_conflict: :nothing,
conflict_target: [:contact_id]
)
end
@spec get_terrain_profile(Ecto.UUID.t()) :: TerrainProfile.t() | nil
def get_terrain_profile(contact_id) do
Repo.get_by(TerrainProfile, contact_id: contact_id)
end
@spec has_terrain_profile?(Ecto.UUID.t()) :: boolean()
def has_terrain_profile?(contact_id) do
TerrainProfile
|> where([t], t.contact_id == ^contact_id)
|> Repo.exists?()
end
end