2024-05-09 20:48:59 +03:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/db/model"
|
2024-05-09 23:26:21 +03:00
|
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/db/util"
|
2024-05-09 20:48:59 +03:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Integration struct {
|
|
|
|
db *gorm.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIntegration(db *gorm.DB) *Integration {
|
|
|
|
return &Integration{db: db}
|
|
|
|
}
|
|
|
|
|
2024-05-09 23:26:21 +03:00
|
|
|
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 {
|
|
|
|
return nil, util.HandleRecordNotFound(err)
|
|
|
|
}
|
|
|
|
return &integration, nil
|
|
|
|
}
|
|
|
|
|
2024-05-09 20:48:59 +03:00
|
|
|
func (r *Integration) Save(integration *model.Integration) error {
|
2024-05-23 13:55:05 +03:00
|
|
|
if integration.ID == 0 {
|
|
|
|
return r.db.Create(integration).Error
|
|
|
|
}
|
2024-05-09 20:48:59 +03:00
|
|
|
return r.db.Model(integration).Save(integration).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Integration) DeleteForChat(id uint64) error {
|
|
|
|
return r.db.Where("chat_id = ?", id).Delete(&model.Integration{}).Error
|
|
|
|
}
|