/
model.go
63 lines (49 loc) · 1.07 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package db_repo
import (
"time"
"github.com/justtrackio/gosoline/pkg/mdl"
)
const ColumnUpdatedAt = "updated_at"
//go:generate mockery --name ModelBased
type ModelBased interface {
mdl.Identifiable
TimeStampable
}
type Model struct {
Id *uint `gorm:"primary_key;AUTO_INCREMENT"`
Timestamps
}
func (m *Model) GetId() *uint {
return m.Id
}
//go:generate mockery --name TimeStampable
type TimeStampable interface {
SetUpdatedAt(updatedAt *time.Time)
SetCreatedAt(createdAt *time.Time)
}
type TimestampAware interface {
GetCreatedAt() *time.Time
GetUpdatedAt() *time.Time
}
type Timestamps struct {
UpdatedAt *time.Time
CreatedAt *time.Time
}
func (m *Timestamps) SetUpdatedAt(updatedAt *time.Time) {
m.UpdatedAt = updatedAt
}
func (m *Timestamps) SetCreatedAt(createdAt *time.Time) {
m.CreatedAt = createdAt
}
func (m *Timestamps) GetUpdatedAt() *time.Time {
return m.UpdatedAt
}
func (m *Timestamps) GetCreatedAt() *time.Time {
return m.CreatedAt
}
func EmptyTimestamps() Timestamps {
return Timestamps{
UpdatedAt: &time.Time{},
CreatedAt: &time.Time{},
}
}