refactor: Update parsing of flight schedule data for improved accuracy and functionality

This commit is contained in:
windyboy
2024-07-31 11:05:30 +08:00
parent f74d61981a
commit 9982b1408d
4 changed files with 113 additions and 58 deletions
+23 -25
View File
@@ -29,25 +29,27 @@ type FlightSchedule struct {
// Example: "ILS(0)"
ILS string `json:"ils,omitempty"`
// ICAO code for the departure airport.
// Example: "ZBTJ"
DepartureAirport string `json:"departure_airport"`
// // ICAO code for the departure airport.
// // Example: "ZBTJ"
// DepartureAirport string `json:"departure_airport"`
// Scheduled departure time of the flight. This field may be formatted as HHMM or include date information.
// Example: "1845"
DepartureTime string `json:"departure_time,omitempty"`
// // Scheduled departure time of the flight. This field may be formatted as HHMM or include date information.
// // Example: "1845"
// DepartureTime string `json:"departure_time,omitempty"`
// Additional schedule information. This field may include special instructions or additional scheduling details.
// Example: "SI:TSN1845"
ScheduleInfo string `json:"schedule_info,omitempty"`
// // Additional schedule information. This field may include special instructions or additional scheduling details.
// // Example: "SI:TSN1845"
// ScheduleInfo string `json:"schedule_info,omitempty"`
// Estimated or scheduled arrival time of the flight. This field may be formatted as HHMM or include date information.
// Example: "2100"
ArrivalTime string `json:"arrival_time,omitempty"`
// // Estimated or scheduled arrival time of the flight. This field may be formatted as HHMM or include date information.
// // Example: "2100"
// ArrivalTime string `json:"arrival_time,omitempty"`
// ICAO code for the arrival airport.
// Example: "ZSPD"
ArrivalAirport string `json:"arrival_airport"`
// // ICAO code for the arrival airport.
// // Example: "ZSPD"
// ArrivalAirport string `json:"arrival_airport"`
Waypoints []WayPoint `json:"waypoints"`
// Additional comments or remarks about the flight schedule. This field may include any relevant notes or observations.
// Example: "Special cargo handling required"
@@ -57,6 +59,12 @@ type FlightSchedule struct {
Reference string `json:"reference,omitempty"`
}
type WayPoint struct {
ArrivalTime string
Airport string
DepartureTime string
}
func (f *FlightSchedule) Validate() error {
if f.Date == "" {
return fmt.Errorf("date is required")
@@ -67,15 +75,5 @@ func (f *FlightSchedule) Validate() error {
if f.AircraftReg == "" {
return fmt.Errorf("aircraft registration is required")
}
if f.DepartureAirport == "" {
return fmt.Errorf("departure airport is required")
}
if f.ArrivalAirport == "" {
return fmt.Errorf("arrival airport is required")
}
if f.DepartureTime == "" && f.ArrivalTime == "" {
return fmt.Errorf("either departure time or arrival time is required")
}
return nil
}