New oc-share
This commit is contained in:
		| @@ -6,7 +6,6 @@ import ( | ||||
| 	"slices" | ||||
|  | ||||
| 	oclib "cloud.o-forge.io/core/oc-lib" | ||||
| 	"cloud.o-forge.io/core/oc-lib/models/utils" | ||||
| 	"cloud.o-forge.io/core/oc-lib/tools" | ||||
| 	beego "github.com/beego/beego/v2/server/web" | ||||
| ) | ||||
| @@ -16,6 +15,24 @@ type CollaborativeAreaController struct { | ||||
| 	beego.Controller | ||||
| } | ||||
|  | ||||
| var paths = map[tools.DataType]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 	tools.COLLABORATIVE_AREA: { | ||||
| 		tools.DELETE: "/oc/shared/workspace/:id?is_remote=true", | ||||
| 		tools.POST:   "/oc/shared/workspace/?is_remote=true", | ||||
| 	}, | ||||
| 	tools.WORKSPACE: { | ||||
| 		tools.DELETE: "/oc/workspace/:id?is_remote=true", | ||||
| 		tools.POST:   "/oc/workspace/?is_remote=true", | ||||
| 	}, | ||||
| 	tools.WORKFLOW: { | ||||
| 		tools.DELETE: "/oc/workflow/:id?is_remote=true", | ||||
| 		tools.POST:   "/oc/workflow/?is_remote=true", | ||||
| 	}, | ||||
| 	tools.PEER: { | ||||
| 		tools.POST: "/oc/peer", | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| // @Title Search | ||||
| // @Description search shared workspace | ||||
| // @Param	search		path 	string	true		"the word search you want to get" | ||||
| @@ -24,7 +41,7 @@ type CollaborativeAreaController struct { | ||||
| func (o *CollaborativeAreaController) Search() { | ||||
| 	// store and return Id or post with UUID | ||||
| 	search := o.Ctx.Input.Param(":search") | ||||
| 	o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) | ||||
| 	o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(tools.COLLABORATIVE_AREA)) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -36,29 +53,13 @@ func (o *CollaborativeAreaController) Search() { | ||||
| // @router /:id [put] | ||||
| func (o *CollaborativeAreaController) Put() { | ||||
| 	// store and return Id or post with UUID | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	var res map[string]interface{} | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	fmt.Println("UPDATE", res) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), res, id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), res, id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -68,28 +69,11 @@ func (o *CollaborativeAreaController) Put() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router / [post] | ||||
| func (o *CollaborativeAreaController) Post() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	var res map[string]interface{} | ||||
| 	json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) | ||||
|  | ||||
| 	o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), res, caller) | ||||
| 	o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), res, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -98,7 +82,7 @@ func (o *CollaborativeAreaController) Post() { | ||||
| // @Success 200 {shared_workspace} models.shared_workspace | ||||
| // @router / [get] | ||||
| func (o *CollaborativeAreaController) GetAll() { | ||||
| 	o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) | ||||
| 	o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(tools.COLLABORATIVE_AREA)) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -109,7 +93,7 @@ func (o *CollaborativeAreaController) GetAll() { | ||||
| // @router /:id [get] | ||||
| func (o *CollaborativeAreaController) Get() { | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -120,27 +104,11 @@ func (o *CollaborativeAreaController) Get() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/workspace/:id2 [delete] | ||||
| func (o *CollaborativeAreaController) RemoveWorkspace() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	shared := r.ToCollaborativeArea() | ||||
| 	newWorkspace := []string{} | ||||
| 	if slices.Contains(shared.Workspaces, id2) { | ||||
| @@ -151,7 +119,7 @@ func (o *CollaborativeAreaController) RemoveWorkspace() { | ||||
| 		} | ||||
| 		shared.Workspaces = newWorkspace | ||||
| 	} | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -162,27 +130,11 @@ func (o *CollaborativeAreaController) RemoveWorkspace() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/workflow/:id2 [delete] | ||||
| func (o *CollaborativeAreaController) RemoveWorkflow() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	fmt.Println("RemoveWorkflow", r) | ||||
| 	shared := r.ToCollaborativeArea() | ||||
| 	newWorkflows := []string{} | ||||
| @@ -194,7 +146,7 @@ func (o *CollaborativeAreaController) RemoveWorkflow() { | ||||
| 		} | ||||
| 		shared.Workflows = newWorkflows | ||||
| 	} | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -205,27 +157,11 @@ func (o *CollaborativeAreaController) RemoveWorkflow() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/peer/:id2 [delete] | ||||
| func (o *CollaborativeAreaController) RemovePeer() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	shared := r.ToCollaborativeArea() | ||||
| 	newPeers := []string{} | ||||
| 	if shared.CreatorID != id2 { | ||||
| @@ -245,7 +181,7 @@ func (o *CollaborativeAreaController) RemovePeer() { | ||||
| 		} | ||||
| 		shared.Peers = newPeers | ||||
| 	} | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -256,27 +192,11 @@ func (o *CollaborativeAreaController) RemovePeer() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/rule/:id2 [delete] | ||||
| func (o *CollaborativeAreaController) RemoveRule() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	shared := r.ToCollaborativeArea() | ||||
| 	newRules := []string{} | ||||
| 	if shared != nil && slices.Contains(shared.Rules, id2) { | ||||
| @@ -287,7 +207,7 @@ func (o *CollaborativeAreaController) RemoveRule() { | ||||
| 		} | ||||
| 		shared.Rules = newRules | ||||
| 	} | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -298,27 +218,11 @@ func (o *CollaborativeAreaController) RemoveRule() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/workspace/:id2 [post] | ||||
| func (o *CollaborativeAreaController) AddWorkspace() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	if r.Code != 200 { | ||||
| 		o.Data["json"] = r | ||||
| 		o.ServeJSON() | ||||
| @@ -328,7 +232,7 @@ func (o *CollaborativeAreaController) AddWorkspace() { | ||||
| 	if shared != nil && !slices.Contains(shared.Workspaces, id2) { | ||||
| 		shared.Workspaces = append(shared.Workspaces, id2) | ||||
| 	} | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -339,35 +243,16 @@ func (o *CollaborativeAreaController) AddWorkspace() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/workflow/:id2 [post] | ||||
| func (o *CollaborativeAreaController) AddWorkflow() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	fmt.Println("AddWorkflow", id, id2) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	shared := r.ToCollaborativeArea() | ||||
| 	if shared != nil && !slices.Contains(shared.Workflows, id2) { | ||||
| 		shared.Workflows = append(shared.Workflows, id2) | ||||
| 	} | ||||
| 	fmt.Println("AddWorkflow", shared.Workflows) | ||||
|  | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -378,32 +263,16 @@ func (o *CollaborativeAreaController) AddWorkflow() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/peer/:id2 [post] | ||||
| func (o *CollaborativeAreaController) AddPeer() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	shared := r.ToCollaborativeArea() | ||||
| 	if shared != nil && !slices.Contains(shared.Peers, id2) { | ||||
| 		shared.Peers = append(shared.Peers, id2) | ||||
| 	} | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -414,32 +283,16 @@ func (o *CollaborativeAreaController) AddPeer() { | ||||
| // @Success 200 {shared workspace} models.shared_workspace | ||||
| // @router /:id/rule/:id2 [post] | ||||
| func (o *CollaborativeAreaController) AddRule() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	id2 := o.Ctx.Input.Param(":id2") | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id) | ||||
| 	r := oclib.LoadOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id) | ||||
| 	shared := r.ToCollaborativeArea() | ||||
| 	if shared != nil && !slices.Contains(shared.Rules, id2) { | ||||
| 		shared.Rules = append(shared.Rules, id2) | ||||
| 	} | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), shared.Serialize(), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|  | ||||
| @@ -449,25 +302,9 @@ func (o *CollaborativeAreaController) AddRule() { | ||||
| // @Success 200 {shared workspace} delete success! | ||||
| // @router /:id [delete] | ||||
| func (o *CollaborativeAreaController) Delete() { | ||||
| 	var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers | ||||
| 		utils.COLLABORATIVE_AREA.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(utils.COLLABORATIVE_AREA)) + "/oc/shared/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKSPACE.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/", | ||||
| 		}, | ||||
| 		utils.WORKFLOW.String(): { | ||||
| 			tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id", | ||||
| 			tools.POST:   oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/", | ||||
| 		}, | ||||
| 		utils.PEER.String(): { | ||||
| 			tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", | ||||
| 		}, | ||||
| 	} | ||||
| 	id := o.Ctx.Input.Param(":id") | ||||
| 	caller := tools.NewHTTPCaller(paths) // caller used to send to peers | ||||
| 	o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(utils.COLLABORATIVE_AREA), id, caller) | ||||
| 	caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true) | ||||
| 	o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(tools.COLLABORATIVE_AREA), id, caller) | ||||
| 	o.ServeJSON() | ||||
| } | ||||
|   | ||||
							
								
								
									
										6
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								go.mod
									
									
									
									
									
								
							| @@ -5,8 +5,8 @@ go 1.22.0 | ||||
| toolchain go1.22.4 | ||||
|  | ||||
| require ( | ||||
| 	cloud.o-forge.io/core/oc-lib v0.0.0-20240927112324-cdf513c2c454 | ||||
| 	github.com/beego/beego/v2 v2.3.0 | ||||
| 	cloud.o-forge.io/core/oc-lib v0.0.0-20241002120813-a09a04e1a71e | ||||
| 	github.com/beego/beego/v2 v2.3.1 | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| @@ -46,7 +46,7 @@ require ( | ||||
| 	github.com/xdg-go/scram v1.1.2 // indirect | ||||
| 	github.com/xdg-go/stringprep v1.0.4 // indirect | ||||
| 	github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect | ||||
| 	go.mongodb.org/mongo-driver v1.17.0 // indirect | ||||
| 	go.mongodb.org/mongo-driver v1.17.1 // indirect | ||||
| 	golang.org/x/crypto v0.27.0 // indirect | ||||
| 	golang.org/x/net v0.29.0 // indirect | ||||
| 	golang.org/x/sync v0.8.0 // indirect | ||||
|   | ||||
							
								
								
									
										10
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								go.sum
									
									
									
									
									
								
							| @@ -2,9 +2,17 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240904135449-4f0ab6a3760f h1:v9mw3uNg/DJsw | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20240904135449-4f0ab6a3760f/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20240927112324-cdf513c2c454 h1:F5/oBMypnb6Mdvcf6N8y8v/DgfglPQ6VsQUY7hjC2zA= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20240927112324-cdf513c2c454/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20241002084552-3c1a84011ecc h1:1R4stJxXDMQ6joJZl9gQ2TUGW6S2jct2lhHUubPChs0= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20241002084552-3c1a84011ecc/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20241002102322-c309d9762350 h1:ybK3Qz1inr9xgrJwbHjSOTNaFIyX+AVINyzqcsvpATY= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20241002102322-c309d9762350/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20241002120813-a09a04e1a71e h1:77QHk5JSf0q13B/Ai3xjcsGSS7nX+9AfxcsYz5oDo/A= | ||||
| cloud.o-forge.io/core/oc-lib v0.0.0-20241002120813-a09a04e1a71e/go.mod h1:t+zpCTVKVdHH/BImwtMYY2QIWLMXKgY4n/JhFm3Vpu8= | ||||
| github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||||
| github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I= | ||||
| github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo= | ||||
| github.com/beego/beego/v2 v2.3.1 h1:7MUKMpJYzOXtCUsTEoXOxsDV/UcHw6CPbaWMlthVNsc= | ||||
| github.com/beego/beego/v2 v2.3.1/go.mod h1:5cqHsOHJIxkq44tBpRvtDe59GuVRVv/9/tyVDxd5ce4= | ||||
| github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= | ||||
| github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= | ||||
| github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= | ||||
| @@ -134,6 +142,8 @@ go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4 | ||||
| go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= | ||||
| go.mongodb.org/mongo-driver v1.17.0 h1:Hp4q2MCjvY19ViwimTs00wHi7G4yzxh4/2+nTx8r40k= | ||||
| go.mongodb.org/mongo-driver v1.17.0/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= | ||||
| go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM= | ||||
| go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||||
| golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||||
|   | ||||
							
								
								
									
										11
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								main.go
									
									
									
									
									
								
							| @@ -22,22 +22,17 @@ func main() { | ||||
| 		o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), | ||||
| 		o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), | ||||
| 		"", | ||||
| 		o.GetStringDefault("lokiurl", ""), | ||||
| 		o.GetStringDefault("loglevel", "info"), | ||||
| 		o.GetStringDefault("LOKI_URL", ""), | ||||
| 		o.GetStringDefault("LOG_LEVEL", "info"), | ||||
| 	) | ||||
|  | ||||
| 	/* PATHS ARE REFERENCE FOR INNER SERVICE OF DISTANT OC | ||||
| 	 * PATHS ARE USED TO CALL OTHER OC SERVICES | ||||
| 	 * NAMES ARE CANONICAL NAMES OF THE SERVICES | ||||
| 	 */ | ||||
| 	oclib.AddPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), o.GetStringDefault("SHARED_WORKSPACE_URL", ":8091")) | ||||
| 	oclib.AddPath(oclib.LibDataEnum(oclib.WORKSPACE), o.GetStringDefault("WORKSPACE_URL", ":8089")) | ||||
| 	oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW), o.GetStringDefault("WORKFLOW_URL", ":8088")) | ||||
| 	oclib.AddPath(oclib.LibDataEnum(oclib.PEER), o.GetStringDefault("WORKFLOW_URL", ":8093")) | ||||
|  | ||||
| 	// Beego init | ||||
| 	beego.BConfig.AppName = appname | ||||
| 	beego.BConfig.Listen.HTTPPort = o.GetIntDefault("port", 8080) | ||||
| 	beego.BConfig.Listen.HTTPPort = 8080 | ||||
| 	beego.BConfig.WebConfig.DirectoryIndex = true | ||||
| 	beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user