resource as resource named
This commit is contained in:
		| @@ -12,7 +12,7 @@ type URL struct { | ||||
| 	Path     string `bson:"path" json:"path"` | ||||
| } | ||||
|  | ||||
| type Storage struct { | ||||
| type StorageResource struct { | ||||
| 	resources.AbstractResource | ||||
|  | ||||
| 	Capacity uint `bson:"capacity,omitempty" json:"capacity,omitempty"` | ||||
| @@ -24,7 +24,7 @@ type Storage struct { | ||||
| 	BookingPrice uint   `bson:"booking_price,omitempty" json:"booking_price,omitempty"` | ||||
| } | ||||
|  | ||||
| func (dma *Storage) Deserialize(j map[string]interface{}) utils.DBObject { | ||||
| func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject { | ||||
| 	b, err := json.Marshal(j) | ||||
| 	if err != nil { | ||||
| 		return nil | ||||
| @@ -33,7 +33,7 @@ func (dma *Storage) Deserialize(j map[string]interface{}) utils.DBObject { | ||||
| 	return dma | ||||
| } | ||||
|  | ||||
| func (dma *Storage) Serialize() map[string]interface{} { | ||||
| func (dma *StorageResource) Serialize() map[string]interface{} { | ||||
| 	var m map[string]interface{} | ||||
| 	b, err := json.Marshal(dma) | ||||
| 	if err != nil { | ||||
| @@ -43,8 +43,8 @@ func (dma *Storage) Serialize() map[string]interface{} { | ||||
| 	return m | ||||
| } | ||||
|  | ||||
| func (d *Storage) GetAccessor() utils.Accessor { | ||||
| func (d *StorageResource) GetAccessor() utils.Accessor { | ||||
| 	data := &StorageMongoAccessor{} | ||||
| 	data.SetLogger(resources.STORAGE) | ||||
| 	data.SetLogger(utils.STORAGE_RESOURCE) | ||||
| 	return data | ||||
| } | ||||
|   | ||||
| @@ -18,21 +18,12 @@ func (sma *StorageMongoAccessor) UpdateOne(set map[string]interface{}, id string | ||||
| } | ||||
|  | ||||
| func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) { | ||||
| 	err := utils.Validate.Struct(data) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	id, err := mongo.MONGOService.StoreOne(data.(*Storage), sma.GetType()) | ||||
| 	if err != nil { | ||||
| 		sma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error()) | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return sma.LoadOne(id) | ||||
| 	return sma.GenericStoreOne(data, sma) | ||||
| } | ||||
|  | ||||
| func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, error) { | ||||
|  | ||||
| 	var storage Storage | ||||
| 	var storage StorageResource | ||||
|  | ||||
| 	res_mongo, err := mongo.MONGOService.LoadOne(id, sma.GetType()) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -4,20 +4,20 @@ import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	resources "cloud.o-forge.io/core/oc-lib/models/resources" | ||||
| 	"cloud.o-forge.io/core/oc-lib/models/utils" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestStoreOneStorage(t *testing.T) { | ||||
| 	s := Storage{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"}, | ||||
| 	s := StorageResource{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"}, | ||||
| 		AbstractResource: resources.AbstractResource{ | ||||
| 			Uuid:        "123", | ||||
| 			Name:        "testData", | ||||
| 			Description: "Lorem Ipsum", | ||||
| 			Logo:        "azerty.com", | ||||
| 			Owner:       "toto", | ||||
| 			OwnerLogo:   "totoLogo", | ||||
| 			SourceUrl:   "azerty.fr", | ||||
| 			AbstractObject: utils.AbstractObject{Name: "testData"}, | ||||
| 			Description:    "Lorem Ipsum", | ||||
| 			Logo:           "azerty.com", | ||||
| 			Owner:          "toto", | ||||
| 			OwnerLogo:      "totoLogo", | ||||
| 			SourceUrl:      "azerty.fr", | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| @@ -28,15 +28,14 @@ func TestStoreOneStorage(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestLoadOneStorage(t *testing.T) { | ||||
| 	s := Storage{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"}, | ||||
| 	s := StorageResource{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"}, | ||||
| 		AbstractResource: resources.AbstractResource{ | ||||
| 			Uuid:        "123", | ||||
| 			Name:        "testData", | ||||
| 			Description: "Lorem Ipsum", | ||||
| 			Logo:        "azerty.com", | ||||
| 			Owner:       "toto", | ||||
| 			OwnerLogo:   "totoLogo", | ||||
| 			SourceUrl:   "azerty.fr", | ||||
| 			AbstractObject: utils.AbstractObject{Name: "testData"}, | ||||
| 			Description:    "Lorem Ipsum", | ||||
| 			Logo:           "azerty.com", | ||||
| 			Owner:          "toto", | ||||
| 			OwnerLogo:      "totoLogo", | ||||
| 			SourceUrl:      "azerty.fr", | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user