Files
gin-gonic-prepack/models/base.go
🐙PiperYxzzy 8ab45e2401 Login, JWT and auth overstructure
* Signup -> Login -> JWT-Doot flow now works for users
* Administrators cannot currently sign up for obvious reasons
* Segmented the main.go methods into a core controller package
2022-05-01 12:31:41 +02:00

37 lines
605 B
Go

package models
import (
"errors"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Base struct {
Uid uuid.UUID `gorm:"type:uuid;primary_key;"`
Created time.Time
Updated time.Time
Deleted time.Time `sql:"index"`
Tenant uuid.UUID `sql:"index"`
}
func (b *Base) BeforeCreate(scope *gorm.DB) error {
b.Uid = uuid.New()
b.Created = time.Now()
return nil
}
func (b *Base) BeforeSave(scope *gorm.DB) error {
if b.Tenant == uuid.Nil {
return errors.New("cannot save an untenanted object")
}
b.Updated = time.Now()
return nil
}
func (b *Base) Delete() {
b.Deleted = time.Now()
}