Files
pocket-id-pocket-id-2/backend/internal/model/base.go

23 lines
471 B
Go
Raw Normal View History

2024-08-12 11:00:25 +02:00
package model
import (
"github.com/google/uuid"
model "github.com/stonith404/pocket-id/backend/internal/model/types"
2024-08-12 11:00:25 +02:00
"gorm.io/gorm"
"time"
)
// Base contains common columns for all tables.
type Base struct {
2025-01-11 20:14:12 +01:00
ID string `gorm:"primaryKey;not null"`
CreatedAt model.DateTime `sortable:"true"`
2024-08-12 11:00:25 +02:00
}
func (b *Base) BeforeCreate(_ *gorm.DB) (err error) {
2024-08-12 11:00:25 +02:00
if b.ID == "" {
b.ID = uuid.New().String()
}
b.CreatedAt = model.DateTime(time.Now())
2024-08-12 11:00:25 +02:00
return
}