prop/lib/microwaveprop_web/controllers/api/v1/beacon_json.ex
Graham McIntire c6d2c48264
feat: secure /api/v1 REST API for regular-user actions
Adds bearer-token authenticated REST API at /api/v1 covering every
action a non-admin user can perform on the website: contact + beacon
submission, beacon-monitor management, propagation queries, profile
read/update, and self-service API token issuance/revocation.

Security: SHA-256-hashed bearer tokens (mwp_ prefix, plaintext shown
once at creation), RFC 9457 problem+json error responses, RFC 9651
RateLimit-* headers backed by an ETS bucket (600/min per token,
60/min per anonymous IP, 30/min on /auth/tokens), private-contact
filtering by viewer.

Docs at docs/api/README.md (prose reference) and docs/api/openapi.yaml
(OpenAPI 3.1 spec covering every endpoint, response, and schema).

Tests: 124 new tests across schema, plug, error renderer, rate
limiter, fallback, and every controller. 16/17 API modules at 100%
line coverage; FallbackController at 87.5% (one defmodule line, an
Erlang-cover artifact for action_fallback-only modules).
2026-05-09 08:59:54 -05:00

28 lines
718 B
Elixir

defmodule MicrowavepropWeb.Api.V1.BeaconJSON do
@moduledoc "Renders beacon representations."
alias Microwaveprop.Beacons.Beacon
def index(%{beacons: beacons}), do: %{data: Enum.map(beacons, &data/1)}
def show(%{beacon: beacon}), do: %{data: data(beacon)}
defp data(%Beacon{} = b) do
%{
id: b.id,
callsign: b.callsign,
frequency_mhz: b.frequency_mhz,
lat: b.lat,
lon: b.lon,
grid: b.grid,
power_mw: b.power_mw,
height_ft: b.height_ft,
on_the_air: b.on_the_air,
approved: b.approved,
keying: b.keying,
bearing: b.bearing,
beamwidth_deg: b.beamwidth_deg,
notes: b.notes,
inserted_at: b.inserted_at
}
end
end