package controllers import ( "cloud.o-forge.io/core/deprecated-oc-catalog/models" beego "github.com/beego/beego/v2/server/web" ) type WorkspaceController struct { beego.Controller } // @Title Add model to workspace // @Description Insert a resource in the workspace // @Param id query string true "ID of a resource" // @Param rtype query string true "Type of resource" // @Success 200 {string} login success // @Failure 403 Authentication issue // @Failure 400 {string} Other error // // @Security jwtAPIToken // @router / [post] func (u *WorkspaceController) AddModel(id, rtype string) { // token := u.Ctx.Input.GetData("jwtAPIToken").(string) // //TODO: Implement as swagger security definition (api key?) // username, err := GetUsernameFromToken(token) // if err != nil { // u.Data["json"] = "No valid token" // u.Ctx.Output.Status = 403 // u.ServeJSON() // return // } var err error username := "asd" w := models.GetWorkspace(username) if w == nil { w, err = models.NewWorkspace(username) if err != nil { u.Data["json"] = err.Error() u.Ctx.Output.Status = 400 u.ServeJSON() return } } // w.NewResource(id, rtype) if err := models.AddResource(username, id, rtype); err != nil { u.Data["json"] = err.Error() u.Ctx.Output.Status = 400 u.ServeJSON() return } } // @Title Get workspace // @Description Get workspace elements based on user_id token // @Success 200 {object} models.Workspace // @Failure 403 Authentication issue // // @Security jwtAPIToken // @router /list [get] func (u *WorkspaceController) ListWorkspace() { // token := u.Ctx.Input.GetData("jwtAPIToken").(string) // //TODO: Implement as swagger security definition (api key?) // username, err := GetUsernameFromToken(token) // if err != nil { // u.Data["json"] = "No valid token" // u.Ctx.Output.Status = 403 // u.ServeJSON() // return // } username := "asd" ws := models.GetWorkspace(username) // if ws == nil { // u.Ctx.Output.Status = 503 // return // } u.Data["json"] = ws u.ServeJSON() } // @Title Get full workspace // @Description Get full workspace elements based on user_id token // @Success 200 {object} models.WorkspaceModel // @Failure 403 Authentication issue // // @Security jwtAPIToken // @router /list_model [get] func (u *WorkspaceController) ListWorkspaceModel() { // token := u.Ctx.Input.GetData("jwtAPIToken").(string) // //TODO: Implement as swagger security definition (api key?) // username, err := GetUsernameFromToken(token) // if err != nil { // u.Data["json"] = "No valid token" // u.Ctx.Output.Status = 403 // u.ServeJSON() // return // } username := "asd" val, err := models.ListFullWorkspace(username) if err != nil { u.Ctx.Output.Status = 503 return } u.Data["json"] = val u.ServeJSON() } // @Title Delete element from user workspace // @Description Remove a resource from the workspace // @Param id query string true "ID of a resource" // @Param rtype query string true "Type of resource" // @Success 200 {string} Removed succeful // @Failure 403 Authentication issue // @Failure 400 {string} Other error // // @Security jwtAPIToken // @router / [delete] func (u *WorkspaceController) DeleteElement(id, rtype string) { // token := u.Ctx.Input.GetData("jwtAPIToken").(string) // //TODO: Implement as swagger security definition (api key?) // username, err := GetUsernameFromToken(token) // if err != nil { // u.Data["json"] = "No valid token" // u.Ctx.Output.Status = 403 // u.ServeJSON() // return // } username := "asd" if err := models.RemoveResource(username, id, rtype); err != nil { u.Data["json"] = err.Error() u.Ctx.Output.Status = 400 u.ServeJSON() return } }