init: Initial commit
This commit is contained in:
58
app/repositories/channel.go
Normal file
58
app/repositories/channel.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"git.secnex.io/secnex/masterlog"
|
||||
"git.secnex.io/secnex/taro-bot/database"
|
||||
"git.secnex.io/secnex/taro-bot/models"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func CreateChannel(name, tenantId, externalId string) error {
|
||||
channel := &models.Channel{
|
||||
Name: name,
|
||||
TenantID: uuid.MustParse(tenantId),
|
||||
ExternalID: externalId,
|
||||
}
|
||||
return database.DB.Create(channel).Error
|
||||
}
|
||||
|
||||
func UpsertChannel(name, tenantId, externalId string) (*models.Channel, error) {
|
||||
masterlog.Debug("Upserting channel", map[string]interface{}{"name": name, "tenantId": tenantId, "externalId": externalId})
|
||||
channel := &models.Channel{}
|
||||
|
||||
tenantUUID := uuid.MustParse(tenantId)
|
||||
|
||||
masterlog.Debug("Upserting channel", map[string]interface{}{"name": name, "tenantId": tenantUUID, "externalId": externalId})
|
||||
|
||||
err := database.DB.
|
||||
Where("external_id = ?", externalId).
|
||||
FirstOrCreate(&channel, models.Channel{
|
||||
Name: name,
|
||||
TenantID: tenantUUID,
|
||||
ExternalID: externalId,
|
||||
}).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
func GetChannelByID(id string) (*models.Channel, error) {
|
||||
var channel models.Channel
|
||||
if err := database.DB.Where("id = ?", id).First(&channel).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
func GetChannelByExternalID(id string) (*models.Channel, error) {
|
||||
var channel models.Channel
|
||||
if err := database.DB.Where("external_id = ?", id).First(&channel).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
func DeleteTeamByExternalID(id string) error {
|
||||
return database.DB.Where("external_id = ?", id).Delete(&models.Channel{}).Error
|
||||
}
|
||||
24
app/repositories/service.go
Normal file
24
app/repositories/service.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"git.secnex.io/secnex/taro-bot/database"
|
||||
"git.secnex.io/secnex/taro-bot/models"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func CreateService(name, description string, url *string) error {
|
||||
service := &models.Service{
|
||||
Name: name,
|
||||
Description: description,
|
||||
URL: url,
|
||||
}
|
||||
return database.DB.Create(service).Error
|
||||
}
|
||||
|
||||
func GetService(id uuid.UUID) (*models.Service, error) {
|
||||
var service models.Service
|
||||
if err := database.DB.Where("id = ?", id).First(&service).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &service, nil
|
||||
}
|
||||
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