func AddAgent(ctx *Context, agent model.AgentDTO) { if !agent.ValidName() { ctx.JSON(400, "invalde agent Name. must match /^[0-9a-Z_-]+$/") return } agent.Id = 0 //need to add suport for middelware context with AUTH/ agent.OrgId = ctx.OrgId err := sqlstore.AddAgent(&agent) if err != nil { log.Error(3, err.Error()) ctx.JSON(200, rbody.ErrResp(500, err)) return } ctx.JSON(200, rbody.OkResp("agent", agent)) }
func UpdateAgent(ctx *Context, agent model.AgentDTO) { if !agent.ValidName() { ctx.JSON(200, rbody.ErrResp(400, fmt.Errorf("invalid agent Name. must match /^[0-9a-Z_-]+$/"))) return } if agent.Id == 0 { ctx.JSON(200, rbody.ErrResp(400, fmt.Errorf("agent ID not set."))) return } //need to add suport for middelware context with AUTH/ agent.OrgId = ctx.OrgId err := sqlstore.UpdateAgent(&agent) if err != nil { log.Error(3, err.Error()) ctx.JSON(200, rbody.ErrResp(500, err)) return } ctx.JSON(200, rbody.OkResp("agent", agent)) }