-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModels.go
112 lines (100 loc) · 2.33 KB
/
Models.go
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"github.com/jinzhu/gorm"
)
type globalSettings struct {
gorm.Model
APIKey string
APIOffset int
UnauthenticatedGreeting string
AuthenticatedGreeting string
AuthenticatedIntro string
}
type chat struct {
gorm.Model
TelegramID int
TelegramFirstName string
TelegramLastName string
TelegramUserName string
TelegramChatID int64
Messages []message
OpenConnection bool
Admin bool
}
type message struct {
gorm.Model
Inbound bool
Text string `gorm:"type:text"`
Date int
ChatID uint
Read bool
}
type crew struct {
gorm.Model
Code string
Name string
Description string `gorm:"type:text"`
ChatID uint
Chat chat
Members []member
Items []item
Transactions []transaction
Contacts []contact `gorm:"foreignkey:OwnerID"`
Spacemails []spacemail
}
type member struct {
gorm.Model
Name string
CrewID uint
}
type item struct {
gorm.Model
Name string
Description string `gorm:"type:text"`
CrewID uint
}
type transaction struct {
gorm.Model
Date int
Value float64
CrewID uint
Description string
}
type contact struct {
gorm.Model
OwnerID uint
CrewID uint
Crew crew
Name string
Description string `gorm:"type:text"`
Spacemails []spacemail
}
type spacemail struct {
gorm.Model
Text string `gorm:"type:text"`
Date int
Read bool
CrewID uint
Inbound bool
ContactID uint
}
func setupDatabase(db *gorm.DB) {
database.AutoMigrate(&globalSettings{})
database.AutoMigrate(&chat{})
database.AutoMigrate(&message{})
database.AutoMigrate(&crew{})
database.AutoMigrate(&member{})
database.AutoMigrate(&item{})
database.AutoMigrate(&transaction{})
database.AutoMigrate(&contact{})
database.AutoMigrate(&spacemail{})
var settings globalSettings
database.First(&settings)
if database.NewRecord(settings) {
//we have no dataset.
settings.UnauthenticatedGreeting = "Willkommen, Captain. Ich benötige Ihren Autorisierungscode, damit wir fortfahren können."
settings.AuthenticatedGreeting = "Autorisierung bestätigt. Willkommen, %s."
settings.AuthenticatedIntro = "Ich stehe dir jederzeit über eine Reihe von Befehlen zur Verfügung. Sende einfach '/help' für eine Liste."
database.Create(&settings)
}
}