Skip to content

Commit

Permalink
IGC processing: Do not serialize optional keys
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Mar 15, 2024
1 parent 98ef540 commit ff64fcb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions frontend/src/routes/flights/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ const SCHEMA_API_LAUNCH_LANDING_INFO = z.object({
}),
alt: z.number(),
timeHms: z.tuple([z.number(), z.number(), z.number()]),
locationId: z
.number()
.optional()
.nullable()
.transform((value) => (value === null ? undefined : value)),
locationId: z.number().optional(),
});

const SCHEMA_API_IGC_METADATA = z.object({
Expand Down
7 changes: 7 additions & 0 deletions src/process_igc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@ struct LaunchLandingInfo {
pos: LatLng,
alt: i16,
time_hms: (u8, u8, u8),
#[serde(skip_serializing_if = "Option::is_none")]
location_id: Option<i32>,
}

#[derive(Default, Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FlightInfo {
/// Name of the pilot, as configured in the flight instrument.
#[serde(skip_serializing_if = "Option::is_none")]
pilot: Option<String>,
/// Name of the glider, as configured in the flight instrument.
#[serde(skip_serializing_if = "Option::is_none")]
glidertype: Option<String>,
/// Name of the launch site, as configured in the flight instrument.
#[serde(skip_serializing_if = "Option::is_none")]
site: Option<String>,
/// Date of flight (YYYY, MM, DD).
#[serde(skip_serializing_if = "Option::is_none")]
date_ymd: Option<(u16, u8, u8)>,
/// Lauch infos.
#[serde(skip_serializing_if = "Option::is_none")]
launch: Option<LaunchLandingInfo>,
/// Landing infos.
#[serde(skip_serializing_if = "Option::is_none")]
landing: Option<LaunchLandingInfo>,
/// Track length in kilometers.
track_distance: f64,
Expand Down

0 comments on commit ff64fcb

Please sign in to comment.