aboutsummaryrefslogtreecommitdiff
path: root/pkg/model
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/model')
-rw-r--r--pkg/model/model.go7
-rw-r--r--pkg/model/user.go61
2 files changed, 68 insertions, 0 deletions
diff --git a/pkg/model/model.go b/pkg/model/model.go
new file mode 100644
index 0000000..0a7e026
--- /dev/null
+++ b/pkg/model/model.go
@@ -0,0 +1,7 @@
+package model
+
+
+
+type Adapter interface {
+ Init(string) // inits adapter with filename
+} \ No newline at end of file
diff --git a/pkg/model/user.go b/pkg/model/user.go
new file mode 100644
index 0000000..af42e3c
--- /dev/null
+++ b/pkg/model/user.go
@@ -0,0 +1,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" }