ammocpr/lib/ammoprices/catalog/caliber.ex
Graham McIntire bbe5bde145
Initial implementation of ammo price tracker
Phoenix 1.8 app that scrapes ammunition retailers (Lucky Gunner,
SGAmmo) for price data and displays historical price trends.

- Data model: retailers, calibers, products, price snapshots
- Scraper infrastructure with Req, Floki, realistic browser headers
- Oban-scheduled scrape jobs (every 4h with randomized delays)
- LiveView pages: homepage with category cards, caliber detail with
  price table, Chart.js price history, and price stats banner
- 18 seeded calibers across handgun/rifle/rimfire/shotgun categories
- 77 tests
2026-03-11 15:58:12 -05:00

27 lines
705 B
Elixir

defmodule Ammoprices.Catalog.Caliber do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "calibers" do
field :name, :string
field :slug, :string
field :category, :string
field :aliases, {:array, :string}, default: []
has_many :products, Ammoprices.Catalog.Product
timestamps(type: :utc_datetime)
end
def changeset(caliber, attrs) do
caliber
|> cast(attrs, [:name, :slug, :category, :aliases])
|> validate_required([:name, :slug, :category])
|> validate_inclusion(:category, ~w(handgun rifle rimfire shotgun))
|> unique_constraint(:slug)
end
end