func (m *TargetManager) Create(raw *target.Target) (*target.Target, error) { // TODO (m0sth8): add validation 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 (m *TargetManager) UpdateSummary(obj *target.Target) error { fltr := &IssueFltr{ Target: obj.Id, False: false, Resolved: false, Muted: false, } // TODO(m0sth8): get only severity/count through aggregation issues, _, err := m.manager.Issues.FilterBy(fltr) if err != nil { return err } summary := map[issue.Severity]int{} for _, issue := range issues { summary[issue.Severity] = summary[issue.Severity] + 1 } if obj.SummaryReport == nil { obj.SummaryReport = &target.SummaryReport{} } obj.SummaryReport.Issues = summary // TODO(m0sth8): update only summary field return m.Update(obj) }
func (m *TargetManager) Update(obj *target.Target) error { obj.Updated = time.Now().UTC() return m.col.UpdateId(obj.Id, obj) }