vegapokerbot/internal/db/repository/integration.go
Neur0toxine 5ffbac8dd2
All checks were successful
continuous-integration/drone/push Build is passing
fix various bugs
2024-05-23 14:22:44 +03:00

35 lines
982 B
Go

package repository
import (
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/db/model"
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/db/util"
"gorm.io/gorm"
)
type Integration struct {
db *gorm.DB
}
func NewIntegration(db *gorm.DB) *Integration {
return &Integration{db: db}
}
func (r *Integration) LoadForChatAndType(chatID uint64, typ model.IntegrationType) (*model.Integration, error) {
var integration model.Integration
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
}
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
}
func (r *Integration) DeleteForChat(id uint64) error {
return r.db.Where("chat_id = ?", id).Delete(&model.Integration{}).Error
}