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

@ -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

View File

@ -11,7 +11,7 @@ log_level: 5
debug: false
update_time: 24
update_interval: 24
config_aws:
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
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)
);

View File

@ -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"`

View File

@ -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

View File

@ -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 {