deserialize

This commit is contained in:
mr 2024-07-22 11:50:14 +02:00
parent a5741d5831
commit 6696b0faac
8 changed files with 1 additions and 78 deletions

View File

@ -20,7 +20,6 @@ func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -31,7 +30,6 @@ func (dma *DataResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -9,7 +9,7 @@ import (
type DatacenterResource struct {
resources.AbstractResource
BookingPrice int `bson:"booking_price" json:"booking_price"`
BookingPrice int `bson:"booking_price" json:"booking_price"`
CPU DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"`
RAM DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"`
@ -42,7 +42,6 @@ func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObj
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -53,7 +52,6 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -37,7 +37,6 @@ func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObj
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -48,7 +47,6 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -1,8 +1,6 @@
package resources
import (
"encoding/json"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
@ -26,27 +24,6 @@ type AbstractResource struct {
SourceUrl string `json:"source_url" bson:"source_url" validate:"required"`
}
func (dma *AbstractResource) ObjDeserialize(j map[string]interface{}) *AbstractResource {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractObject.ObjDeserialize(j)
return dma
}
func (dma *AbstractResource) ObjSerialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractObject.ObjSerialize()
return m
}
func (r *AbstractResource) GetID() string {
return r.UUID
}

View File

@ -30,7 +30,6 @@ func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -41,7 +40,6 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -22,25 +22,6 @@ type AbstractWorkflow struct {
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
}
func (w *AbstractWorkflow) ObjDeserialize(j map[string]interface{}) *AbstractWorkflow {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, w)
return w
}
func (w *AbstractWorkflow) ObjSerialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(w)
if err != nil {
return nil
}
json.Unmarshal(b, w)
return m
}
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) bool {
if _, exists := w.Datacenters[link.Destination.ID]; exists {
return true
@ -69,7 +50,6 @@ func (dma *WorkflowResource) Deserialize(j map[string]interface{}) utils.DBObjec
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjDeserialize(j)
return dma
}
@ -80,6 +60,5 @@ func (dma *WorkflowResource) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractResource.ObjSerialize()
return m
}

View File

@ -1,8 +1,6 @@
package utils
import (
"encoding/json"
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/logs"
"github.com/go-playground/validator/v10"
@ -21,25 +19,6 @@ func (ao *AbstractObject) GetID() string {
return ao.UUID
}
func (dma *AbstractObject) ObjDeserialize(j map[string]interface{}) *AbstractObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
func (dma *AbstractObject) ObjSerialize() 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 (r *AbstractObject) GenerateID() {
r.UUID = uuid.New().String()
}

View File

@ -29,8 +29,6 @@ func (dma *Workflow) Deserialize(j map[string]interface{}) utils.DBObject {
return nil
}
json.Unmarshal(b, dma)
//dma.AbstractObject.ObjDeserialize(j)
//dma.AbstractWorkflow.ObjDeserialize(j)
fmt.Println(j, dma)
return dma
}
@ -42,7 +40,5 @@ func (dma *Workflow) Serialize() map[string]interface{} {
return nil
}
json.Unmarshal(b, dma)
dma.AbstractObject.ObjSerialize()
dma.AbstractWorkflow.ObjSerialize()
return m
}