ammocpr/lib/ammoprices/catalog/retailer.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
690 B
Elixir

defmodule Ammoprices.Catalog.Retailer do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "retailers" do
field :name, :string
field :slug, :string
field :base_url, :string
field :enabled, :boolean, default: true
field :last_scraped_at, :utc_datetime
has_many :products, Ammoprices.Catalog.Product
timestamps(type: :utc_datetime)
end
def changeset(retailer, attrs) do
retailer
|> cast(attrs, [:name, :slug, :base_url, :enabled, :last_scraped_at])
|> validate_required([:name, :slug, :base_url])
|> unique_constraint(:slug)
end
end