azote-backend/models/userModel.go

24 lines
524 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 {
ID uuid.UUID `gorm:"type:char(36);primary_key;"`
CreatedAt time.Time
UpdatedAt time.Time
Avatar File `gorm:"foreignKey:UserID;"`
Username string `gorm:"unique"`
Email string `gorm:"unique"`
Password string `json:"-"`
Posts []Post `gorm:"foreignKey:Author;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}
func (user *User) BeforeCreate(tx *gorm.DB) (err error) {
user.ID = uuid.New()
return
}