From 5ffbac8dd2c271e1453b66d2abe630f4ecc40b12 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Thu, 23 May 2024 14:22:44 +0300 Subject: [PATCH] fix various bugs --- internal/db/repository/chat.go | 4 ++-- internal/db/repository/integration.go | 2 +- internal/db/repository/user.go | 4 ++-- internal/handler/util/payload.go | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/db/repository/chat.go b/internal/db/repository/chat.go index d06ba72..f402f30 100644 --- a/internal/db/repository/chat.go +++ b/internal/db/repository/chat.go @@ -24,7 +24,7 @@ func (c *Chat) ByID(id uint64) (*model.Chat, error) { func (c *Chat) ByTelegramID(id int64) (*model.Chat, error) { var chat model.Chat - if err := c.db.Model(model.Chat{TelegramID: id}).First(&chat).Error; err != nil { + if err := c.db.Model(&model.Chat{}).Where("telegram_id = ?", id).First(&chat).Error; err != nil { return nil, util.HandleRecordNotFound(err) } return &chat, nil @@ -32,7 +32,7 @@ func (c *Chat) ByTelegramID(id int64) (*model.Chat, error) { func (c *Chat) ByTelegramIDWithIntegrations(id int64) (*model.Chat, error) { var chat model.Chat - if err := c.db.Model(model.Chat{TelegramID: id}).Preload("Integrations").First(&chat).Error; err != nil { + if err := c.db.Model(&model.Chat{}).Where("telegram_id = ?", id).Preload("Integrations").First(&chat).Error; err != nil { return nil, util.HandleRecordNotFound(err) } return &chat, nil diff --git a/internal/db/repository/integration.go b/internal/db/repository/integration.go index 93f1329..d5eb715 100644 --- a/internal/db/repository/integration.go +++ b/internal/db/repository/integration.go @@ -16,7 +16,7 @@ func NewIntegration(db *gorm.DB) *Integration { func (r *Integration) LoadForChatAndType(chatID uint64, typ model.IntegrationType) (*model.Integration, error) { var integration model.Integration - if err := r.db.Model(model.Integration{ChatID: chatID, Type: typ}).First(&integration).Error; err != nil { + if err := r.db.Model(&model.Integration{}).Where(`chat_id = ? and "type" = ?`, chatID, typ).First(&integration).Error; err != nil { return nil, util.HandleRecordNotFound(err) } return &integration, nil diff --git a/internal/db/repository/user.go b/internal/db/repository/user.go index 2222df4..a52cd16 100644 --- a/internal/db/repository/user.go +++ b/internal/db/repository/user.go @@ -24,7 +24,7 @@ func (u *User) ByID(id uint64) (*model.User, error) { func (u *User) ByTelegramID(id int64) (*model.User, error) { var user model.User - if err := u.db.Model(model.User{TelegramID: id}).First(&user).Error; err != nil { + if err := u.db.Model(&model.User{}).Where("telegram_id = ?", id).First(&user).Error; err != nil { return nil, util.HandleRecordNotFound(err) } return &user, nil @@ -32,7 +32,7 @@ func (u *User) ByTelegramID(id int64) (*model.User, error) { func (u *User) ByTelegramIDs(ids []int64) ([]model.User, error) { var users []model.User - if err := u.db.Model(model.User{}).Where("telegram_id in (?)", ids).Find(&users).Error; err != nil { + if err := u.db.Model(&model.User{}).Where("telegram_id in (?)", ids).Find(&users).Error; err != nil { return nil, util.HandleRecordNotFound(err) } return users, nil diff --git a/internal/handler/util/payload.go b/internal/handler/util/payload.go index 1e3bc6a..cb51341 100644 --- a/internal/handler/util/payload.go +++ b/internal/handler/util/payload.go @@ -44,7 +44,7 @@ func (p Payload) Vote() (val Vote) { } func (p Payload) KeyboardChoice() (val KBChooserData) { - if p.Action != PayloadActionVote { + if p.Action != PayloadActionChooseKeyboard { return } _ = json.Unmarshal(p.Data, &val) @@ -65,7 +65,7 @@ type Member struct { } type KBChooserData struct { - Type uint8 `json:"k"` + Type int64 `json:"k"` } type Vote struct { @@ -83,7 +83,7 @@ func NewKeyboardChooserPayload(userID, chatID int64, kbType uint8) *Payload { User: userID, Chat: chatID, Data: marshal(KBChooserData{ - Type: kbType, + Type: int64(kbType), }), } }