Skip to main content

flyr/
model.rs

1use serde::Serialize;
2
3#[derive(Debug, Clone, Serialize)]
4pub struct Airport {
5    pub code: String,
6    pub name: String,
7}
8
9#[derive(Debug, Clone, Serialize)]
10pub struct FlightDateTime {
11    pub year: u32,
12    pub month: u32,
13    pub day: u32,
14    pub hour: u32,
15    pub minute: u32,
16}
17
18impl std::fmt::Display for FlightDateTime {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        write!(
21            f,
22            "{:04}-{:02}-{:02} {:02}:{:02}",
23            self.year, self.month, self.day, self.hour, self.minute
24        )
25    }
26}
27
28#[derive(Debug, Clone, Serialize)]
29pub struct Segment {
30    pub from_airport: Airport,
31    pub to_airport: Airport,
32    pub departure: FlightDateTime,
33    pub arrival: FlightDateTime,
34    pub duration_minutes: u32,
35    pub aircraft: Option<String>,
36}
37
38#[derive(Debug, Clone, Serialize)]
39pub struct CarbonEmission {
40    pub emission_grams: Option<i64>,
41    pub typical_grams: Option<i64>,
42}
43
44#[derive(Debug, Clone, Serialize)]
45pub struct FlightResult {
46    pub flight_type: String,
47    pub airlines: Vec<String>,
48    pub segments: Vec<Segment>,
49    pub price: Option<i64>,
50    pub carbon: CarbonEmission,
51}
52
53#[derive(Debug, Clone, Serialize)]
54pub struct Airline {
55    pub code: String,
56    pub name: String,
57}
58
59#[derive(Debug, Clone, Serialize)]
60pub struct Alliance {
61    pub code: String,
62    pub name: String,
63}
64
65#[derive(Debug, Clone, Default, Serialize)]
66pub struct SearchMetadata {
67    pub airlines: Vec<Airline>,
68    pub alliances: Vec<Alliance>,
69}
70
71#[derive(Debug, Clone, Default, Serialize)]
72pub struct SearchResult {
73    pub flights: Vec<FlightResult>,
74    pub metadata: SearchMetadata,
75}