blob: 213934adefe6f5ece421404494c1b3e94ad77120 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package model
import (
"time"
)
func SentinelBirthday() time.Time {
return time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
}
type User struct {
ID uint64 `gorm:"primaryKey"`
Nick string `gorm:"not null;uniqueIndex:uniq_user_nick"`
Name string
Surname string
Fathersname string
Sex Sex `gorm:"type:smallint;check:sex IN (0,1,2)"`
Birthday time.Time
Cards []Card `gorm:"foreignKey:UserID"`
CardsIDs []uint64 `gorm:"-"`
// just for compatibility
Flights []Flight `gorm:"many2many:user_flights;joinForeignKey:UserID;joinReferences:FlightID"`
FlightsIDs []uint64 `gorm:"-"`
}
func (User) TableName() string { return "users" }
type Card struct {
ID uint64 `gorm:"primaryKey"`
Prefix string `gorm:"not null;uniqueIndex:uniq_card_identity"`
Number uint64 `gorm:"not null;uniqueIndex:uniq_card_identity"`
Bonusprogramm string `gorm:"not null;uniqueIndex:uniq_card_identity"`
Flights []Flight `gorm:"many2many:card_flights;joinForeignKey:CardID;joinReferences:FlightID"`
FlightsIDs []uint64 `gorm:"-"`
UserID uint64
User User `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}
func (Card) TableName() string { return "cards" }
type LatLong struct {
Lat, Long float64
}
type Flight struct {
ID uint64 `gorm:"primaryKey"`
Number string `gorm:"not null;uniqueIndex:uniq_flight_identity"`
From string `gorm:"not null;uniqueIndex:uniq_flight_identity"`
FromCoords LatLong `gorm:"-"`
To string `gorm:"not null;uniqueIndex:uniq_flight_identity"`
ToCoords LatLong `gorm:"-"`
Date time.Time `gorm:"not null;uniqueIndex:uniq_flight_identity"`
HasTime bool
Code string `gorm:"-"`
Users []User `gorm:"many2many:user_flights;joinForeignKey:FlightID;joinReferences:UserID"`
Cards []Card `gorm:"many2many:card_flights;joinForeignKey:FlightID;joinReferences:CardID"`
UserID uint64 `gorm:"-"`
CardID uint64 `gorm:"-"`
}
func (Flight) TableName() string { return "flights" }
|