25 lines
626 B
Go
25 lines
626 B
Go
|
|
package models
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ReadReceipt struct {
|
||
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
||
|
|
UserID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:uq_read_receipts_user_message" json:"user_id"`
|
||
|
|
MessageID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:uq_read_receipts_user_message" json:"message_id"`
|
||
|
|
ReadAt time.Time `gorm:"autoCreateTime" json:"read_at"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (r *ReadReceipt) BeforeCreate(tx *gorm.DB) error {
|
||
|
|
if r.ID == uuid.Nil {
|
||
|
|
r.ID = uuid.New()
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (ReadReceipt) TableName() string { return "read_receipts" }
|