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"