MCPcopy
hub / github.com/apache/answer / Update

Method Update

internal/service/content/answer_service.go:350–445  ·  view source on GitHub ↗
(ctx context.Context, req *schema.AnswerUpdateReq)

Source from the content-addressed store, hash-verified

348}
349
350func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq) (string, error) {
351 var canUpdate bool
352 _, existUnreviewed, err := as.revisionService.ExistUnreviewedByObjectID(ctx, req.ID)
353 if err != nil {
354 return "", err
355 }
356 if existUnreviewed {
357 return "", errors.BadRequest(reason.AnswerCannotUpdate)
358 }
359
360 answerInfo, exist, err := as.answerRepo.GetByID(ctx, req.ID)
361 if err != nil {
362 return "", err
363 }
364 if !exist {
365 return "", errors.BadRequest(reason.AnswerNotFound)
366 }
367 if answerInfo.Status == entity.AnswerStatusDeleted {
368 return "", errors.BadRequest(reason.AnswerCannotUpdate)
369 }
370
371 questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, answerInfo.QuestionID)
372 if err != nil {
373 return "", err
374 }
375 if !exist {
376 return "", errors.BadRequest(reason.QuestionNotFound)
377 }
378
379 // If the content is the same, ignore it
380 if answerInfo.OriginalText == req.Content {
381 return "", nil
382 }
383
384 insertData := &entity.Answer{}
385 insertData.ID = req.ID
386 insertData.UserID = answerInfo.UserID
387 insertData.QuestionID = questionInfo.ID
388 insertData.OriginalText = req.Content
389 insertData.ParsedText = req.HTML
390 insertData.UpdatedAt = time.Now()
391 insertData.LastEditUserID = "0"
392 if answerInfo.UserID != req.UserID {
393 insertData.LastEditUserID = req.UserID
394 }
395
396 revisionDTO := &schema.AddRevisionDTO{
397 UserID: req.UserID,
398 ObjectID: req.ID,
399 Log: req.EditSummary,
400 }
401
402 if req.NoNeedReview || answerInfo.UserID == req.UserID {
403 canUpdate = true
404 }
405
406 if !canUpdate {
407 revisionDTO.Status = entity.RevisionUnreviewedStatus

Callers 15

SetMethod · 0.80
UpdateAnswerMethod · 0.80
defaultLoginConfigFunction · 0.80
deactivatePluginFunction · 0.80
SaveByTypeMethod · 0.80
UpdateConversationMethod · 0.80
UpdateRecordVoteMethod · 0.80
ClearUnReadMethod · 0.80
ClearIDUnReadMethod · 0.80
UpdateCollectionMethod · 0.80

Calls 12

NewEventFunction · 0.92
UpdateQuestionLinkMethod · 0.80
UpdatePostTimeMethod · 0.80
AIDMethod · 0.80
TIDMethod · 0.80
GetByIDMethod · 0.65
GetQuestionMethod · 0.65
UpdateAnswerMethod · 0.65
AddRevisionMethod · 0.65
SendMethod · 0.65

Tested by

no test coverage detected