Files
taro-bot/app/models/webhook.go
Björn Benouarets fc8238759a init: Initial commit
2026-01-20 06:53:05 +01:00

36 lines
995 B
Go

package models
import (
"time"
"git.secnex.io/secnex/taro-bot/utils"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Webhook struct {
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"id"`
ServiceID uuid.UUID `gorm:"not null" json:"service_id"`
Token string `gorm:"not null" json:"token"`
ChannelID uuid.UUID `gorm:"not null" json:"channel_id"`
CreatedAt time.Time `gorm:"not null;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"not null;default:now()" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
Service *Service `gorm:"foreignKey:ServiceID" json:"service"`
Channel *Channel `gorm:"foreignKey:ChannelID" json:"channel"`
}
func (Webhook) TableName() string {
return "webhooks"
}
func (webhook *Webhook) BeforeCreate(tx *gorm.DB) (err error) {
tokenHash, err := utils.Hash(webhook.Token)
if err != nil {
return err
}
webhook.Token = tokenHash
return nil
}