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 {
log := logs.GetLogger()
return log
return logs.GetLogger()
}
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 {
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}
}

View File

@ -23,6 +23,16 @@ func (dma *Data) Deserialize(j map[string]interface{}) utils.DBObject {
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 {
return resources.DATA
}

View File

@ -46,6 +46,16 @@ func (dma *Datacenter) Deserialize(j map[string]interface{}) utils.DBObject {
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 {
return resources.DATACENTER
}

View File

@ -40,6 +40,16 @@ func (dma *Processing) Deserialize(j map[string]interface{}) utils.DBObject {
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 {
return resources.PROCESSING
}

View File

@ -44,14 +44,14 @@ type Resource interface {
}
type AbstractResource struct {
Uuid string `json:"uuid" required:"true" bson:"uuid"`
Name string `json:"name" required:"true" bson:"name"`
ShortDescription string `json:"short_description" required:"true" bson:"short_description"`
Uuid string `json:"uuid" required:"true" bson:"uuid" validate:"required"`
Name string `json:"name" required:"true" bson:"name" validate:"required"`
ShortDescription string `json:"short_description" required:"true" bson:"short_description" validate:"required"`
Description string `json:"description,omitempty" bson:"description"`
Logo string `json:"logo" required:"true" bson:"logo"`
Owner string `json:"owner" required:"true" bson:"owner"`
Logo string `json:"logo" required:"true" bson:"logo" validate:"required"`
Owner string `json:"owner" required:"true" bson:"owner" validate:"required"`
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 {

View File

@ -33,6 +33,16 @@ func (dma *Storage) Deserialize(j map[string]interface{}) utils.DBObject {
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 {
data := &StorageMongoAccessor{}
data.SetLogger(resources.STORAGE)

View File

@ -37,6 +37,16 @@ func (dma *Workflow) Deserialize(j map[string]interface{}) utils.DBObject {
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 {
if _, exists := w.Datacenters[link.Destination.ID]; exists {
return true

View File

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