fix Adopted

This commit is contained in:
aichy 2022-09-28 10:53:09 +08:00
parent 60dfc74301
commit a116c39e11
4 changed files with 43 additions and 13 deletions

2
.gitignore vendored
View File

@ -9,7 +9,7 @@
/.vscode/*.log
/cmd/answer/*.sh
/cmd/logs
/configs/*
/configs/config-dev.yaml
/go.work*
/logs
/ui/build

19
configs/config.yaml Normal file
View File

@ -0,0 +1,19 @@
server:
http:
addr: ""
data:
database:
connection: ""
cache:
file_path: ""
i18n:
bundle_dir: ""
swaggerui:
show: true
protocol: http
host: 0
address: ':'
service_config:
secret_key: ""
web_host: ""
upload_path: ""

View File

@ -132,7 +132,7 @@ func (ar *answerRepo) UpdateAdopted(ctx context.Context, id string, questionId s
if err != nil {
return err
}
if id != "" {
if id != "0" {
data.Adopted = schema.Answer_Adopted_Enable
_, err = ar.data.DB.Where("id = ?", id).Cols("adopted").Update(&data)
if err != nil {

View File

@ -191,16 +191,25 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
// UpdateAdopted
func (as *AnswerService) UpdateAdopted(ctx context.Context, req *schema.AnswerAdoptedReq) error {
if req.AnswerID == "" {
req.AnswerID = "0"
}
if req.UserID == "" {
return nil
}
newAnswerInfo, exist, err := as.answerRepo.GetByID(ctx, req.AnswerID)
if err != nil {
return err
}
if !exist {
return errors.BadRequest(reason.AnswerNotFound)
newAnswerInfo := &entity.Answer{}
newAnswerInfoexist := false
var err error
if req.AnswerID != "0" {
newAnswerInfo, newAnswerInfoexist, err = as.answerRepo.GetByID(ctx, req.AnswerID)
if err != nil {
return err
}
if !newAnswerInfoexist {
return errors.BadRequest(reason.AnswerNotFound)
}
}
questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, req.QuestionID)
@ -250,12 +259,14 @@ func (as *AnswerService) updateAnswerRank(ctx context.Context, userID string,
log.Error(err)
}
}
err := as.answerActivityService.AcceptAnswer(
ctx, newAnswerInfo.ID, questionInfo.UserID, newAnswerInfo.UserID, newAnswerInfo.UserID == userID)
if err != nil {
log.Error(err)
if newAnswerInfo.ID != "" {
err := as.answerActivityService.AcceptAnswer(
ctx, newAnswerInfo.ID, questionInfo.UserID, newAnswerInfo.UserID, newAnswerInfo.UserID == userID)
if err != nil {
log.Error(err)
}
}
}
func (as *AnswerService) Get(ctx context.Context, answerID, loginUserId string) (*schema.AnswerInfo, *schema.QuestionInfo, bool, error) {