init: Initial commit
This commit is contained in:
44
app/repositories/webhook.go
Normal file
44
app/repositories/webhook.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user