Add paths

This commit is contained in:
mr 2024-08-13 11:29:20 +02:00
parent 94255cf815
commit 08f1aced8c
2 changed files with 33 additions and 18 deletions

View File

@ -12,6 +12,33 @@ import (
"github.com/nats-io/nats.go"
)
var paths = map[string]map[tools.METHOD]string{
oclib.LibDataEnum(oclib.BOOKING).String(): {
tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/",
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/",
},
oclib.LibDataEnum(oclib.SHARED_WORKSPACE).String(): {
tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
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/",
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
},
oclib.LibDataEnum(oclib.WORKSPACE).String(): {
tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
},
oclib.LibDataEnum(oclib.WORKFLOW).String(): {
tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
},
}
// Operations about workflow
type WorkflowController struct {
beego.Controller
@ -40,15 +67,7 @@ func (o *WorkflowController) Put() {
var res map[string]interface{}
id := o.Ctx.Input.Param(":id")
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
caller := tools.NewHTTPCaller(
map[string]map[tools.METHOD]string{
oclib.LibDataEnum(oclib.BOOKING).String(): {
tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking",
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking",
},
})
caller := tools.NewHTTPCaller(paths)
data := oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW), res, id, caller)
data.Err += o.SetNATSPub(res, data)
o.Data["json"] = data
@ -95,14 +114,7 @@ func (o *WorkflowController) SetNATSPub(res map[string]interface{}, data oclib.L
func (o *WorkflowController) Post() {
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
caller := tools.NewHTTPCaller(map[string]map[tools.METHOD]string{
oclib.LibDataEnum(oclib.BOOKING).String(): {
tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking",
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking",
},
})
caller := tools.NewHTTPCaller(paths)
data := oclib.StoreOne(oclib.LibDataEnum(oclib.WORKFLOW), res, caller)
data.Err += o.SetNATSPub(res, data)
o.Data["json"] = data

View File

@ -37,7 +37,10 @@ func main() {
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
)
oclib.Init("oc-workflow")
oclib.AddPath(oclib.LibDataEnum(oclib.BOOKING), o.GetStringDefault("BOOKING_URL", ":8089"))
oclib.AddPath(oclib.LibDataEnum(oclib.BOOKING), o.GetStringDefault("BOOKING_URL", ":8092"))
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"))
// Normal beego init
//if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true