2022-08-30 20:03:24 -06:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ModelBase struct {
|
|
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
DeletedAt *time.Time `gorm:"index"`
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://medium.com/@the.hasham.ali/how-to-use-uuid-key-type-with-gorm-cc00d4ec7100
|
|
|
|
|
|
|
|
func (base *ModelBase) BeforeCreate(tx *gorm.DB) error {
|
|
|
|
base.ID = uuid.New()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type OriginBase struct {
|
|
|
|
ModelBase
|
2022-09-10 12:59:13 -06:00
|
|
|
User *User `json:"user,omitempty" gorm:"-"`
|
2022-08-30 20:03:24 -06:00
|
|
|
UserID uuid.UUID `json:"user_id"`
|
|
|
|
|
2022-09-10 12:59:13 -06:00
|
|
|
Source *Source `json:"source,omitempty" gorm:"-"`
|
2022-08-30 22:36:40 -06:00
|
|
|
SourceID uuid.UUID `json:"source_id" gorm:"not null;index:,unique,composite:source_resource_id"`
|
2022-08-30 20:03:24 -06:00
|
|
|
|
2022-08-30 22:36:40 -06:00
|
|
|
SourceResourceType string `json:"source_resource_type" gorm:"not null;index:,unique,composite:source_resource_id"`
|
|
|
|
SourceResourceID string `json:"source_resource_id" gorm:"not null;index:,unique,composite:source_resource_id"`
|
2022-08-30 20:03:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (o OriginBase) GetSourceID() uuid.UUID {
|
|
|
|
return o.SourceID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o OriginBase) GetSourceResourceType() string {
|
|
|
|
return o.SourceResourceType
|
|
|
|
}
|
|
|
|
func (o OriginBase) GetSourceResourceID() string {
|
|
|
|
return o.SourceResourceID
|
|
|
|
}
|
|
|
|
|
|
|
|
type OriginBaser interface {
|
|
|
|
GetSourceID() uuid.UUID
|
|
|
|
GetSourceResourceType() string
|
|
|
|
GetSourceResourceID() string
|
|
|
|
}
|