diff --git a/config.go b/config.go index 7a4ede1..6b8c6af 100644 --- a/config.go +++ b/config.go @@ -10,13 +10,13 @@ import ( // TransportConfig struct type TransportConfig struct { - LogLevel logging.Level `yaml:"log_level"` - Database DatabaseConfig `yaml:"database"` - SentryDSN string `yaml:"sentry_dsn"` - HTTPServer HTTPServerConfig `yaml:"http_server"` - Debug bool `yaml:"debug"` - UpdateTime int `yaml:"update_time"` - ConfigAWS ConfigAWS `yaml:"config_aws"` + LogLevel logging.Level `yaml:"log_level"` + Database DatabaseConfig `yaml:"database"` + SentryDSN string `yaml:"sentry_dsn"` + HTTPServer HTTPServerConfig `yaml:"http_server"` + Debug bool `yaml:"debug"` + UpdateInterval int `yaml:"update_interval"` + ConfigAWS ConfigAWS `yaml:"config_aws"` } // ConfigAWS struct diff --git a/config.yml.dist b/config.yml.dist index d0ffe8b..0618529 100644 --- a/config.yml.dist +++ b/config.yml.dist @@ -11,7 +11,7 @@ log_level: 5 debug: false -update_time: 24 +update_interval: 24 config_aws: access_key_id: ~ diff --git a/migrations/1528208070_app.down.sql b/migrations/1528208070_app.down.sql index 66c6be7..7fa478c 100644 --- a/migrations/1528208070_app.down.sql +++ b/migrations/1528208070_app.down.sql @@ -1 +1 @@ -drop table user_tg; \ No newline at end of file +drop table users; diff --git a/migrations/1528208070_app.up.sql b/migrations/1528208070_app.up.sql index 21ea3ce..e9c007f 100644 --- a/migrations/1528208070_app.up.sql +++ b/migrations/1528208070_app.up.sql @@ -1,4 +1,4 @@ -create table user_tg +create table users ( id serial not null constraint user_tg_pkey @@ -10,4 +10,3 @@ create table user_tg updated_at timestamp with time zone, constraint user_tg_key unique(external_id, user_photo, user_photo_id) ); - diff --git a/models.go b/models.go index f576dba..841ba0e 100644 --- a/models.go +++ b/models.go @@ -28,8 +28,8 @@ type Bot struct { Active bool `json:"active,omitempty"` } -// UserTG model -type UserTG struct { +// Users model +type Users struct { ID int `gorm:"primary_key"` ExternalID int `gorm:"external_id;not null;unique"` UserPhotoURL string `gorm:"user_photo type:varchar(255);unique"` diff --git a/repository.go b/repository.go index 7eb94c9..615cec0 100644 --- a/repository.go +++ b/repository.go @@ -79,12 +79,12 @@ func getConnectionById(id int) *Connection { return &connection } -func (u *UserTG) saveUser() error { +func (u *Users) saveUser() error { return orm.DB.Save(u).Error } -func getUserByExternalID(eid int) *UserTG { - user := UserTG{ExternalID: eid} +func getUserByExternalID(eid int) *Users { + user := Users{ExternalID: eid} orm.DB.First(&user) return &user diff --git a/telegram.go b/telegram.go index be8dd94..83833b3 100644 --- a/telegram.go +++ b/telegram.go @@ -75,7 +75,7 @@ func telegramWebhookHandler(w http.ResponseWriter, r *http.Request, token string 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) if err != nil {