package controllers import ( "strconv" "time" oclib "cloud.o-forge.io/core/oc-lib" dbs "cloud.o-forge.io/core/oc-lib/dbs" beego "github.com/beego/beego/v2/server/web" "go.mongodb.org/mongo-driver/bson/primitive" ) var collection = oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION) // Operations about workflow type WorkflowExecutionController struct { beego.Controller } // @Title SearchPerDate // @Description search workspace // @Param start_date path string true "the word search you want to get" // @Param end_date path string true "the word search you want to get" // @Param is_draft query string false "draft wished" // @Param offset query string false // @Param limit query string false // @Success 200 {workspace} models.workspace // @router /search/:start_date/:end_date [get] func (o *WorkflowExecutionController) SearchPerDate() { /* * This is a sample of how to use the search function * The search function is used to search for data in the database * The search function takes in a filter and a data type * The filter is a struct that contains the search parameters * The data type is an enum that specifies the type of data to search for * The search function returns a list of data that matches the filter * The data is then returned as a json object */ // user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request) // store and return Id or post with UUID offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset")) limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit")) start_date, _ := time.ParseInLocation("2006-01-02", o.Ctx.Input.Param(":start_date"), time.UTC) end_date, _ := time.ParseInLocation("2006-01-02", o.Ctx.Input.Param(":end_date"), time.UTC) sd := primitive.NewDateTimeFromTime(start_date) ed := primitive.NewDateTimeFromTime(end_date) f := dbs.Filters{ And: map[string][]dbs.Filter{ "execution_date": {{Operator: "gte", Value: sd}, {Operator: "lte", Value: ed}}, }, } isDraft := o.Ctx.Input.Query("is_draft") // o.Data["json"] = oclib.NewRequest(collection, user, peerID, groups, nil).Search(&f, "", isDraft == "true") o.Data["json"] = oclib.NewRequestAdmin(collection, nil).Search(&f, "", isDraft == "true", int64(offset), int64(limit)) o.ServeJSON() } // @Title GetAll // @Description find workflow by workflowid // @Param is_draft query string false "draft wished" // @Param offset query string false // @Param limit query string false // @Success 200 {workflow} models.workflow // @router / [get] func (o *WorkflowExecutionController) GetAll() { offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset")) limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit")) user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request) isDraft := o.Ctx.Input.Query("is_draft") o.Data["json"] = oclib.NewRequest(collection, user, peerID, groups, nil).LoadAll(isDraft == "true", int64(offset), int64(limit)) o.ServeJSON() } // @Title Get // @Description find workflow by workflowid // @Param id path string true "the workflowid you want to get" // @Success 200 {workflow} models.workflow // @router /:id [get] func (o *WorkflowExecutionController) Get() { //user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request) id := o.Ctx.Input.Param(":id") // o.Data["json"] = oclib.NewRequest(collection, user, peerID, groups, nil).LoadOne(id) o.Data["json"] = oclib.NewRequestAdmin(collection, nil).LoadOne(id) o.ServeJSON() } // @Title Delete // @Description find workflow by workflowid // @Param id path string true "the workflowid you want to get" // @Success 200 {workflow} models.workflow // @router /:id [delete] func (o *WorkflowExecutionController) Delete() { user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request) id := o.Ctx.Input.Param(":id") data := oclib.NewRequest(collection, user, peerID, groups, nil).LoadOne(id) if b := data.ToBookings(); b != nil { bAccess := oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.BOOKING), nil) s := bAccess.Search(&dbs.Filters{ And: map[string][]dbs.Filter{ "execution_id": {{Operator: dbs.EQUAL.String(), Value: b.ExecutionID}}, }, }, "", false, 0, 10000) for _, ss := range s.Data { bAccess.DeleteOne(ss.GetID()) } } o.Data["json"] = oclib.NewRequest(collection, user, peerID, groups, nil).DeleteOne(id) o.ServeJSON() } // @Title Search // @Description find compute by key word // @Param search path string true "the search you want to get" // @Param is_draft query string false "draft wished" // @Param offset query string false // @Param limit query string false // @Success 200 {compute} models.compute // @router /search/:search [get] func (o *WorkflowExecutionController) Search() { user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request) offset, _ := strconv.Atoi(o.Ctx.Input.Query("offset")) limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit")) isDraft := o.Ctx.Input.Query("is_draft") search := o.Ctx.Input.Param(":search") o.Data["json"] = oclib.NewRequest(collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true", int64(offset), int64(limit)) o.ServeJSON() }