45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package repositories
|
|
|
|
import (
|
|
"git.secnex.io/secnex/taro-bot/database"
|
|
"git.secnex.io/secnex/taro-bot/models"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func CreateWebhook(serviceId, channelId uuid.UUID, token string) (*models.Webhook, error) {
|
|
webhook := &models.Webhook{
|
|
ServiceID: serviceId,
|
|
ChannelID: channelId,
|
|
Token: token,
|
|
}
|
|
err := database.DB.Create(webhook).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return webhook, nil
|
|
}
|
|
|
|
func GetWebhookByID(id uuid.UUID) (*models.Webhook, error) {
|
|
var webhook models.Webhook
|
|
if err := database.DB.Where("id = ?", id).First(&webhook).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &webhook, nil
|
|
}
|
|
|
|
func GetWebhookByServiceID(serviceId uuid.UUID) (*models.Webhook, error) {
|
|
var webhook models.Webhook
|
|
if err := database.DB.Where("service_id = ?", serviceId).First(&webhook).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &webhook, nil
|
|
}
|
|
|
|
func GetWebhookByChannelID(channelId uuid.UUID) (*models.Webhook, error) {
|
|
var webhook models.Webhook
|
|
if err := database.DB.Where("channel_id = ?", channelId).First(&webhook).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &webhook, nil
|
|
}
|