OC-SHARED -> add route

This commit is contained in:
mr 2024-08-26 13:45:50 +02:00
parent a5a86f44c5
commit b94f6c4ddf
8 changed files with 273 additions and 2 deletions

View File

@ -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"

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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"))

BIN
oc-shared

Binary file not shown.

View File

@ -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",

View File

@ -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": [

View File

@ -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
<br>
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
<br>
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
<br>
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: