@@ -346,24 +346,23 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
346346 return "" , errors .BadRequest (reason .AnswerCannotUpdate )
347347 }
348348
349- questionInfo , exist , err := as .questionRepo . GetQuestion (ctx , req .QuestionID )
349+ answerInfo , exist , err := as .answerRepo . GetByID (ctx , req .ID )
350350 if err != nil {
351351 return "" , err
352352 }
353353 if ! exist {
354- return "" , errors .BadRequest (reason .QuestionNotFound )
354+ return "" , errors .BadRequest (reason .AnswerNotFound )
355+ }
356+ if answerInfo .Status == entity .AnswerStatusDeleted {
357+ return "" , errors .BadRequest (reason .AnswerCannotUpdate )
355358 }
356359
357- answerInfo , exist , err := as .answerRepo . GetByID (ctx , req . ID )
360+ questionInfo , exist , err := as .questionRepo . GetQuestion (ctx , answerInfo . QuestionID )
358361 if err != nil {
359362 return "" , err
360363 }
361364 if ! exist {
362- return "" , errors .BadRequest (reason .AnswerNotFound )
363- }
364-
365- if answerInfo .Status == entity .AnswerStatusDeleted {
366- return "" , errors .BadRequest (reason .AnswerCannotUpdate )
365+ return "" , errors .BadRequest (reason .QuestionNotFound )
367366 }
368367
369368 //If the content is the same, ignore it
@@ -374,7 +373,7 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
374373 insertData := & entity.Answer {}
375374 insertData .ID = req .ID
376375 insertData .UserID = answerInfo .UserID
377- insertData .QuestionID = req . QuestionID
376+ insertData .QuestionID = questionInfo . ID
378377 insertData .OriginalText = req .Content
379378 insertData .ParsedText = req .HTML
380379 insertData .UpdatedAt = time .Now ()
@@ -403,7 +402,7 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
403402 if err = as .answerRepo .UpdateAnswer (ctx , insertData , []string {"original_text" , "parsed_text" , "updated_at" , "last_edit_user_id" }); err != nil {
404403 return "" , err
405404 }
406- err = as .questionCommon .UpdatePostTime (ctx , req . QuestionID )
405+ err = as .questionCommon .UpdatePostTime (ctx , questionInfo . ID )
407406 if err != nil {
408407 return insertData .ID , err
409408 }
0 commit comments