package controllers import ( "cloud.o-forge.io/core/oc-catalog/models" beego "github.com/beego/beego/v2/server/web" ) // All operations related to the rType computing type ComputingController struct { beego.Controller } // @Title Get computing by ID // @Description Find a computing resource based on ID // @Param ID path string true "The ID of the resource" // @Success 200 {object} models.ComputingModel // @Failure 403 ID is empty // @router /:ID [get] func (o *ComputingController) GetOneComputing(ID string) { if ID != "" { ob, err := models.GetOneComputing(ID) if err != nil { o.Data["json"] = err.Error() } else { o.Data["json"] = ob } } o.ServeJSON() } // @Title Add computing // @Description Submit a computing object // @Param body body models.ComputingNEWModel true "The object content" // @Success 200 {string} ID // @Failure 403 Missing body or fields // @router / [post] func (o *ComputingController) PostComputing(body models.ComputingNEWModel) { err := validate.Struct(body) // validationErrors := err.(validator.ValidationErrors) if err != nil { o.Data["json"] = err.Error() o.Ctx.Output.Status = 403 o.ServeJSON() return } ID, err := models.PostOneComputing(body) if err != nil { o.Ctx.Output.SetStatus(500) return } o.Data["json"] = map[string]string{"ID": ID} o.ServeJSON() } // @Title Get multiple computing by IDs // @Description Return Computing objects if found in the DB. Not found IDs will be ignored // @Param IDs path []string true "List of computing IDs" // @Success 200 {object} []models.ComputingModel // @Failure 403 IDs are empty // @router /multi/:IDs [get] func (o *ComputingController) GetMultipleComputing(IDs []string) { if len(IDs) != 0 { ob, err := models.GetMultipleComputing(IDs) if err != nil { o.Ctx.Output.SetStatus(500) } else { o.Data["json"] = ob } } else { o.Ctx.Output.SetStatus(403) } o.ServeJSON() }