validator use test

This commit is contained in:
mr 2024-07-19 09:32:58 +02:00
parent 071a49cd81
commit e838474835
8 changed files with 61 additions and 9 deletions

View File

@ -36,8 +36,7 @@ func Init(appName string) {
} }
func GetLogger() zerolog.Logger { func GetLogger() zerolog.Logger {
log := logs.GetLogger() return logs.GetLogger()
return log
} }
func LoadOne(collection LibDataEnum, id string) LibData { func LoadOne(collection LibDataEnum, id string) LibData {
@ -46,7 +45,9 @@ func LoadOne(collection LibDataEnum, id string) LibData {
} }
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData { func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
d, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id) model := models.Model(collection.EnumIndex())
set = model.Deserialize(set).Serialize()
d, err := model.GetAccessor().UpdateOne(set, id)
return LibData{Data: d, Err: err} return LibData{Data: d, Err: err}
} }

View File

@ -23,6 +23,16 @@ func (dma *Data) Deserialize(j map[string]interface{}) utils.DBObject {
return dma return dma
} }
func (dma *Data) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
func (d *Data) GetType() resources.ResourceType { func (d *Data) GetType() resources.ResourceType {
return resources.DATA return resources.DATA
} }

View File

@ -46,6 +46,16 @@ func (dma *Datacenter) Deserialize(j map[string]interface{}) utils.DBObject {
return dma return dma
} }
func (dma *Datacenter) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
func (d *Datacenter) GetType() resources.ResourceType { func (d *Datacenter) GetType() resources.ResourceType {
return resources.DATACENTER return resources.DATACENTER
} }

View File

@ -40,6 +40,16 @@ func (dma *Processing) Deserialize(j map[string]interface{}) utils.DBObject {
return dma return dma
} }
func (dma *Processing) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
func (p *Processing) GetType() resources.ResourceType { func (p *Processing) GetType() resources.ResourceType {
return resources.PROCESSING return resources.PROCESSING
} }

View File

@ -44,14 +44,14 @@ type Resource interface {
} }
type AbstractResource struct { type AbstractResource struct {
Uuid string `json:"uuid" required:"true" bson:"uuid"` Uuid string `json:"uuid" required:"true" bson:"uuid" validate:"required"`
Name string `json:"name" required:"true" bson:"name"` Name string `json:"name" required:"true" bson:"name" validate:"required"`
ShortDescription string `json:"short_description" required:"true" bson:"short_description"` ShortDescription string `json:"short_description" required:"true" bson:"short_description" validate:"required"`
Description string `json:"description,omitempty" bson:"description"` Description string `json:"description,omitempty" bson:"description"`
Logo string `json:"logo" required:"true" bson:"logo"` Logo string `json:"logo" required:"true" bson:"logo" validate:"required"`
Owner string `json:"owner" required:"true" bson:"owner"` Owner string `json:"owner" required:"true" bson:"owner" validate:"required"`
OwnerLogo string `json:"owner_logo" required:"true" bson:"owner_logo"` OwnerLogo string `json:"owner_logo" required:"true" bson:"owner_logo"`
SourceUrl string `json:"source_url" required:"true" bson:"source_url"` SourceUrl string `json:"source_url" required:"true" bson:"source_url" validate:"required"`
} }
func (r *AbstractResource) GetID() string { func (r *AbstractResource) GetID() string {

View File

@ -33,6 +33,16 @@ func (dma *Storage) Deserialize(j map[string]interface{}) utils.DBObject {
return dma return dma
} }
func (dma *Storage) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
func (d *Storage) GetAccessor() utils.Accessor { func (d *Storage) GetAccessor() utils.Accessor {
data := &StorageMongoAccessor{} data := &StorageMongoAccessor{}
data.SetLogger(resources.STORAGE) data.SetLogger(resources.STORAGE)

View File

@ -37,6 +37,16 @@ func (dma *Workflow) Deserialize(j map[string]interface{}) utils.DBObject {
return dma return dma
} }
func (dma *Workflow) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
func (w *Workflow) isDCLink(link graph.GraphLink) bool { func (w *Workflow) isDCLink(link graph.GraphLink) bool {
if _, exists := w.Datacenters[link.Destination.ID]; exists { if _, exists := w.Datacenters[link.Destination.ID]; exists {
return true return true

View File

@ -5,6 +5,7 @@ import "cloud.o-forge.io/core/oc-lib/models/resources"
type DBObject interface { type DBObject interface {
GetName() string GetName() string
Deserialize(j map[string]interface{}) DBObject Deserialize(j map[string]interface{}) DBObject
Serialize() map[string]interface{}
GetAccessor() Accessor GetAccessor() Accessor
} }