azote-backend/models/userModel.go

25 lines
560 B
Go
Raw Normal View History

2024-01-16 00:36:49 +01:00
package models
import (
"github.com/google/uuid"
"gorm.io/gorm"
"time"
)
type User struct {
2024-01-18 23:45:06 +01:00
ID uuid.UUID `gorm:"type:char(36);primary_key;"`
CreatedAt time.Time
UpdatedAt time.Time
Avatar File `gorm:"foreignKey:UserID;"`
Username string `gorm:"unique"`
DisplayName string
Email string `gorm:"unique"`
Password string `json:"-"`
Posts []Post `gorm:"foreignKey:Author;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
2024-01-16 00:36:49 +01:00
}
func (user *User) BeforeCreate(tx *gorm.DB) (err error) {
user.ID = uuid.New()
return
}