diff --git a/controllers/shared_workspace.go b/controllers/shared_workspace.go index 539ed8a..55470ef 100644 --- a/controllers/shared_workspace.go +++ b/controllers/shared_workspace.go @@ -1,6 +1,7 @@ package controllers import ( + "slices" "encoding/json" oclib "cloud.o-forge.io/core/oc-lib" @@ -109,6 +110,82 @@ func (o *SharedWorkspaceController) Get() { o.ServeJSON() } +// @Title Add Workspace +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/workspace/:id2 [post] +func (o *SharedWorkspaceController) AddWorkspace() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + if !slices.Contains(shared.Workspaces, id) { + shared.Workspaces = append(shared.Workspaces, id2) + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + +// @Title Add Workflow +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/workflow/:id2 [post] +func (o *SharedWorkspaceController) AddWorkflow() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + if !slices.Contains(shared.Workflows, id) { + shared.Workflows = append(shared.Workflows, id2) + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + +// @Title Add Peer +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/peer/:id2 [post] +func (o *SharedWorkspaceController) AddPeer() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + if !slices.Contains(shared.Peers, id) { + shared.Peers = append(shared.Peers, id2) + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + +// @Title Add Peer +// @Description find shared workspace by id +// @Param id path string true "the id you want to get" +// @Param id2 path string true "the id you want to add" +// @Success 200 {shared workspace} models.shared_workspace +// @router /:id/peer/:id2 [post] +func (o *SharedWorkspaceController) AddRule() { + var res map[string]interface{} + id := o.Ctx.Input.Param(":id") + id2 := o.Ctx.Input.Param(":id2") + r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + shared := r.ToSharedWorkspace() + if !slices.Contains(shared.Rules, id) { + shared.Rules = append(shared.Rules, id2) + } + o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil) + o.ServeJSON() +} + // @Title Delete // @Description delete the shared workspace // @Param id path string true "The id you want to delete" diff --git a/go.mod b/go.mod index 2e5d581..525fccb 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( ) require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b // indirect + cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/beego/bee/v2 v2.1.0 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index 9581b8b..21ce4fd 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,8 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8 h1:y4hngS1bedPKY cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b h1:A7NBwTXoHTg/oDbnxnnSdiT85kZY4VvhcbUeb3q7Irk= cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71 h1:GodGMXVFgSdd5R1FoUjFAloOS+zOd3j66Wa+jcEPa4c= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/main.go b/main.go index 714b7e3..a542c9d 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ func main() { o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), "", ) - oclib.Init("oc-shared") + oclib.Init("oc-shared", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8091")) 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")) diff --git a/oc-shared b/oc-shared index 99f0b30..4a11b67 100755 Binary files a/oc-shared and b/oc-shared differ diff --git a/routers/commentsRouter.go b/routers/commentsRouter.go index 3f66cfc..84d03b9 100644 --- a/routers/commentsRouter.go +++ b/routers/commentsRouter.go @@ -106,6 +106,42 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "AddPeer", + Router: `/:id/peer/:id2`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "AddRule", + Router: `/:id/peer/:id2`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "AddWorkflow", + Router: `/:id/workflow/:id2`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], + beego.ControllerComments{ + Method: "AddWorkspace", + Router: `/:id/workspace/:id2`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"] = append(beego.GlobalControllerRouter["oc-shared/controllers:SharedWorkspaceController"], beego.ControllerComments{ Method: "Search", diff --git a/swagger/swagger.json b/swagger/swagger.json index 561766a..3f9127f 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -283,6 +283,96 @@ } } }, + "/shared/workspace/{id}/peer/{id2}": { + "post": { + "tags": [ + "shared/workspace" + ], + "description": "find shared workspace by id\n\u003cbr\u003e", + "operationId": "SharedWorkspaceController.Add Peer", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "the id you want to get", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "id2", + "description": "the id you want to add", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "{shared workspace} models.shared_workspace" + } + } + } + }, + "/shared/workspace/{id}/workflow/{id2}": { + "post": { + "tags": [ + "shared/workspace" + ], + "description": "find shared workspace by id\n\u003cbr\u003e", + "operationId": "SharedWorkspaceController.Add Workflow", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "the id you want to get", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "id2", + "description": "the id you want to add", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "{shared workspace} models.shared_workspace" + } + } + } + }, + "/shared/workspace/{id}/workspace/{id2}": { + "post": { + "tags": [ + "shared/workspace" + ], + "description": "find shared workspace by id\n\u003cbr\u003e", + "operationId": "SharedWorkspaceController.Add Workspace", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "the id you want to get", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "id2", + "description": "the id you want to add", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "{shared workspace} models.shared_workspace" + } + } + } + }, "/version/": { "get": { "tags": [ diff --git a/swagger/swagger.yml b/swagger/swagger.yml index 74a8474..334094c 100644 --- a/swagger/swagger.yml +++ b/swagger/swagger.yml @@ -95,6 +95,72 @@ paths: responses: "200": description: '{shared workspace} delete success!' + /shared/workspace/{id}/peer/{id2}: + post: + tags: + - shared/workspace + description: |- + find shared workspace by id +
+ operationId: SharedWorkspaceController.Add Peer + parameters: + - in: path + name: id + description: the id you want to get + required: true + type: string + - in: path + name: id2 + description: the id you want to add + required: true + type: string + responses: + "200": + description: '{shared workspace} models.shared_workspace' + /shared/workspace/{id}/workflow/{id2}: + post: + tags: + - shared/workspace + description: |- + find shared workspace by id +
+ operationId: SharedWorkspaceController.Add Workflow + parameters: + - in: path + name: id + description: the id you want to get + required: true + type: string + - in: path + name: id2 + description: the id you want to add + required: true + type: string + responses: + "200": + description: '{shared workspace} models.shared_workspace' + /shared/workspace/{id}/workspace/{id2}: + post: + tags: + - shared/workspace + description: |- + find shared workspace by id +
+ operationId: SharedWorkspaceController.Add Workspace + parameters: + - in: path + name: id + description: the id you want to get + required: true + type: string + - in: path + name: id2 + description: the id you want to add + required: true + type: string + responses: + "200": + description: '{shared workspace} models.shared_workspace' /shared/workspace/rule/: get: tags: