determine returnal
This commit is contained in:
@@ -10,24 +10,24 @@ type StorageMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (dma *StorageMongoAccessor) DeleteOne(id string) utils.DBObject {
|
||||
func (dma *StorageMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
return dma.GenericDeleteOne(id, dma)
|
||||
}
|
||||
|
||||
func (dma *StorageMongoAccessor) UpdateOne(set map[string]interface{}, id string) utils.DBObject {
|
||||
func (dma *StorageMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
return dma.GenericUpdateOne(set, id, dma)
|
||||
}
|
||||
|
||||
func (dma *StorageMongoAccessor) StoreOne(data utils.DBObject) utils.DBObject {
|
||||
func (dma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
id, err := mongo.MONGOService.StoreOne(data.(*Storage), "data")
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return &Storage{}
|
||||
return nil, err
|
||||
}
|
||||
return dma.LoadOne(id)
|
||||
}
|
||||
|
||||
func (schedulema *StorageMongoAccessor) LoadOne(id string) utils.DBObject {
|
||||
func (schedulema *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
|
||||
var storage Storage
|
||||
|
||||
@@ -35,10 +35,10 @@ func (schedulema *StorageMongoAccessor) LoadOne(id string) utils.DBObject {
|
||||
if err != nil {
|
||||
l := logs.CreateLogger("oclib", "")
|
||||
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return &Storage{}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res_mongo.Decode(&storage)
|
||||
|
||||
return &storage
|
||||
return &storage, nil
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ func TestStoreOneStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
sma := StorageMongoAccessor{}
|
||||
id := sma.StoreOne(&s)
|
||||
id, _ := sma.StoreOne(&s)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func TestLoadOneStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
sma := StorageMongoAccessor{}
|
||||
new_s := sma.StoreOne(&s)
|
||||
new_s, _ := sma.StoreOne(&s)
|
||||
|
||||
assert.Equal(t, s, new_s)
|
||||
}
|
||||
|
Reference in New Issue
Block a user