@@ -112,20 +112,23 @@ func (as *AnswerService) RemoveAnswer(ctx context.Context, req *schema.RemoveAns
112
112
113
113
}
114
114
115
+ err = as .answerRepo .RemoveAnswer (ctx , req .ID )
116
+ if err != nil {
117
+ return err
118
+ }
119
+
115
120
// user add question count
116
- err = as .questionCommon .UpdateAnswerCount (ctx , answerInfo .QuestionID , - 1 )
121
+ err = as .questionCommon .UpdateAnswerCount (ctx , answerInfo .QuestionID )
117
122
if err != nil {
118
123
log .Error ("IncreaseAnswerCount error" , err .Error ())
119
124
}
120
-
121
- err = as .userCommon .UpdateAnswerCount (ctx , answerInfo .UserID , - 1 )
125
+ userAnswerCount , err := as .answerRepo .GetCountByUserID (ctx , answerInfo .UserID )
122
126
if err != nil {
123
- log .Error ("user IncreaseAnswerCount error" , err .Error ())
127
+ log .Error ("GetCountByUserID error" , err .Error ())
124
128
}
125
-
126
- err = as .answerRepo .RemoveAnswer (ctx , req .ID )
129
+ err = as .userCommon .UpdateAnswerCount (ctx , answerInfo .UserID , int (userAnswerCount ))
127
130
if err != nil {
128
- return err
131
+ log . Error ( "user IncreaseAnswerCount error" , err . Error ())
129
132
}
130
133
// #2372 In order to simplify the process and complexity, as well as to consider if it is in-house,
131
134
// facing the problem of recovery.
@@ -167,7 +170,7 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (
167
170
if err = as .answerRepo .AddAnswer (ctx , insertData ); err != nil {
168
171
return "" , err
169
172
}
170
- err = as .questionCommon .UpdateAnswerCount (ctx , req .QuestionID , 1 )
173
+ err = as .questionCommon .UpdateAnswerCount (ctx , req .QuestionID )
171
174
if err != nil {
172
175
log .Error ("IncreaseAnswerCount error" , err .Error ())
173
176
}
@@ -179,8 +182,11 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (
179
182
if err != nil {
180
183
return insertData .ID , err
181
184
}
182
-
183
- err = as .userCommon .UpdateAnswerCount (ctx , req .UserID , 1 )
185
+ userAnswerCount , err := as .answerRepo .GetCountByUserID (ctx , req .UserID )
186
+ if err != nil {
187
+ log .Error ("GetCountByUserID error" , err .Error ())
188
+ }
189
+ err = as .userCommon .UpdateAnswerCount (ctx , req .UserID , int (userAnswerCount ))
184
190
if err != nil {
185
191
log .Error ("user IncreaseAnswerCount error" , err .Error ())
186
192
}
0 commit comments