flight-crud-go/types.go
2025-03-25 15:36:21 +01:00

61 lines
1.7 KiB
Go

package main
import (
"gorm.io/gorm"
"time"
)
type AirportModel struct {
Icao string `json:"icao" gorm:"primary_key"`
Name string `json:"name" `
Country string `json:"country"`
RunwayLength int16 `json:"runway-length"`
DateOptions
}
type PlaneModel struct {
TailNo string `json:"tail-no" gorm:"primary_key"`
Model string `json:"model"`
Manufacturer string `json:"manufacturer"`
Capacity int16 `json:"capacity"`
DateOptions
}
type FlightModel struct {
FlightNo string `json:"flight-no" gorm:"primary_key"`
Departure time.Time `json:"departure"`
Arrival *time.Time `json:"arrival"`
ArrivalAirportID string `json:"arrival-airport-id"`
ArrivalAirport AirportModel `gorm:"foreignKey:ArrivalAirportID;references:Icao"`
DepartureAirportID string `json:"departure-airport-id"`
DepartureAirport AirportModel `gorm:"foreignKey:DepartureAirportID;references:Icao"`
OperatesTailNo string `json:"operates-tail-no"`
Operates PlaneModel `gorm:"foreignKey:OperatesTailNo;references:TailNo"`
DateOptions
}
type PassengerModel struct {
Ssn string `json:"ssn" gorm:"primary_key"`
Name string `json:"name" `
DateOfBirth time.Time `json:"date-of-birth"`
isFemale *bool `json:"is-female"`
DateOptions
}
type ReservationModel struct {
TicketNumber int
Seat string
FlightID string
Flight FlightModel `gorm:"foreignKey:FlightID;references:FlightNo"`
PassengerID string
Passenger PassengerModel `gorm:"foreignKey:PassengerID;references:Ssn"`
DateOptions
}
type DateOptions struct {
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}