25 lines
660 B
Go
25 lines
660 B
Go
|
|
package models
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
type DeliveredStatus struct {
|
||
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
||
|
|
UserID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:uq_delivered_status_user_message" json:"user_id"`
|
||
|
|
MessageID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:uq_delivered_status_user_message" json:"message_id"`
|
||
|
|
DeliveredAt time.Time `gorm:"autoCreateTime" json:"delivered_at"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d *DeliveredStatus) BeforeCreate(tx *gorm.DB) error {
|
||
|
|
if d.ID == uuid.Nil {
|
||
|
|
d.ID = uuid.New()
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (DeliveredStatus) TableName() string { return "delivered_status" }
|