-
Notifications
You must be signed in to change notification settings - Fork 0
/
DummyMapMongoDbPersistence.go
135 lines (112 loc) · 4.04 KB
/
DummyMapMongoDbPersistence.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package test_persistence
import (
"reflect"
cdata "github.com/pip-services3-go/pip-services3-commons-go/data"
persist "github.com/pip-services3-go/pip-services3-mongodb-go/persistence"
"go.mongodb.org/mongo-driver/bson"
)
type DummyMapMongoDbPersistence struct {
persist.IdentifiableMongoDbPersistence
}
func NewDummyMapMongoDbPersistence() *DummyMapMongoDbPersistence {
var t map[string]interface{}
proto := reflect.TypeOf(t)
c := &DummyMapMongoDbPersistence{}
c.IdentifiableMongoDbPersistence = *persist.InheritIdentifiableMongoDbPersistence(c, proto, "dummies")
return c
}
func (c *DummyMapMongoDbPersistence) Create(correlationId string, item map[string]interface{}) (result map[string]interface{}, err error) {
value, err := c.IdentifiableMongoDbPersistence.Create(correlationId, item)
if value != nil {
val, _ := value.(map[string]interface{})
result = val
}
return result, err
}
func (c *DummyMapMongoDbPersistence) GetListByIds(correlationId string, ids []string) (items []map[string]interface{}, err error) {
convIds := make([]interface{}, len(ids))
for i, v := range ids {
convIds[i] = v
}
result, err := c.IdentifiableMongoDbPersistence.GetListByIds(correlationId, convIds)
items = make([]map[string]interface{}, len(result))
for i, v := range result {
val, _ := v.(map[string]interface{})
items[i] = val
}
return items, err
}
func (c *DummyMapMongoDbPersistence) GetOneById(correlationId string, id string) (item map[string]interface{}, err error) {
result, err := c.IdentifiableMongoDbPersistence.GetOneById(correlationId, id)
if result != nil {
val, _ := result.(map[string]interface{})
item = val
}
return item, err
}
func (c *DummyMapMongoDbPersistence) Update(correlationId string, item map[string]interface{}) (result map[string]interface{}, err error) {
value, err := c.IdentifiableMongoDbPersistence.Update(correlationId, item)
if value != nil {
val, _ := value.(map[string]interface{})
result = val
}
return result, err
}
func (c *DummyMapMongoDbPersistence) UpdatePartially(correlationId string, id string, data *cdata.AnyValueMap) (item map[string]interface{}, err error) {
result, err := c.IdentifiableMongoDbPersistence.UpdatePartially(correlationId, id, data)
if result != nil {
val, _ := result.(map[string]interface{})
item = val
}
return item, err
}
func (c *DummyMapMongoDbPersistence) DeleteById(correlationId string, id string) (item map[string]interface{}, err error) {
result, err := c.IdentifiableMongoDbPersistence.DeleteById(correlationId, id)
if result != nil {
val, _ := result.(map[string]interface{})
item = val
}
return item, err
}
func (c *DummyMapMongoDbPersistence) DeleteByIds(correlationId string, ids []string) (err error) {
convIds := make([]interface{}, len(ids))
for i, v := range ids {
convIds[i] = v
}
return c.IdentifiableMongoDbPersistence.DeleteByIds(correlationId, convIds)
}
func (c *DummyMapMongoDbPersistence) GetPageByFilter(correlationId string, filter *cdata.FilterParams, paging *cdata.PagingParams) (page *MapPage, err error) {
if filter == nil {
filter = cdata.NewEmptyFilterParams()
}
key := filter.GetAsNullableString("Key")
var filterObj bson.M
if key != nil && *key != "" {
filterObj = bson.M{"key": *key}
} else {
filterObj = bson.M{}
}
sorting := bson.M{"key": -1}
tempPage, err := c.IdentifiableMongoDbPersistence.GetPageByFilter(correlationId, filterObj, paging,
sorting, nil)
dataLen := int64(len(tempPage.Data))
data := make([]map[string]interface{}, dataLen)
for i, v := range tempPage.Data {
data[i] = v.(map[string]interface{})
}
dataPage := NewMapPage(&dataLen, data)
return dataPage, err
}
func (c *DummyMapMongoDbPersistence) GetCountByFilter(correlationId string, filter *cdata.FilterParams) (count int64, err error) {
if filter == nil {
filter = cdata.NewEmptyFilterParams()
}
key := filter.GetAsNullableString("Key")
var filterObj bson.M
if key != nil && *key != "" {
filterObj = bson.M{"key": *key}
} else {
filterObj = bson.M{}
}
return c.IdentifiableMongoDbPersistence.GetCountByFilter(correlationId, filterObj)
}