From be2cc7ddfaa02ea939e8ecbc5845a2e56644dfa7 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Thu, 23 May 2024 13:55:05 +0300 Subject: [PATCH] fix broken create --- internal/db/repository/chat.go | 3 +++ internal/db/repository/integration.go | 3 +++ internal/db/repository/user.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/internal/db/repository/chat.go b/internal/db/repository/chat.go index 50f12fd..d06ba72 100644 --- a/internal/db/repository/chat.go +++ b/internal/db/repository/chat.go @@ -47,6 +47,9 @@ func (c *Chat) ByIDWithIntegrations(id uint64) (*model.Chat, error) { } func (c *Chat) Save(chat *model.Chat) error { + if chat.ID == 0 { + return c.db.Create(chat).Error + } return c.db.Model(chat).Save(chat).Error } diff --git a/internal/db/repository/integration.go b/internal/db/repository/integration.go index 0f35d13..93f1329 100644 --- a/internal/db/repository/integration.go +++ b/internal/db/repository/integration.go @@ -23,6 +23,9 @@ func (r *Integration) LoadForChatAndType(chatID uint64, typ model.IntegrationTyp } func (r *Integration) Save(integration *model.Integration) error { + if integration.ID == 0 { + return r.db.Create(integration).Error + } return r.db.Model(integration).Save(integration).Error } diff --git a/internal/db/repository/user.go b/internal/db/repository/user.go index a7f4908..2222df4 100644 --- a/internal/db/repository/user.go +++ b/internal/db/repository/user.go @@ -47,5 +47,8 @@ func (u *User) ByIDWithChats(id uint64) (*model.User, error) { } func (u *User) Save(user *model.User) error { + if user.ID == 0 { + return u.db.Create(user).Error + } return u.db.Model(user).Save(user).Error }