mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Personal tokens (Profile → API tokens) act as their owner; integration tokens (Admin → Integrations) reach chosen aircraft and scopes, and their writes name the person they're for (SAM-On-Behalf-Of). Tokens are stored hashed, shown once, revocable, with last use recorded. - GET aircraft, components, due list, inspections, ADs, logbook entries and squawks; POST/PATCH squawks with external_ref links to the other system. - Idempotency-Key for safe retries, paging, JSON errors, rate limits. - Record history keeps the token with each change (in the hashed payload). - Webhooks (squawk created/updated/resolved, entry signed), HMAC-signed, retried, never sent to the server itself; deliveries listed for admins. - The outbound address check is shared by AirTrail and webhooks; reporting a squawk is announced the same way from the form and the API. - docs/guide/api.md: the API reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.8 KiB
Ruby
50 lines
1.8 KiB
Ruby
module Api
|
|
module V1
|
|
# The fleet this token reaches, and each aircraft's own lists.
|
|
class AircraftController < BaseController
|
|
before_action -> { require_scope!(:read) }
|
|
|
|
def index
|
|
render_page(aircraft_scope) { ApiPresenter.aircraft(_1) }
|
|
end
|
|
|
|
def show
|
|
render json: { data: ApiPresenter.aircraft(find_aircraft(params[:id])) }
|
|
end
|
|
|
|
# The parts tree (?all=1 includes disposed parts).
|
|
def components
|
|
aircraft = find_aircraft(params[:id])
|
|
scope = aircraft.components.includes(:component_type)
|
|
scope = scope.where.not(status: "DISPOSED") unless params[:all].present?
|
|
render_page(scope) { ApiPresenter.component(_1) }
|
|
end
|
|
|
|
# Everything coming due, soonest first (hours projected to dates).
|
|
def due
|
|
aircraft = find_aircraft(params[:id])
|
|
render json: { data: DueList.new(aircraft).items.map { ApiPresenter.due_item(_1) } }
|
|
end
|
|
|
|
def inspections
|
|
aircraft = find_aircraft(params[:id])
|
|
render json: { data: Compliance.inspection_rows(aircraft).map { ApiPresenter.inspection(_1) } }
|
|
end
|
|
|
|
def ads
|
|
aircraft = find_aircraft(params[:id])
|
|
render json: { data: Compliance.ad_rows(aircraft).map { ApiPresenter.ad(_1) } }
|
|
end
|
|
|
|
# Logbook entries, oldest first (paged); ?log=AC|ENG|PROP|OTHER, ?signed=true|false.
|
|
def logbook_entries
|
|
aircraft = find_aircraft(params[:id])
|
|
scope = aircraft.logbook_entries.includes(:signature)
|
|
scope = scope.where(log_type: params[:log]) if params[:log].present?
|
|
scope = params[:signed] == "true" ? scope.where.associated(:signature) : scope.where.missing(:signature) if params[:signed].present?
|
|
render_page(scope) { ApiPresenter.logbook_entry(_1) }
|
|
end
|
|
end
|
|
end
|
|
end
|