change naming user struct
This commit is contained in:
parent
3bb3d9bd4f
commit
a391a01c0f
@ -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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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: ~
|
||||||
|
@ -1 +1 @@
|
|||||||
drop table user_tg;
|
drop table users;
|
||||||
|
@ -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)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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"`
|
||||||
|
@ -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
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user