func (m *AgentManager) Create(raw *agent.Agent) (*agent.Agent, error) { // TODO (m0sth8): add validattion raw.Id = bson.NewObjectId() raw.Created = time.Now().UTC() raw.Updated = raw.Created if err := m.col.Insert(raw); err != nil { return nil, err } return raw, nil }
func (a *Agent) Retrieve(ctx context.Context, agnt *agent.Agent) error { logrus.Info("Retrieve") if agnt.Id == "" { agnt.Status = agent.StatusUndefined return fmt.Errorf("ageng.Id shouldn't be empty") } got, err := a.api.Agents.Get(ctx, client.FromId(agnt.Id)) if err != nil { return err } *agnt = *got return nil }
func (m *AgentManager) Update(obj *agent.Agent) error { obj.Updated = time.Now().UTC() return m.col.UpdateId(obj.Id, obj) }