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"`
|
||||
HTTPServer HTTPServerConfig `yaml:"http_server"`
|
||||
Debug bool `yaml:"debug"`
|
||||
UpdateTime int `yaml:"update_time"`
|
||||
UpdateInterval int `yaml:"update_interval"`
|
||||
ConfigAWS ConfigAWS `yaml:"config_aws"`
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ log_level: 5
|
||||
|
||||
debug: false
|
||||
|
||||
update_time: 24
|
||||
update_interval: 24
|
||||
|
||||
config_aws:
|
||||
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
|
||||
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)
|
||||
);
|
||||
|
||||
|
@ -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"`
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user