organised in packages
This commit is contained in:
parent
02b0a2a595
commit
2684703da5
23
data/data.go
Normal file
23
data/data.go
Normal file
@ -0,0 +1,23 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
oclib "oc-lib"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
oclib.AbstractResource
|
||||
|
||||
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
||||
DataType string `json:"datatype" required:"true" bson:"datatype"`
|
||||
Example string `json:"example" bson:"example" required:"true" validate:"required" description:"base64 encoded data"`
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (d *Data) GetType() oclib.ResourceType{
|
||||
return oclib.DATA
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
38
data/data_mongo_accessor.go
Normal file
38
data/data_mongo_accessor.go
Normal file
@ -0,0 +1,38 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
logger "oc-lib/logs"
|
||||
mongo "oc-lib/mongo"
|
||||
)
|
||||
|
||||
type DataMongoAccessor struct{
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (dma *DataMongoAccessor) StoreOne(data Data) string {
|
||||
|
||||
id, err := mongo.StoreOne(data,"data")
|
||||
if err != nil{
|
||||
l := logger.CreateLogger("oclib","")
|
||||
l.Error().Msg("Could not store " + data.Name + " to db. Error: " + err.Error())
|
||||
return ""
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) LoadOne(id string) Data {
|
||||
|
||||
var data Data
|
||||
|
||||
res_mongo, err := mongo.LoadOne(id,"data")
|
||||
if err != nil{
|
||||
l := logger.CreateLogger("oclib","")
|
||||
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return Data{}
|
||||
}
|
||||
|
||||
res_mongo.Decode(&data)
|
||||
|
||||
return data
|
||||
}
|
47
data/data_test.go
Normal file
47
data/data_test.go
Normal file
@ -0,0 +1,47 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
oclib "oc-lib"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneData(t *testing.T){
|
||||
d := Data{DataType: "jpeg", Example: "123456",
|
||||
AbstractResource: oclib.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo : "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
dma := DataMongoAccessor{}
|
||||
id := dma.StoreOne(d)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
|
||||
func TestLoadOneDate(t *testing.T){
|
||||
d := Data{DataType: "jpeg", Example: "123456",
|
||||
AbstractResource: oclib.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo : "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
dma := DataMongoAccessor{}
|
||||
id := dma.StoreOne(d)
|
||||
new_d := dma.LoadOne(id)
|
||||
|
||||
assert.Equal(t,d, new_d)
|
||||
}
|
1
data/datacenter_workflows.go
Normal file
1
data/datacenter_workflows.go
Normal file
@ -0,0 +1 @@
|
||||
package data
|
Loading…
Reference in New Issue
Block a user