init: Initial commit
This commit is contained in:
24
app/models/channel.go
Normal file
24
app/models/channel.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
TenantID uuid.UUID `gorm:"not null" json:"tenant_id"`
|
||||
ExternalID string `gorm:"not null" json:"external_id"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
|
||||
|
||||
Webhooks []Webhook `gorm:"foreignKey:ChannelID" json:"webhooks"`
|
||||
}
|
||||
|
||||
func (Channel) TableName() string {
|
||||
return "channels"
|
||||
}
|
||||
24
app/models/service.go
Normal file
24
app/models/service.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
ID uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"id"`
|
||||
Name string `gorm:"not null;unique" json:"name"`
|
||||
Description string `gorm:"not null" json:"description"`
|
||||
URL *string `json:"url"`
|
||||
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"`
|
||||
|
||||
Webhooks []Webhook `gorm:"foreignKey:ServiceID" json:"webhooks"`
|
||||
}
|
||||
|
||||
func (Service) TableName() string {
|
||||
return "services"
|
||||
}
|
||||
35
app/models/webhook.go
Normal file
35
app/models/webhook.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user