func (m *IssueManager) Create(raw *issue.TargetIssue) (*issue.TargetIssue, 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 (s *IssueService) update(req *restful.Request, resp *restful.Response, issueObj *issue.TargetIssue) { // TODO (m0sth8): Check permissions raw := &TargetIssueEntity{} if err := req.ReadEntity(raw); err != nil { logrus.Error(stackerr.Wrap(err)) resp.WriteServiceError(http.StatusBadRequest, services.WrongEntityErr) return } mgr := s.Manager() defer mgr.Close() if raw.Confirmed != nil { issueObj.Confirmed = *raw.Confirmed } if raw.False != nil { issueObj.False = *raw.False } if raw.Resolved != nil { issueObj.Resolved = *raw.Resolved } if raw.Muted != nil { issueObj.Muted = *raw.Muted } if err := mgr.Issues.Update(issueObj); err != nil { if mgr.IsNotFound(err) { resp.WriteErrorString(http.StatusNotFound, "Not found") return } if mgr.IsDup(err) { resp.WriteServiceError( http.StatusConflict, services.DuplicateErr) return } logrus.Error(stackerr.Wrap(err)) resp.WriteServiceError(http.StatusInternalServerError, services.DbErr) return } resp.WriteHeader(http.StatusOK) resp.WriteEntity(issueObj) }
func (m *IssueManager) Update(obj *issue.TargetIssue) error { obj.Updated = time.Now().UTC() return m.col.UpdateId(obj.Id, obj) }