oc-shared/controllers/shared_workspace.go

474 lines
19 KiB
Go
Raw Permalink Normal View History

2024-08-12 14:12:51 +02:00
package controllers
import (
"encoding/json"
2024-08-27 15:39:08 +02:00
"fmt"
"slices"
2024-08-12 14:12:51 +02:00
oclib "cloud.o-forge.io/core/oc-lib"
2024-08-13 11:42:09 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
2024-08-12 14:12:51 +02:00
beego "github.com/beego/beego/v2/server/web"
)
// Operations about workspace
type SharedWorkspaceController struct {
beego.Controller
}
// @Title Search
// @Description search shared workspace
// @Param search path string true "the word search you want to get"
// @Success 200 {shared workspace} models.shared_workspace
// @router /search/:search [get]
func (o *SharedWorkspaceController) Search() {
// store and return Id or post with UUID
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.SHARED_WORKSPACE))
o.ServeJSON()
}
// @Title Update
// @Description create shared workspaces
// @Param id path string true "the shared workspace id you want to get"
// @Param body body models.workspace true "The shared workspace content"
// @Success 200 {shared workspace} models.shared_workspace
// @router /:id [put]
func (o *SharedWorkspaceController) Put() {
// store and return Id or post with UUID
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers
2024-08-13 11:42:09 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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/",
},
2024-08-21 16:17:43 +02:00
utils.PEER.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
},
2024-08-13 11:42:09 +02:00
}
2024-08-12 14:12:51 +02:00
var res map[string]interface{}
id := o.Ctx.Input.Param(":id")
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-27 15:39:08 +02:00
fmt.Println("UPDATE", res)
2024-08-13 11:42:09 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, caller)
2024-08-12 14:12:51 +02:00
o.ServeJSON()
}
// @Title Create
// @Description create shared workspace
// @Param data body json true "body for data content (Json format)"
// @Success 200 {shared workspace} models.shared_workspace
// @router / [post]
func (o *SharedWorkspaceController) Post() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-13 11:42:09 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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/",
},
2024-08-21 16:17:43 +02:00
utils.PEER.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
},
2024-08-13 11:42:09 +02:00
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-12 14:12:51 +02:00
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
2024-08-27 15:39:08 +02:00
2024-08-13 11:42:09 +02:00
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, caller)
2024-08-12 14:12:51 +02:00
o.ServeJSON()
}
// @Title GetAll
// @Description find shared workspace by id
// @Success 200 {shared_workspace} models.shared_workspace
// @router / [get]
func (o *SharedWorkspaceController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.SHARED_WORKSPACE))
o.ServeJSON()
}
// @Title Get
// @Description find shared workspace by id
// @Param id path string true "the id you want to get"
// @Success 200 {shared workspace} models.shared_workspace
// @router /:id [get]
func (o *SharedWorkspaceController) Get() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
o.ServeJSON()
}
2024-08-26 13:45:50 +02:00
// @Title Add Workspace
// @Description find shared workspace by id
2024-08-26 15:39:56 +02:00
// @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 [delete]
func (o *SharedWorkspaceController) RemoveWorkspace() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 15:39:56 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
shared := r.ToSharedWorkspace()
newWorkspace := []string{}
2024-08-30 10:35:12 +02:00
if slices.Contains(shared.Workspaces, id2) {
2024-08-26 15:39:56 +02:00
for _, w := range shared.Workspaces {
if w != id2 {
newWorkspace = append(newWorkspace, w)
}
}
shared.Workspaces = newWorkspace
}
2024-08-27 15:39:08 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 15:39:56 +02:00
o.ServeJSON()
}
// @Title Remove 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 [delete]
func (o *SharedWorkspaceController) RemoveWorkflow() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 15:39:56 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
2024-08-30 10:35:12 +02:00
fmt.Println("RemoveWorkflow", r)
2024-08-26 15:39:56 +02:00
shared := r.ToSharedWorkspace()
newWorkflows := []string{}
2024-08-30 10:35:12 +02:00
if slices.Contains(shared.Workflows, id2) {
2024-08-26 15:39:56 +02:00
for _, w := range shared.Workflows {
if w != id2 {
newWorkflows = append(newWorkflows, w)
}
}
shared.Workflows = newWorkflows
}
2024-08-27 15:39:08 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 15:39:56 +02:00
o.ServeJSON()
}
// @Title Remove 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 [delete]
func (o *SharedWorkspaceController) RemovePeer() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 15:39:56 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
shared := r.ToSharedWorkspace()
newPeers := []string{}
if shared.CreatorID != id2 {
o.Data["json"] = map[string]interface{}{
2024-08-27 15:39:08 +02:00
"data": nil,
"code": 409,
2024-08-26 15:39:56 +02:00
"error": "You can't remove the creator from the shared workspace",
}
o.ServeJSON()
return
}
if slices.Contains(shared.Peers, id) && shared.CreatorID != id2 {
for _, peer := range shared.Peers {
if peer != id2 {
newPeers = append(newPeers, peer)
}
}
shared.Peers = newPeers
}
2024-08-27 15:39:08 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 15:39:56 +02:00
o.ServeJSON()
}
// @Title Remove Rule
// @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/rule/:id2 [delete]
func (o *SharedWorkspaceController) RemoveRule() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 15:39:56 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
shared := r.ToSharedWorkspace()
newRules := []string{}
2024-08-30 10:35:12 +02:00
if shared != nil && slices.Contains(shared.Rules, id2) {
2024-08-26 15:39:56 +02:00
for _, rule := range shared.Rules {
if rule != id2 {
newRules = append(newRules, rule)
}
}
shared.Rules = newRules
}
2024-08-27 15:39:08 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 15:39:56 +02:00
o.ServeJSON()
}
// @Title Add Workspace
// @Description find shared workspace by id
2024-08-26 13:45:50 +02:00
// @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() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 13:45:50 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
2024-08-27 15:39:08 +02:00
if r.Code != 200 {
o.Data["json"] = r
o.ServeJSON()
return
}
2024-08-26 13:45:50 +02:00
shared := r.ToSharedWorkspace()
2024-08-30 10:35:12 +02:00
if shared != nil && !slices.Contains(shared.Workspaces, id2) {
2024-08-26 13:45:50 +02:00
shared.Workspaces = append(shared.Workspaces, id2)
}
2024-08-27 15:39:08 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 13:45:50 +02:00
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() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 13:45:50 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
2024-08-27 15:39:08 +02:00
fmt.Println("AddWorkflow", id, id2)
2024-08-26 13:45:50 +02:00
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
shared := r.ToSharedWorkspace()
2024-08-30 10:35:12 +02:00
if shared != nil && !slices.Contains(shared.Workflows, id2) {
2024-08-26 13:45:50 +02:00
shared.Workflows = append(shared.Workflows, id2)
}
2024-08-27 15:39:08 +02:00
fmt.Println("AddWorkflow", shared.Workflows)
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 13:45:50 +02:00
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() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 13:45:50 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
shared := r.ToSharedWorkspace()
2024-08-30 10:35:12 +02:00
if shared != nil && !slices.Contains(shared.Peers, id2) {
2024-08-26 13:45:50 +02:00
shared.Peers = append(shared.Peers, id2)
}
2024-08-27 15:39:08 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 13:45:50 +02:00
o.ServeJSON()
}
2024-08-26 13:50:11 +02:00
// @Title Add Rule
2024-08-26 13:45:50 +02:00
// @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
2024-08-26 13:50:11 +02:00
// @router /:id/rule/:id2 [post]
2024-08-26 13:45:50 +02:00
func (o *SharedWorkspaceController) AddRule() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers
2024-08-27 15:39:08 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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",
},
}
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-26 13:45:50 +02:00
id := o.Ctx.Input.Param(":id")
id2 := o.Ctx.Input.Param(":id2")
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
shared := r.ToSharedWorkspace()
2024-08-30 10:35:12 +02:00
if shared != nil && !slices.Contains(shared.Rules, id2) {
2024-08-26 13:45:50 +02:00
shared.Rules = append(shared.Rules, id2)
}
2024-08-27 15:39:08 +02:00
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
2024-08-26 13:45:50 +02:00
o.ServeJSON()
}
2024-08-12 14:12:51 +02:00
// @Title Delete
// @Description delete the shared workspace
// @Param id path string true "The id you want to delete"
// @Success 200 {shared workspace} delete success!
// @router /:id [delete]
func (o *SharedWorkspaceController) Delete() {
2024-08-30 10:35:12 +02:00
var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers
2024-08-13 15:22:24 +02:00
utils.SHARED_WORKSPACE.String(): {
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/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/",
},
2024-08-21 16:17:43 +02:00
utils.PEER.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
},
2024-08-13 15:22:24 +02:00
}
2024-08-12 14:12:51 +02:00
id := o.Ctx.Input.Param(":id")
2024-08-30 10:35:12 +02:00
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
2024-08-13 15:22:24 +02:00
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id, caller)
2024-08-12 14:12:51 +02:00
o.ServeJSON()
}