aboutsummaryrefslogtreecommitdiff
path: root/pkg/model/user.go
blob: af42e3c21841ffdcb3b3ff0eb005be84bf6b9377 (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
package model

import "time"

type Sex bool

const (
	SexMale   Sex = false
	SexFemale Sex = true
)

type User struct {
	ID          uint64 `gorm:"primaryKey"`
	Name        string
	Surname     string
	Fathersname string

	Age uint8

	Sex      Sex
	Birthday time.Time

	Cards   []Card   `gorm:"foreignKey:UserID"`

	// just for compatibility
	Flights []Flight `gorm:"many2many:user_flights;joinForeignKey:UserID;joinReferences:FlightID"`
}

func (User) TableName() string { return "users" }

type Card struct {
	ID uint64 `gorm:"primaryKey"`

	Prefix string
	Number uint64

	Bonusprogramm string

	// User has multiple cards -> each card has registered flights to it
	Flights []Flight `gorm:"many2many:card_flights;joinForeignKey:CardID;joinReferences:FlightID"`

	UserID uint64
	User   User `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}

func (Card) TableName() string { return "cards" }

type Flight struct {
	ID uint64 `gorm:"primaryKey"`

	Number    string
	From      string
	To        string
	Departure time.Time
	Arrival   time.Time

	Users []User `gorm:"many2many:user_flights;joinForeignKey:FlightID;joinReferences:UserID"`
	Cards []Card `gorm:"many2many:card_flights;joinForeignKey:FlightID;joinReferences:CardID"`
}

func (Flight) TableName() string { return "flights" }