2024-07-26 13:07:25 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2026-01-27 15:39:53 +01:00
|
|
|
"oc-catalog/infrastructure"
|
2024-07-26 13:07:25 +02:00
|
|
|
|
|
|
|
|
oclib "cloud.o-forge.io/core/oc-lib"
|
2026-01-27 15:39:53 +01:00
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
2024-07-26 13:07:25 +02:00
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
|
|
)
|
|
|
|
|
|
2024-07-26 14:39:57 +02:00
|
|
|
// Operations about processing
|
2024-07-26 13:07:25 +02:00
|
|
|
type ProcessingController struct {
|
|
|
|
|
beego.Controller
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 17:03:32 +01:00
|
|
|
var processing_collection = oclib.LibDataEnum(oclib.PROCESSING_RESOURCE)
|
2026-01-27 15:39:53 +01:00
|
|
|
var processing_dt = tools.PROCESSING_RESOURCE
|
2025-01-17 17:03:32 +01:00
|
|
|
|
2024-07-26 13:07:25 +02:00
|
|
|
// @Title Update
|
|
|
|
|
// @Description create processings
|
|
|
|
|
// @Param id path string true "the processing id you want to get"
|
|
|
|
|
// @Param body body models.processing true "The processing content"
|
|
|
|
|
// @Success 200 {processing} models.processing
|
|
|
|
|
// @router /:id [put]
|
|
|
|
|
func (o *ProcessingController) Put() {
|
|
|
|
|
// store and return Id or post with UUID
|
2025-01-17 17:03:32 +01:00
|
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
2024-07-26 13:07:25 +02:00
|
|
|
var res map[string]interface{}
|
|
|
|
|
id := o.Ctx.Input.Param(":id")
|
|
|
|
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
2026-01-27 15:39:53 +01:00
|
|
|
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
|
|
|
|
if data.Err == "" {
|
|
|
|
|
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
2026-01-28 17:23:55 +01:00
|
|
|
infrastructure.EmitNATS(tools.PropalgationMessage{
|
|
|
|
|
Action: tools.PB_UPDATE,
|
|
|
|
|
DataType: processing_dt.EnumIndex(),
|
|
|
|
|
User: user,
|
|
|
|
|
Payload: data,
|
|
|
|
|
})
|
2026-01-27 15:39:53 +01:00
|
|
|
}
|
|
|
|
|
o.Data["json"] = data
|
2024-07-26 13:07:25 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Title Create
|
|
|
|
|
// @Description create processing
|
|
|
|
|
// @Param processing body json true "body for processing content (Json format)"
|
|
|
|
|
// @Success 200 {processing} models.processing
|
|
|
|
|
// @router / [post]
|
|
|
|
|
func (o *ProcessingController) Post() {
|
2025-01-17 17:03:32 +01:00
|
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
2024-07-26 13:07:25 +02:00
|
|
|
var res map[string]interface{}
|
|
|
|
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
2026-01-27 15:39:53 +01:00
|
|
|
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).StoreOne(res)
|
|
|
|
|
if data.Err == "" {
|
|
|
|
|
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
2026-01-28 17:23:55 +01:00
|
|
|
infrastructure.EmitNATS(tools.PropalgationMessage{
|
|
|
|
|
Action: tools.PB_CREATE,
|
|
|
|
|
DataType: processing_dt.EnumIndex(),
|
|
|
|
|
User: user,
|
|
|
|
|
Payload: data,
|
|
|
|
|
})
|
2026-01-27 15:39:53 +01:00
|
|
|
}
|
|
|
|
|
o.Data["json"] = data
|
2024-07-26 13:07:25 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Title GetAll
|
|
|
|
|
// @Description find processing by id
|
2025-01-17 17:03:32 +01:00
|
|
|
// @Param is_draft query string false "draft wished"
|
2024-07-26 13:07:25 +02:00
|
|
|
// @Success 200 {processing} models.processing
|
|
|
|
|
// @router / [get]
|
|
|
|
|
func (o *ProcessingController) GetAll() {
|
2025-01-17 17:03:32 +01:00
|
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
|
|
|
|
isDraft := o.Ctx.Input.Query("is_draft")
|
|
|
|
|
o.Data["json"] = oclib.NewRequest(processing_collection, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
2024-07-26 13:07:25 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 14:39:57 +02:00
|
|
|
// @Title Get
|
|
|
|
|
// @Description find processing by key word
|
|
|
|
|
// @Param search path string true "the search you want to get"
|
2025-01-17 17:03:32 +01:00
|
|
|
// @Param is_draft query string false "draft wished"
|
2024-07-26 14:39:57 +02:00
|
|
|
// @Success 200 {processing} models.processing
|
2024-07-30 10:07:34 +02:00
|
|
|
// @router /search/:search [get]
|
2024-07-26 14:39:57 +02:00
|
|
|
func (o *ProcessingController) Search() {
|
2025-01-17 17:03:32 +01:00
|
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
2024-07-26 14:39:57 +02:00
|
|
|
search := o.Ctx.Input.Param(":search")
|
2025-01-17 17:03:32 +01:00
|
|
|
isDraft := o.Ctx.Input.Query("is_draft")
|
|
|
|
|
o.Data["json"] = oclib.NewRequest(processing_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
2024-07-26 14:39:57 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 13:07:25 +02:00
|
|
|
// @Title Get
|
|
|
|
|
// @Description find processing by id
|
|
|
|
|
// @Param id path string true "the id you want to get"
|
|
|
|
|
// @Success 200 {processing} models.processing
|
|
|
|
|
// @router /:id [get]
|
|
|
|
|
func (o *ProcessingController) Get() {
|
2025-01-17 17:03:32 +01:00
|
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
2024-07-26 13:07:25 +02:00
|
|
|
id := o.Ctx.Input.Param(":id")
|
2025-01-17 17:03:32 +01:00
|
|
|
o.Data["json"] = oclib.NewRequest(processing_collection, user, peerID, groups, nil).LoadOne(id)
|
2024-07-26 13:07:25 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Title Delete
|
|
|
|
|
// @Description delete the processing
|
|
|
|
|
// @Param id path string true "The id you want to delete"
|
|
|
|
|
// @Success 200 {processing} delete success!
|
|
|
|
|
// @router /:id [delete]
|
|
|
|
|
func (o *ProcessingController) Delete() {
|
2025-01-17 17:03:32 +01:00
|
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
2024-07-26 13:07:25 +02:00
|
|
|
id := o.Ctx.Input.Param(":id")
|
2026-01-27 15:39:53 +01:00
|
|
|
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).DeleteOne(id)
|
|
|
|
|
if data.Err == "" {
|
|
|
|
|
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
2026-01-28 17:23:55 +01:00
|
|
|
infrastructure.EmitNATS(tools.PropalgationMessage{
|
|
|
|
|
Action: tools.PB_DELETE,
|
|
|
|
|
DataType: processing_dt.EnumIndex(),
|
|
|
|
|
User: user,
|
|
|
|
|
Payload: data,
|
|
|
|
|
})
|
2026-01-27 15:39:53 +01:00
|
|
|
}
|
|
|
|
|
o.Data["json"] = data
|
2024-07-26 13:07:25 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
|
}
|
2026-01-27 15:39:53 +01:00
|
|
|
|
|
|
|
|
// @Title Search Decentralized
|
|
|
|
|
// @Description find workflow by key word
|
|
|
|
|
// @Param search path string true "the search you want to get"
|
|
|
|
|
// @Param is_draft query string false "draft wished"
|
|
|
|
|
// @Success 200 {workflow} models.workflow
|
|
|
|
|
// @router /search/:search/decentralized/:type [get]
|
|
|
|
|
func (o *ProcessingController) SearchDecentralized() {
|
|
|
|
|
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
|
|
|
|
search := o.Ctx.Input.Param(":search")
|
|
|
|
|
t := o.Ctx.Input.Param(":type")
|
2026-01-28 17:23:55 +01:00
|
|
|
b, err := json.Marshal(map[string]string{
|
|
|
|
|
"search": search,
|
|
|
|
|
"type": t,
|
|
|
|
|
})
|
|
|
|
|
infrastructure.EmitNATS(tools.PropalgationMessage{
|
|
|
|
|
Action: tools.PB_SEARCH,
|
|
|
|
|
DataType: processing_dt.EnumIndex(),
|
|
|
|
|
User: user,
|
|
|
|
|
Payload: b,
|
|
|
|
|
})
|
2026-01-27 15:39:53 +01:00
|
|
|
if err != nil {
|
|
|
|
|
o.Data["json"] = map[string]interface{}{
|
|
|
|
|
"data": nil,
|
|
|
|
|
"code": 400,
|
|
|
|
|
"error": err,
|
|
|
|
|
}
|
|
|
|
|
o.ServeJSON()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
|
|
|
|
}
|