add with http code
This commit is contained in:
@@ -9,26 +9,26 @@ type DataMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
func (dma *DataMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return dma.GenericDeleteOne(id, dma)
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
func (dma *DataMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
return dma.GenericUpdateOne(set, id, dma)
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
func (dma *DataMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return dma.GenericStoreOne(data, dma)
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
func (dma *DataMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var data DataResource
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, dma.GetType())
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dma.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&data)
|
||||
|
||||
return &data, nil
|
||||
return &data, 200, nil
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestStoreOneData(t *testing.T) {
|
||||
}
|
||||
|
||||
dma := DataMongoAccessor{}
|
||||
id, _ := dma.StoreOne(&d)
|
||||
id, _, _ := dma.StoreOne(&d)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
@@ -40,6 +40,6 @@ func TestLoadOneDate(t *testing.T) {
|
||||
}
|
||||
|
||||
dma := DataMongoAccessor{}
|
||||
new_d, _ := dma.StoreOne(&d)
|
||||
new_d, _, _ := dma.StoreOne(&d)
|
||||
assert.Equal(t, d, new_d)
|
||||
}
|
||||
|
||||
@@ -9,28 +9,28 @@ type DatacenterMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
func (dca *DatacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return dca.GenericDeleteOne(id, dca)
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
func (dca *DatacenterMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
return dca.GenericUpdateOne(set, id, dca)
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
func (dca *DatacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return dca.GenericStoreOne(data, dca)
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
func (dca *DatacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var datacenter DatacenterResource
|
||||
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, dca.GetType())
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dca.GetType())
|
||||
if err != nil {
|
||||
dca.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
|
||||
res_mongo.Decode(&datacenter)
|
||||
|
||||
return &datacenter, nil
|
||||
return &datacenter, 200, nil
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestStoreOneDatacenter(t *testing.T) {
|
||||
}
|
||||
|
||||
dcma := DatacenterMongoAccessor{}
|
||||
id, _ := dcma.StoreOne(&dc)
|
||||
id, _, _ := dcma.StoreOne(&dc)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func TestLoadOneDatacenter(t *testing.T) {
|
||||
}
|
||||
|
||||
dcma := DatacenterMongoAccessor{}
|
||||
new_dc, _ := dcma.StoreOne(&dc)
|
||||
new_dc, _, _ := dcma.StoreOne(&dc)
|
||||
|
||||
assert.Equal(t, dc, new_dc)
|
||||
}
|
||||
|
||||
@@ -9,29 +9,29 @@ type ProcessingMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
func (pma *ProcessingMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return pma.GenericDeleteOne(id, pma)
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
func (pma *ProcessingMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
return pma.GenericUpdateOne(set, id, pma)
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
func (pma *ProcessingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return pma.GenericStoreOne(data, pma)
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
func (pma *ProcessingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
|
||||
var processing ProcessingResource
|
||||
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, pma.GetType())
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, pma.GetType())
|
||||
if err != nil {
|
||||
pma.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
|
||||
res_mongo.Decode(&processing)
|
||||
|
||||
return &processing, nil
|
||||
return &processing, 200, nil
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestStoreOneProcessing(t *testing.T) {
|
||||
}
|
||||
|
||||
sma := ProcessingMongoAccessor{}
|
||||
id, _ := sma.StoreOne(&p)
|
||||
id, _, _ := sma.StoreOne(&p)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
@@ -40,6 +40,6 @@ func TestLoadOneProcessing(t *testing.T) {
|
||||
}
|
||||
|
||||
sma := ProcessingMongoAccessor{}
|
||||
new_s, _ := sma.StoreOne(&p)
|
||||
new_s, _, _ := sma.StoreOne(&p)
|
||||
assert.Equal(t, p, new_s)
|
||||
}
|
||||
|
||||
@@ -9,29 +9,29 @@ type StorageMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
func (sma *StorageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return sma.GenericDeleteOne(id, sma)
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
func (sma *StorageMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
return sma.GenericUpdateOne(set, id, sma)
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return sma.GenericStoreOne(data, sma)
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
|
||||
var storage StorageResource
|
||||
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, sma.GetType())
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, sma.GetType())
|
||||
if err != nil {
|
||||
sma.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
|
||||
res_mongo.Decode(&storage)
|
||||
|
||||
return &storage, nil
|
||||
return &storage, 200, nil
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestStoreOneStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
sma := StorageMongoAccessor{}
|
||||
id, _ := sma.StoreOne(&s)
|
||||
id, _, _ := sma.StoreOne(&s)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func TestLoadOneStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
sma := StorageMongoAccessor{}
|
||||
new_s, _ := sma.StoreOne(&s)
|
||||
new_s, _, _ := sma.StoreOne(&s)
|
||||
|
||||
assert.Equal(t, s, new_s)
|
||||
}
|
||||
|
||||
@@ -9,25 +9,25 @@ type WorkflowResourceMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowResourceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericDeleteOne(id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowResourceMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var workflow WorkflowResource
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&workflow)
|
||||
return &workflow, nil
|
||||
return &workflow, 200, nil
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestStoreOneWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
wma := WorkflowResourceMongoAccessor{}
|
||||
id, _ := wma.StoreOne(&w)
|
||||
id, _, _ := wma.StoreOne(&w)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
@@ -38,6 +38,6 @@ func TestLoadOneWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
wma := WorkflowResourceMongoAccessor{}
|
||||
new_w, _ := wma.StoreOne(&w)
|
||||
new_w, _, _ := wma.StoreOne(&w)
|
||||
assert.Equal(t, w, new_w)
|
||||
}
|
||||
|
||||
@@ -33,39 +33,40 @@ func (dma *AbstractAccessor) SetLogger(t DataType) {
|
||||
dma.Type = t.String()
|
||||
}
|
||||
|
||||
func (wfa *AbstractAccessor) GenericStoreOne(data DBObject, accessor Accessor) (DBObject, error) {
|
||||
func (wfa *AbstractAccessor) GenericStoreOne(data DBObject, accessor Accessor) (DBObject, int, error) {
|
||||
data.GenerateID()
|
||||
err := validate.Struct(data)
|
||||
wfa.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 422, err
|
||||
}
|
||||
id, err := mongo.MONGOService.StoreOne(data, wfa.GetType())
|
||||
id, code, err := mongo.MONGOService.StoreOne(data, wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
return accessor.LoadOne(id)
|
||||
}
|
||||
|
||||
func (dma *AbstractAccessor) GenericDeleteOne(id string, accessor Accessor) (DBObject, error) {
|
||||
res, err := accessor.LoadOne(id)
|
||||
func (dma *AbstractAccessor) GenericDeleteOne(id string, accessor Accessor) (DBObject, int, error) {
|
||||
res, code, err := accessor.LoadOne(id)
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not retrieve " + id + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
_, err = mongo.MONGOService.DeleteOne(id, accessor.GetType())
|
||||
_, code, err = mongo.MONGOService.DeleteOne(id, accessor.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not delete " + id + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
return res, nil
|
||||
return res, 200, nil
|
||||
}
|
||||
|
||||
func (dma *AbstractAccessor) GenericUpdateOne(set map[string]interface{}, id string, accessor Accessor) (DBObject, error) {
|
||||
id, err := mongo.MONGOService.UpdateOne(set, id, accessor.GetType())
|
||||
func (dma *AbstractAccessor) GenericUpdateOne(set map[string]interface{}, id string, accessor Accessor) (DBObject, int, error) {
|
||||
id, code, err := mongo.MONGOService.UpdateOne(set, id, accessor.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
}
|
||||
return accessor.LoadOne(id)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ type DBObject interface {
|
||||
type Accessor interface {
|
||||
SetLogger(t DataType)
|
||||
GetType() string
|
||||
LoadOne(id string) (DBObject, error)
|
||||
DeleteOne(id string) (DBObject, error)
|
||||
StoreOne(data DBObject) (DBObject, error)
|
||||
UpdateOne(set map[string]interface{}, id string) (DBObject, error)
|
||||
LoadOne(id string) (DBObject, int, error)
|
||||
DeleteOne(id string) (DBObject, int, error)
|
||||
StoreOne(data DBObject) (DBObject, int, error)
|
||||
UpdateOne(set map[string]interface{}, id string) (DBObject, int, error)
|
||||
}
|
||||
|
||||
@@ -9,25 +9,25 @@ type WorkflowMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericDeleteOne(id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var workflow Workflow
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return nil, err
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&workflow)
|
||||
return &workflow, nil
|
||||
return &workflow, 200, nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func TestStoreOneWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
wma := WorkflowMongoAccessor{}
|
||||
id, _ := wma.StoreOne(&w)
|
||||
id, _, _ := wma.StoreOne(&w)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
@@ -24,6 +24,6 @@ func TestLoadOneWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
wma := WorkflowMongoAccessor{}
|
||||
new_w, _ := wma.StoreOne(&w)
|
||||
new_w, _, _ := wma.StoreOne(&w)
|
||||
assert.Equal(t, w, new_w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user