mirror of https://gitee.com/answerdev/answer.git
fix Adopted
This commit is contained in:
parent
60dfc74301
commit
a116c39e11
|
@ -9,7 +9,7 @@
|
|||
/.vscode/*.log
|
||||
/cmd/answer/*.sh
|
||||
/cmd/logs
|
||||
/configs/*
|
||||
/configs/config-dev.yaml
|
||||
/go.work*
|
||||
/logs
|
||||
/ui/build
|
||||
|
|
|
@ -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: ""
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue