Files
go-caatsm/internal/domain/pln.go
T
windyboy 5b6b4f5dba refactor: Add FlightSchedule struct and validation logic
The code changes in `pln.go` introduce a new `FlightSchedule` struct and validation logic. This struct represents a flight schedule and includes various fields such as date, category, flight number, aircraft registration, passenger configuration, ILS category, departure airport, departure time, schedule info, arrival time, arrival airport, comments, and reference. The `Validate` method ensures that the required fields are populated and returns an error if any field is missing. This addition improves the overall functionality and data integrity of the code.
2024-07-29 15:40:10 +08:00

80 lines
2.8 KiB
Go

package domain
import "fmt"
type FlightSchedule struct {
// Date of the flight schedule.
// Example: "30OCT"
Date string `json:"date"`
// Category of the flight schedule. It could represent different categories based on the airline or flight type.
// Example: "H/G"
Category string `json:"category,omitempty"`
// Flight number of the flight schedule. This is a unique identifier for the flight.
// Example: "CA1014"
FlightNumber string `json:"flight_number"`
// Aircraft registration number. This is a unique identifier for the aircraft used for the flight.
// Example: "B2458"
AircraftReg string `json:"aircraft_reg"`
// Passenger configuration or seating arrangement for the flight. This field may include details about class configurations.
// Example: "1/1"
PassengerConfig string `json:"passenger_config,omitempty"`
// Instrument Landing System (ILS) category or configuration used for the flight. This field may include ILS category details.
// Example: "ILS(0)"
ILS string `json:"ils,omitempty"`
// 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"`
// 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"`
// ICAO code for the arrival airport.
// Example: "ZSPD"
ArrivalAirport string `json:"arrival_airport"`
// Additional comments or remarks about the flight schedule. This field may include any relevant notes or observations.
// Example: "Special cargo handling required"
Comments string `json:"comments,omitempty"`
// Reference information or external identifiers related to the flight schedule. This field may include references to external systems or documents.
Reference string `json:"reference,omitempty"`
}
func (f *FlightSchedule) Validate() error {
if f.Date == "" {
return fmt.Errorf("date is required")
}
if f.FlightNumber == "" {
return fmt.Errorf("flight number is required")
}
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
}