mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
REST API v1: tokens, read endpoints, squawks, webhooks
- 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>
This commit is contained in:
1 parent
ec0f43019f
commit
bffdea937c
45 files changed
+1577
-51
No files matched your search
@@ -0,0 +1,69 @@
|
||||
# What the API and webhooks send for each kind of record (docs/api.md).
|
||||
# Times are ISO 8601 UTC, hours decimals, codes rather than translated labels.
|
||||
module ApiPresenter
|
||||
module_function
|
||||
|
||||
def aircraft(a)
|
||||
aw = a.airworthiness
|
||||
{ id: a.id, tail_number: a.tail_number, make: a.make, model: a.model, serial_number: a.serial_number,
|
||||
icao_type: a.icao_type, status: a.status,
|
||||
airworthiness: { status: aw.status, issues: aw.issues.map { { category: _1.category, severity: _1.severity, title: _1.title } } },
|
||||
time_basis: a.time_basis, hours: dec(a.current_hours), tach: dec(a.tach_time), hobbs: dec(a.hobbs_time),
|
||||
updated_at: time(a.updated_at) }
|
||||
end
|
||||
|
||||
def component(c)
|
||||
{ id: c.id, aircraft_id: c.aircraft_id, parent_id: c.parent_component_id, type: c.component_type&.name,
|
||||
manufacturer: c.manufacturer, model: c.model, serial_number: c.serial_number.presence,
|
||||
location: c.install_location.presence, status: c.status, date_in_service: c.date_in_service&.iso8601,
|
||||
hours_in_service: dec(c.hours_in_service), hours_since_overhaul: dec(c.hours_since_overhaul),
|
||||
overhaul_date: c.overhaul_date&.iso8601, overhaul_kind: c.overhaul_kind.presence,
|
||||
tbo: { hours: c.tbo_hours, days: c.tbo_days, months: c.tbo_months, on_condition: c.on_condition, critical: c.tbo_critical }.compact,
|
||||
replacement: { hours: c.replacement_hours, days: c.replacement_days, months: c.replacement_months, critical: c.replacement_critical }.compact,
|
||||
expires_on: c.expires_on&.iso8601, updated_at: time(c.updated_at) }
|
||||
end
|
||||
|
||||
def due_item(i)
|
||||
{ key: i.key, title: i.title, kind: i.kind, due_date: i.date.iso8601, projected: i.projected,
|
||||
due_hours: dec(i.due_hours), overdue: i.overdue? }
|
||||
end
|
||||
|
||||
def squawk(s)
|
||||
{ id: s.id, aircraft_id: s.aircraft_id, component_id: s.component_id, issue_reported: s.issue_reported,
|
||||
priority: s.priority, grounding: s.grounding?, deferred: s.deferred?, resolved: !!s.resolved,
|
||||
resolved_at: time(s.resolved_at), notes: s.notes.presence, logbook_entry_id: s.logbook_entry_id,
|
||||
reported_by: s.reported_by&.display_name, external_ref: s.external_ref,
|
||||
attachments: s.attachments.map { _1.filename.to_s },
|
||||
created_at: time(s.created_at), updated_at: time(s.updated_at) }
|
||||
end
|
||||
|
||||
def logbook_entry(e)
|
||||
sig = e.signature
|
||||
{ id: e.id, aircraft_id: e.aircraft_id, component_id: e.component_id, log: e.log_type, entry_type: e.entry_type,
|
||||
date: e.date.iso8601, text: e.text, aircraft_hours: dec(e.aircraft_hours_at_entry),
|
||||
inspection_result: e.inspection_result.presence, verified: e.verified, superseded: e.superseded_at.present?,
|
||||
signed: sig.present?, signature: sig && signature(sig),
|
||||
signoff: sig ? nil : { person: e.signoff_person.presence, certificate_type: e.signoff_certificate_type.presence,
|
||||
certificate_number: e.signoff_certificate_number.presence }.compact.presence,
|
||||
created_at: time(e.created_at), updated_at: time(e.updated_at) }
|
||||
end
|
||||
|
||||
def signature(sig)
|
||||
{ signer_name: sig.signer_name, certificate_kind: sig.certificate_kind, certificate_number: sig.certificate_number,
|
||||
signed_at: time(sig.signed_at) }
|
||||
end
|
||||
|
||||
def inspection(row)
|
||||
{ inspection_type_id: row.type.id, name: row.type.name, status: row.status, next_due_date: row.next_due_date&.iso8601,
|
||||
next_due_hours: dec(row.next_due_hours), last_done: row.latest&.date&.iso8601 }
|
||||
end
|
||||
|
||||
def ad(row)
|
||||
{ airworthiness_directive_id: row.ad.id, name: row.ad.name, description: row.ad.short_description.presence,
|
||||
status: row.status, next_due_date: row.next_due_date&.iso8601, next_due_hours: dec(row.next_due_hours),
|
||||
last_complied: row.latest&.date_complied&.iso8601 }
|
||||
end
|
||||
|
||||
def dec(value) = value&.to_d&.round(1)&.to_f
|
||||
def time(value) = value&.utc&.iso8601
|
||||
end
|
||||
Reference in new issue
Block a user