diff --git a/internal/repo/answer/answer_repo.go b/internal/repo/answer/answer_repo.go index cd04a8ec..cfa8023d 100644 --- a/internal/repo/answer/answer_repo.go +++ b/internal/repo/answer/answer_repo.go @@ -115,10 +115,10 @@ func (ar *answerRepo) RemoveAllUserAnswer(ctx context.Context, userID string) (e } // UpdateAnswer update answer -func (ar *answerRepo) UpdateAnswer(ctx context.Context, answer *entity.Answer, Colar []string) (err error) { +func (ar *answerRepo) UpdateAnswer(ctx context.Context, answer *entity.Answer, cols []string) (err error) { answer.ID = uid.DeShortID(answer.ID) answer.QuestionID = uid.DeShortID(answer.QuestionID) - _, err = ar.data.DB.Context(ctx).ID(answer.ID).Cols(Colar...).Update(answer) + _, err = ar.data.DB.Context(ctx).ID(answer.ID).Cols(cols...).Update(answer) if err != nil { err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() } @@ -126,15 +126,13 @@ func (ar *answerRepo) UpdateAnswer(ctx context.Context, answer *entity.Answer, C return err } -func (ar *answerRepo) UpdateAnswerStatus(ctx context.Context, answer *entity.Answer) (err error) { - now := time.Now() - answer.ID = uid.DeShortID(answer.ID) - answer.UpdatedAt = now - _, err = ar.data.DB.Context(ctx).Where("id =?", answer.ID).Cols("status", "updated_at").Update(answer) +func (ar *answerRepo) UpdateAnswerStatus(ctx context.Context, answerID string, status int) (err error) { + answerID = uid.DeShortID(answerID) + _, err = ar.data.DB.Context(ctx).ID(answerID).Cols("status").Update(&entity.Answer{Status: status}) if err != nil { return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() } - _ = ar.updateSearch(ctx, answer.ID) + _ = ar.updateSearch(ctx, answerID) return } diff --git a/internal/repo/question/question_repo.go b/internal/repo/question/question_repo.go index 8420eb45..c2fe00f5 100644 --- a/internal/repo/question/question_repo.go +++ b/internal/repo/question/question_repo.go @@ -118,15 +118,13 @@ func (qr *questionRepo) UpdateCollectionCount(ctx context.Context, questionID st return nil } -func (qr *questionRepo) UpdateQuestionStatus(ctx context.Context, question *entity.Question) (err error) { - question.ID = uid.DeShortID(question.ID) - now := time.Now() - question.UpdatedAt = now - _, err = qr.data.DB.Context(ctx).Where("id =?", question.ID).Cols("status", "updated_at").Update(question) +func (qr *questionRepo) UpdateQuestionStatus(ctx context.Context, questionID string, status int) (err error) { + questionID = uid.DeShortID(questionID) + _, err = qr.data.DB.Context(ctx).ID(questionID).Cols("status").Update(&entity.Question{Status: status}) if err != nil { return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() } - _ = qr.updateSearch(ctx, question.ID) + _ = qr.updateSearch(ctx, questionID) return nil } diff --git a/internal/service/answer_common/answer.go b/internal/service/answer_common/answer.go index 4851fd79..2ba191e0 100644 --- a/internal/service/answer_common/answer.go +++ b/internal/service/answer_common/answer.go @@ -13,7 +13,7 @@ import ( type AnswerRepo interface { AddAnswer(ctx context.Context, answer *entity.Answer) (err error) RemoveAnswer(ctx context.Context, id string) (err error) - UpdateAnswer(ctx context.Context, answer *entity.Answer, Colar []string) (err error) + UpdateAnswer(ctx context.Context, answer *entity.Answer, cols []string) (err error) GetAnswer(ctx context.Context, id string) (answer *entity.Answer, exist bool, err error) GetAnswerList(ctx context.Context, answer *entity.Answer) (answerList []*entity.Answer, err error) GetAnswerPage(ctx context.Context, page, pageSize int, answer *entity.Answer) (answerList []*entity.Answer, total int64, err error) @@ -24,7 +24,7 @@ type AnswerRepo interface { GetByUserIDQuestionID(ctx context.Context, userID string, questionID string) (*entity.Answer, bool, error) SearchList(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error) AdminSearchList(ctx context.Context, search *schema.AdminAnswerPageReq) ([]*entity.Answer, int64, error) - UpdateAnswerStatus(ctx context.Context, answer *entity.Answer) (err error) + UpdateAnswerStatus(ctx context.Context, answerID string, status int) (err error) GetAnswerCount(ctx context.Context) (count int64, err error) RemoveAllUserAnswer(ctx context.Context, userID string) (err error) } diff --git a/internal/service/answer_service.go b/internal/service/answer_service.go index f1e76bf1..7895f09b 100644 --- a/internal/service/answer_service.go +++ b/internal/service/answer_service.go @@ -451,7 +451,7 @@ func (as *AnswerService) AdminSetAnswerStatus(ctx context.Context, req *schema.A return fmt.Errorf("answer does not exist") } answerInfo.Status = setStatus - err = as.answerRepo.UpdateAnswerStatus(ctx, answerInfo) + err = as.answerRepo.UpdateAnswerStatus(ctx, req.AnswerID, setStatus) if err != nil { return err } diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go index 4f23dd9f..c088ac44 100644 --- a/internal/service/question_common/question.go +++ b/internal/service/question_common/question.go @@ -37,7 +37,7 @@ type QuestionRepo interface { GetQuestionList(ctx context.Context, question *entity.Question) (questions []*entity.Question, err error) GetQuestionPage(ctx context.Context, page, pageSize int, userID, tagID, orderCond string, inDays int) ( questionList []*entity.Question, total int64, err error) - UpdateQuestionStatus(ctx context.Context, question *entity.Question) (err error) + UpdateQuestionStatus(ctx context.Context, questionID string, status int) (err error) UpdateQuestionStatusWithOutUpdateTime(ctx context.Context, question *entity.Question) (err error) UpdateQuestionOperation(ctx context.Context, question *entity.Question) (err error) GetQuestionsByTitle(ctx context.Context, title string, pageSize int) (questionList []*entity.Question, err error) @@ -451,7 +451,7 @@ func (qs *QuestionCommon) RemoveQuestion(ctx context.Context, req *schema.Remove } questionInfo.Status = entity.QuestionStatusDeleted - err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo) + err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo.ID, questionInfo.Status) if err != nil { return err } @@ -478,7 +478,7 @@ func (qs *QuestionCommon) CloseQuestion(ctx context.Context, req *schema.CloseQu return nil } questionInfo.Status = entity.QuestionStatusClosed - err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo) + err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo.ID, questionInfo.Status) if err != nil { return err } diff --git a/internal/service/question_service.go b/internal/service/question_service.go index 00bdf299..7907bcb0 100644 --- a/internal/service/question_service.go +++ b/internal/service/question_service.go @@ -104,7 +104,7 @@ func (qs *QuestionService) CloseQuestion(ctx context.Context, req *schema.CloseQ } questionInfo.Status = entity.QuestionStatusClosed - err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo) + err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo.ID, questionInfo.Status) if err != nil { return err } @@ -138,7 +138,7 @@ func (qs *QuestionService) ReopenQuestion(ctx context.Context, req *schema.Reope } questionInfo.Status = entity.QuestionStatusAvailable - err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo) + err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo.ID, questionInfo.Status) if err != nil { return err } @@ -1207,7 +1207,7 @@ func (qs *QuestionService) AdminSetQuestionStatus(ctx context.Context, questionI if !exist { return errors.BadRequest(reason.QuestionNotFound) } - err = qs.questionRepo.UpdateQuestionStatus(ctx, &entity.Question{ID: questionInfo.ID, Status: setStatus}) + err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo.ID, setStatus) if err != nil { return err } diff --git a/internal/service/user_admin/user_backyard.go b/internal/service/user_admin/user_backyard.go index 831730fe..71990a37 100644 --- a/internal/service/user_admin/user_backyard.go +++ b/internal/service/user_admin/user_backyard.go @@ -353,6 +353,9 @@ func (us *UserAdminService) GetUserPage(ctx context.Context, req *schema.GetUser user.Status = entity.UserStatusSuspended } else if req.IsDeleted() { user.Status = entity.UserStatusDeleted + } else { + user.MailStatus = entity.EmailStatusAvailable + user.Status = entity.UserStatusAvailable } if len(req.Query) > 0 {