update fails

This commit is contained in:
mr 2024-07-22 15:18:59 +02:00
parent 7a49f6b957
commit 4a90d3379c
6 changed files with 34 additions and 23 deletions

View File

@ -42,32 +42,43 @@ func GetLogger() zerolog.Logger {
func LoadOne(collection LibDataEnum, id string) LibData {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
if err != nil { return LibData{Data: d, Code: code, Err: err.Error()} }
return LibData{Data: d, Code: code }
if err != nil {
return LibData{Data: d, Code: code, Err: err.Error()}
}
return LibData{Data: d, Code: code}
}
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id)
if err != nil { return LibData{Data: d, Code: code, Err: err.Error()} }
return LibData{Data: d, Code: code }
model := models.Model(collection.EnumIndex())
d, code, err := model.GetAccessor().UpdateOne(model.Deserialize(set).Serialize(), id)
if err != nil {
return LibData{Data: d, Code: code, Err: err.Error()}
}
return LibData{Data: d, Code: code}
}
func DeleteOne(collection LibDataEnum, id string) LibData {
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id)
if err != nil { return LibData{Data: d, Code: code, Err: err.Error()} }
return LibData{Data: d, Code: code }
if err != nil {
return LibData{Data: d, Code: code, Err: err.Error()}
}
return LibData{Data: d, Code: code}
}
func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData {
model := models.Model(collection.EnumIndex())
d, code, err := model.GetAccessor().StoreOne(model.Deserialize(object))
if err != nil { return LibData{Data: d, Code: code, Err: err.Error()} }
return LibData{Data: d, Code: code }
if err != nil {
return LibData{Data: d, Code: code, Err: err.Error()}
}
return LibData{Data: d, Code: code}
}
func CopyOne(collection LibDataEnum, object map[string]interface{}) LibData {
model := models.Model(collection.EnumIndex())
d, code, err := model.GetAccessor().CopyOne(model.Deserialize(object))
if err != nil { return LibData{Data: d, Code: code, Err: err.Error()} }
return LibData{Data: d, Code: code }
if err != nil {
return LibData{Data: d, Code: code, Err: err.Error()}
}
return LibData{Data: d, Code: code}
}

View File

@ -10,8 +10,8 @@ import (
type DataResource struct {
resources.AbstractResource
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
DataType string `json:"datatype" bson:"datatype"`
Example string `json:"example" bson:"example" description:"base64 encoded data"`
DataType string `json:"datatype,omitempty" bson:"datatype"`
Example string `json:"example,omitempty" bson:"example" description:"base64 encoded data"`
}
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {

View File

@ -9,11 +9,11 @@ import (
type DatacenterResource struct {
resources.AbstractResource
BookingPrice int `bson:"booking_price" json:"booking_price"`
BookingPrice int `bson:"booking_price" json:"booking_price,omitempty"`
CPU DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"`
RAM DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"`
GPU []DatacenterGpuModel `bson:"gpu,omitempty" json:"gpu,omitempty"`
CPU *DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"`
RAM *DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"`
GPU []DatacenterGpuModel `bson:"gpu,omitempty" json:"gpu,omitempty"`
}
type DatacenterCpuModel struct {

View File

@ -8,15 +8,15 @@ import (
)
type URL struct {
Protocol string `bson:"protocol" json:"protocol"`
Path string `bson:"path" json:"path"`
Protocol string `bson:"protocol,omitempty" json:"protocol"`
Path string `bson:"path,omitempty" json:"path"`
}
type StorageResource struct {
resources.AbstractResource
Capacity uint `bson:"capacity,omitempty" json:"capacity,omitempty"`
Url URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
Url *URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"`
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"`

View File

@ -10,7 +10,7 @@ import (
)
func TestStoreOneStorage(t *testing.T) {
s := StorageResource{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"},
s := StorageResource{Capacity: 123, Url: &URL{Protocol: "http", Path: "azerty.fr"},
AbstractResource: resources.AbstractResource{
AbstractObject: utils.AbstractObject{Name: "testData"},
Description: "Lorem Ipsum",
@ -28,7 +28,7 @@ func TestStoreOneStorage(t *testing.T) {
}
func TestLoadOneStorage(t *testing.T) {
s := StorageResource{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"},
s := StorageResource{Capacity: 123, Url: &URL{Protocol: "http", Path: "azerty.fr"},
AbstractResource: resources.AbstractResource{
AbstractObject: utils.AbstractObject{Name: "testData"},
Description: "Lorem Ipsum",

View File

@ -19,7 +19,7 @@ type AbstractWorkflow struct {
ProcessingResource map[string]processing.ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
Datacenters map[string]datacenter.DatacenterResource `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
Workflows map[string]WorkflowResource `bson:"workflows,omitempty" json:"workflows,omitempty"`
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
}
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) bool {