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 }