1
0
mirror of synced 2024-11-24 12:56:01 +03:00

change naming user struct

This commit is contained in:
DmitryZagorulko 2018-06-07 15:35:27 +03:00
parent 3bb3d9bd4f
commit a391a01c0f
7 changed files with 16 additions and 17 deletions

View File

@ -15,7 +15,7 @@ type TransportConfig struct {
SentryDSN string `yaml:"sentry_dsn"` SentryDSN string `yaml:"sentry_dsn"`
HTTPServer HTTPServerConfig `yaml:"http_server"` HTTPServer HTTPServerConfig `yaml:"http_server"`
Debug bool `yaml:"debug"` Debug bool `yaml:"debug"`
UpdateTime int `yaml:"update_time"` UpdateInterval int `yaml:"update_interval"`
ConfigAWS ConfigAWS `yaml:"config_aws"` ConfigAWS ConfigAWS `yaml:"config_aws"`
} }

View File

@ -11,7 +11,7 @@ log_level: 5
debug: false debug: false
update_time: 24 update_interval: 24
config_aws: config_aws:
access_key_id: ~ access_key_id: ~

View File

@ -1 +1 @@
drop table user_tg; drop table users;

View File

@ -1,4 +1,4 @@
create table user_tg create table users
( (
id serial not null id serial not null
constraint user_tg_pkey constraint user_tg_pkey
@ -10,4 +10,3 @@ create table user_tg
updated_at timestamp with time zone, updated_at timestamp with time zone,
constraint user_tg_key unique(external_id, user_photo, user_photo_id) constraint user_tg_key unique(external_id, user_photo, user_photo_id)
); );

View File

@ -28,8 +28,8 @@ type Bot struct {
Active bool `json:"active,omitempty"` Active bool `json:"active,omitempty"`
} }
// UserTG model // Users model
type UserTG struct { type Users struct {
ID int `gorm:"primary_key"` ID int `gorm:"primary_key"`
ExternalID int `gorm:"external_id;not null;unique"` ExternalID int `gorm:"external_id;not null;unique"`
UserPhotoURL string `gorm:"user_photo type:varchar(255);unique"` UserPhotoURL string `gorm:"user_photo type:varchar(255);unique"`

View File

@ -79,12 +79,12 @@ func getConnectionById(id int) *Connection {
return &connection return &connection
} }
func (u *UserTG) saveUser() error { func (u *Users) saveUser() error {
return orm.DB.Save(u).Error return orm.DB.Save(u).Error
} }
func getUserByExternalID(eid int) *UserTG { func getUserByExternalID(eid int) *Users {
user := UserTG{ExternalID: eid} user := Users{ExternalID: eid}
orm.DB.First(&user) orm.DB.First(&user)
return &user return &user

View File

@ -75,7 +75,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string
user := getUserByExternalID(update.Message.From.ID) user := getUserByExternalID(update.Message.From.ID)
if time.Now().After(user.UpdatedAt.Add(time.Hour*time.Duration(config.UpdateTime))) || user.ID == 0 { if time.Now().After(user.UpdatedAt.Add(time.Hour*time.Duration(config.UpdateInterval))) || user.ID == 0 {
fileID, fileURL, err := getFileIDAndURL(b.Token, update.Message.From.ID) fileID, fileURL, err := getFileIDAndURL(b.Token, update.Message.From.ID)
if err != nil { if err != nil {