-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_history_test.go
69 lines (60 loc) · 1.9 KB
/
order_history_test.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
64
65
66
67
68
69
package struct_snapshot
type OrderHistory struct {
OldEntity *Order
UpdatedEntity *Order
}
func (oh *OrderHistory) InitStructs() {
oh.OldEntity = &Order{}
oh.UpdatedEntity = &Order{}
}
func (oh *OrderHistory) ToFillEntitiesFields(oldEntity Entity, updatedEntity Entity) {
if oldEntity != nil {
order := oldEntity.(*Order)
oh.OldEntity.CompanyName = order.CompanyName
oh.OldEntity.BrigadeName = order.BrigadeName
oh.OldEntity.StatusInt = order.StatusInt
oh.OldEntity.IsBlocked = order.IsBlocked
}
if updatedEntity != nil {
order := updatedEntity.(*Order)
oh.UpdatedEntity.CompanyName = order.CompanyName
oh.UpdatedEntity.BrigadeName = order.BrigadeName
oh.UpdatedEntity.StatusInt = order.StatusInt
oh.UpdatedEntity.IsBlocked = order.IsBlocked
}
}
func (oh *OrderHistory) PrepareFieldsData() Changes {
observableFields := make(map[string]*Field)
if !oh.FieldIsEqual(oh.OldEntity.BrigadeName, oh.UpdatedEntity.BrigadeName) {
observableFields[ObservableOrderBrigade] = &Field{
OldValue: oh.OldEntity.BrigadeName,
NewValue: oh.UpdatedEntity.BrigadeName,
}
}
if !oh.FieldIsEqual(oh.OldEntity.CompanyName, oh.UpdatedEntity.CompanyName) {
observableFields[ObservableOrderCompany] = &Field{
OldValue: oh.OldEntity.CompanyName,
NewValue: oh.UpdatedEntity.CompanyName,
}
}
if !oh.FieldIsEqual(oh.OldEntity.StatusInt, oh.UpdatedEntity.StatusInt) {
observableFields[ObservableOrderStatus] = &Field{
OldValue: oh.OldEntity.StatusInt,
NewValue: oh.UpdatedEntity.StatusInt,
}
}
if !oh.FieldIsEqual(oh.OldEntity.IsBlocked, oh.UpdatedEntity.IsBlocked) {
observableFields[ObservableOrderIsBlocked] = &Field{
OldValue: oh.OldEntity.IsBlocked,
NewValue: oh.UpdatedEntity.IsBlocked,
}
}
return observableFields
}
func (oh *OrderHistory) FieldIsEqual(old any, new any) bool {
return old == new
}
func (oh *OrderHistory) Reset() {
oh.OldEntity = nil
oh.UpdatedEntity = nil
}