From 53811538c01017e9d8bd043698e03beda2b5225c Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 22 Jul 2024 09:03:57 +0200 Subject: [PATCH] config pb --- entrypoint.go | 43 +++++++++-------------- models/resources/data/data.go | 4 +-- models/resources/datacenter/datacenter.go | 3 +- models/resources/resource.go | 10 +++--- models/resources/workflow/graph/graph.go | 34 +++++++++--------- 5 files changed, 42 insertions(+), 52 deletions(-) diff --git a/entrypoint.go b/entrypoint.go index 870aebd..3a19549 100644 --- a/entrypoint.go +++ b/entrypoint.go @@ -4,6 +4,7 @@ import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" "cloud.o-forge.io/core/oc-lib/logs" "cloud.o-forge.io/core/oc-lib/models" + "cloud.o-forge.io/core/oc-lib/models/resources" "cloud.o-forge.io/core/oc-lib/models/utils" "github.com/rs/zerolog" ) @@ -11,13 +12,12 @@ import ( type LibDataEnum int const ( - INVALID LibDataEnum = iota - DATA_RESOURCE = utils.DATA_RESOURCE - PROCESSING_RESOURCE = utils.PROCESSING_RESOURCE - STORAGE_RESOURCE = utils.STORAGE_RESOURCE - DATACENTER_RESOURCE = utils.DATACENTER_RESOURCE - WORKFLOW_RESOURCE = utils.WORKFLOW_RESOURCE - WORKFLOW = utils.WORKFLOW + INVALID LibDataEnum = iota + DATA = resources.DATA + PROCESSING = resources.PROCESSING + STORAGE = resources.STORAGE + DATACENTER = resources.DATACENTER + WORKFLOW = resources.WORKFLOW ) func (d LibDataEnum) EnumIndex() int { @@ -25,9 +25,8 @@ func (d LibDataEnum) EnumIndex() int { } type LibData struct { - DataResource utils.DBObject `bson:"data" json:"data"` - Code int `bson:"code" json:"code"` - Err string `bson:"error" json:"error"` + Data utils.DBObject `bson:"data" json:"data"` + Err error `bson:"error" json:"error"` } func Init(appName string) { @@ -41,30 +40,22 @@ func GetLogger() zerolog.Logger { } func LoadOne(collection LibDataEnum, id string) LibData { - d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id) - return LibData{DataResource: d, Code: code, Err: err.Error()} + d, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id) + return LibData{Data: d, Err: err} } func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData { - model := models.Model(collection.EnumIndex()) - set = model.Deserialize(set).Serialize() - d, code, err := model.GetAccessor().UpdateOne(set, id) - return LibData{DataResource: d, Code: code, Err: err.Error()} + d, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id) + return LibData{Data: d, Err: err} } func DeleteOne(collection LibDataEnum, id string) LibData { - d, code, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id) - return LibData{DataResource: d, Code: code, Err: err.Error()} -} - -func CopyOne(collection LibDataEnum, object map[string]interface{}) LibData { - model := models.Model(collection.EnumIndex()) - d, code, err := model.GetAccessor().CopyOne(model.Deserialize(object)) - return LibData{DataResource: d, Code: code, Err: err.Error()} + d, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id) + return LibData{Data: d, Err: err} } func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData { model := models.Model(collection.EnumIndex()) - d, code, err := model.GetAccessor().StoreOne(model.Deserialize(object)) - return LibData{DataResource: d, Code: code, Err: err.Error()} + d, err := model.GetAccessor().StoreOne(model.Deserialize(object)) + return LibData{Data: d, Err: err} } diff --git a/models/resources/data/data.go b/models/resources/data/data.go index 9ff6dc4..7234b96 100644 --- a/models/resources/data/data.go +++ b/models/resources/data/data.go @@ -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" required:"true" bson:"datatype"` - Example string `json:"example" bson:"example" required:"true" validate:"required" description:"base64 encoded data"` + DataType string `json:"datatype" bson:"datatype"` + Example string `json:"example" bson:"example" description:"base64 encoded data"` } func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject { diff --git a/models/resources/datacenter/datacenter.go b/models/resources/datacenter/datacenter.go index 3c0ccbb..30f7c33 100644 --- a/models/resources/datacenter/datacenter.go +++ b/models/resources/datacenter/datacenter.go @@ -9,8 +9,7 @@ import ( type DatacenterResource struct { resources.AbstractResource - Owner string `bson:"owner" json:"owner" required:"true"` - BookingPrice int `bson:"booking_price" json:"booking_price" required:"true"` + BookingPrice int `bson:"booking_price" json:"booking_price"` CPU DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"` RAM DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"` diff --git a/models/resources/resource.go b/models/resources/resource.go index a173b81..321be52 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -18,12 +18,12 @@ type Resource interface { type AbstractResource struct { utils.AbstractObject - ShortDescription string `json:"short_description" required:"true" bson:"short_description" validate:"required"` + ShortDescription string `json:"short_description" bson:"short_description" validate:"required"` Description string `json:"description,omitempty" bson:"description"` - 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" validate:"required"` + Logo string `json:"logo" bson:"logo" validate:"required"` + Owner string `json:"owner" bson:"owner" validate:"required"` + OwnerLogo string `json:"owner_logo" bson:"owner_logo"` + SourceUrl string `json:"source_url" bson:"source_url" validate:"required"` } func (dma *AbstractResource) ObjDeserialize(j map[string]interface{}) *AbstractResource { diff --git a/models/resources/workflow/graph/graph.go b/models/resources/workflow/graph/graph.go index 8435cbf..ce868e8 100644 --- a/models/resources/workflow/graph/graph.go +++ b/models/resources/workflow/graph/graph.go @@ -1,41 +1,41 @@ package graph type Graph struct { - Items map[string]GraphItem `bson:"items" json:"items" default:"{}" required:"true"` - Links []GraphLink `bson:"links" json:"links" default:"{}" required:"true"` + Items map[string]GraphItem `bson:"items" json:"items" default:"{}" validate:"required"` + Links []GraphLink `bson:"links" json:"links" default:"{}" validate:"required"` } type GraphItem struct { - ID string `bson:"ID" json:"ID" required:"true"` - Width float64 `bson:"width" json:"width" required:"true"` - Height float64 `bson:"height" json:"height" required:"true"` - Position Position `bson:"position" json:"position" required:"true"` - ResourceID string `bson:"resource_id" json:"resource_id" required:"true"` + ID string `bson:"ID" json:"ID" validate:"required"` + Width float64 `bson:"width" json:"width" validate:"required"` + Height float64 `bson:"height" json:"height" validate:"required"` + Position Position `bson:"position" json:"position" validate:"required"` + ResourceID string `bson:"resource_id" json:"resource_id" validate:"required"` } type GraphLink struct { - Source Position `bson:"source" json:"source" required:"true"` - Destination Position `bson:"destination" json:"destination" required:"true"` - Style GraphLinkStyle `bson:"style" json:"style" required:"true"` + Source Position `bson:"source" json:"source" validate:"required"` + Destination Position `bson:"destination" json:"destination" validate:"required"` + Style GraphLinkStyle `bson:"style" json:"style" validate:"required"` } type GraphLinkStyle struct { - Color int64 `bson:"color" json:"color" required:"true"` - Stroke float64 `bson:"stroke" json:"stroke" required:"true"` + Color int64 `bson:"color" json:"color" validate:"required"` + Stroke float64 `bson:"stroke" json:"stroke" validate:"required"` Tension float64 `bson:"tension" json:"tension"` HeadRadius float64 `bson:"head_radius" json:"head_radius"` DashWidth float64 `bson:"dash_width" json:"dash_width"` DashSpace float64 `bson:"dash_space" json:"dash_space"` EndArrow Position `bson:"end_arrow" json:"end_arrow"` StartArrow Position `bson:"start_arrow" json:"start_arrow"` - ArrowStyle int64 `bson:"arrow_style" json:"arrow_style" required:"true"` - ArrowDirection int64 `bson:"arrow_direction" json:"arrow_direction" required:"true"` + ArrowStyle int64 `bson:"arrow_style" json:"arrow_style" validate:"required"` + ArrowDirection int64 `bson:"arrow_direction" json:"arrow_direction" validate:"required"` StartArrowWidth float64 `bson:"start_arrow_style" json:"start_arrow_style"` EndArrowWidth float64 `bson:"end_arrow_style" json:"end_arrow_style"` } type Position struct { - ID string `json:"ID" required:"true"` - X float64 `json:"x" required:"true"` - Y float64 `json:"y" required:"true"` + ID string `json:"ID" validate:"required"` + X float64 `json:"x" validate:"required"` + Y float64 `json:"y" validate:"required"` }