/
model.go
48 lines (42 loc) · 1.13 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
package mongodb
import (
"time"
"github.com/blackhorseya/ekko/entity/domain/workflow/agg"
"github.com/blackhorseya/ekko/entity/domain/workflow/model"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type issue struct {
ID primitive.ObjectID `bson:"_id"`
Title string `bson:"title"`
Completed bool `bson:"completed"`
OwnerID string `bson:"owner_id"`
CreatedAt time.Time `bson:"created_at"`
UpdatedAt time.Time `bson:"updated_at"`
}
func newIssue(v *agg.Issue) *issue {
id := primitive.NewObjectIDFromTimestamp(time.Now())
if v.ID != "" {
id, _ = primitive.ObjectIDFromHex(v.ID)
}
return &issue{
ID: id,
Title: v.Ticket.Title,
Completed: v.Ticket.Completed,
OwnerID: v.Ticket.OwnerID,
CreatedAt: v.Ticket.CreatedAt,
UpdatedAt: v.Ticket.UpdatedAt,
}
}
// ToAgg is to convert issue to aggregate issue.
func (x *issue) ToAgg() *agg.Issue {
return &agg.Issue{
Ticket: &model.Ticket{
ID: x.ID.Hex(),
Title: x.Title,
Completed: x.Completed,
OwnerID: x.OwnerID,
CreatedAt: x.CreatedAt,
UpdatedAt: x.UpdatedAt,
},
}
}