private accessor

This commit is contained in:
mr
2024-07-31 10:07:55 +02:00
parent d6a2a416c1
commit 7ae1399a9a
21 changed files with 121 additions and 87 deletions

View File

@@ -44,7 +44,7 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
}
func (d *StorageResource) GetAccessor() utils.Accessor {
data := &StorageMongoAccessor{}
data := New()
data.SetLogger(utils.STORAGE_RESOURCE)
return data
}

View File

@@ -6,29 +6,33 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type StorageMongoAccessor struct {
type storageMongoAccessor struct {
utils.AbstractAccessor
}
func (sma *StorageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *storageMongoAccessor {
return &storageMongoAccessor{}
}
func (sma *storageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return sma.GenericDeleteOne(id, sma)
}
func (sma *StorageMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*StorageResource).ResourceModel = nil
return sma.GenericUpdateOne(set, id, sma, &StorageResource{})
}
func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*StorageResource).ResourceModel = nil
return sma.GenericStoreOne(data, sma)
}
func (sma *StorageMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return sma.GenericStoreOne(data, sma)
}
func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var storage StorageResource
@@ -47,7 +51,7 @@ func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
return &storage, 200, nil
}
func (wfa StorageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa storageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@@ -69,7 +73,7 @@ func (wfa StorageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
return objs, 200, nil
}
func (wfa *StorageMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *storageMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}, wfa.GetType())
if err != nil {

View File

@@ -21,7 +21,7 @@ func TestStoreOneStorage(t *testing.T) {
},
}
sma := StorageMongoAccessor{}
sma := New()
id, _, _ := sma.StoreOne(&s)
assert.NotEmpty(t, id)
@@ -39,7 +39,7 @@ func TestLoadOneStorage(t *testing.T) {
},
}
sma := StorageMongoAccessor{}
sma := New()
new_s, _, _ := sma.StoreOne(&s)
assert.Equal(t, s, new_s)