28 lines
701 B
Go
28 lines
701 B
Go
|
|
package model
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
// UserBlock 用户拉黑关系
|
||
|
|
type UserBlock struct {
|
||
|
|
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
||
|
|
BlockerID string `json:"blocker_id" gorm:"type:varchar(36);index;not null;uniqueIndex:idx_blocker_blocked"` // 拉黑人
|
||
|
|
BlockedID string `json:"blocked_id" gorm:"type:varchar(36);index;not null;uniqueIndex:idx_blocker_blocked"` // 被拉黑人
|
||
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (b *UserBlock) BeforeCreate(tx *gorm.DB) error {
|
||
|
|
if b.ID == "" {
|
||
|
|
b.ID = uuid.New().String()
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (UserBlock) TableName() string {
|
||
|
|
return "user_blocks"
|
||
|
|
}
|