Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update inviteUser

aichy12680b6b786c536
diff --git a/docs/docs.go b/docs/docs.go
index 3310c0b2..d2fe7190 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -7618,6 +7618,12 @@ const docTemplate = `{
"maxLength": 65535,
"minLength": 6
},
+ "mention_username_list": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
"tags": {
"description": "tags",
"type": "array",
@@ -7781,6 +7787,12 @@ const docTemplate = `{
"description": "question id",
"type": "string"
},
+ "invite_user": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
"tags": {
"description": "tags",
"type": "array",
diff --git a/docs/swagger.json b/docs/swagger.json
index d8bcb632..3a1afb34 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -7606,6 +7606,12 @@
"maxLength": 65535,
"minLength": 6
},
+ "mention_username_list": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
"tags": {
"description": "tags",
"type": "array",
@@ -7769,6 +7775,12 @@
"description": "question id",
"type": "string"
},
+ "invite_user": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
"tags": {
"description": "tags",
"type": "array",
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index a97803db..b73f8efe 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1218,6 +1218,10 @@ definitions:
maxLength: 65535
minLength: 6
type: string
+ mention_username_list:
+ items:
+ type: string
+ type: array
tags:
description: tags
items:
@@ -1334,6 +1338,10 @@ definitions:
id:
description: question id
type: string
+ invite_user:
+ items:
+ type: string
+ type: array
tags:
description: tags
items:
diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go
index 9a0f4073..9ef45d7a 100644
--- a/internal/schema/question_schema.go
+++ b/internal/schema/question_schema.go
@@ -61,8 +61,7 @@ type QuestionAdd struct {
// tags
Tags []*TagItem `validate:"required,dive" json:"tags"`
// user id
- UserID string `json:"-"`
- InviteUser []string `validate:"omitempty" json:"invite_user"`
+ UserID string `json:"-"`
QuestionPermission
}
@@ -141,7 +140,8 @@ type QuestionUpdate struct {
// content
Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"`
// html
- HTML string `json:"-"`
+ HTML string `json:"-"`
+ InviteUser []string `validate:"omitempty" json:"invite_user"`
// tags
Tags []*TagItem `validate:"required,dive" json:"tags"`
// edit summary
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index 7c141123..73c89386 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -28,7 +28,6 @@ import (
usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/answerdev/answer/pkg/htmltext"
"github.com/answerdev/answer/pkg/uid"
- "github.com/davecgh/go-spew/spew"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/i18n"
@@ -259,13 +258,6 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
}
}
- //verify invite user
- inviteUserInfoList, err := qs.userCommon.BatchGetUserBasicInfoByUserNames(ctx, req.InviteUser)
- if err != nil {
- log.Error("BatchGetUserBasicInfoByUserNames error", err.Error())
- }
- spew.Dump(inviteUserInfoList)
-
question := &entity.Question{}
now := time.Now()
question.UserID = req.UserID
@@ -585,6 +577,27 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
return nil, err
}
+ //verify invite user
+ inviteUserInfoList, err := qs.userCommon.BatchGetUserBasicInfoByUserNames(ctx, req.InviteUser)
+ if err != nil {
+ log.Error("BatchGetUserBasicInfoByUserNames error", err.Error())
+ }
+ inviteUser := make([]string, 0)
+ for _, item := range req.InviteUser {
+ _, ok := inviteUserInfoList[item]
+ if ok {
+ inviteUser = append(inviteUser, inviteUserInfoList[item].ID)
+ }
+ }
+ inviteUserStr := ""
+ inviteUserByte, err := json.Marshal(inviteUser)
+ if err != nil {
+ log.Error("json.Marshal error", err.Error())
+ inviteUserStr = "[]"
+ } else {
+ inviteUserStr = string(inviteUserByte)
+ }
+
now := time.Now()
question := &entity.Question{}
question.Title = req.Title
@@ -592,6 +605,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
question.ParsedText = req.HTML
question.ID = uid.DeShortID(req.ID)
question.UpdatedAt = now
+ question.InviteUserID = inviteUserStr
question.PostUpdateTime = now
question.UserID = dbinfo.UserID
question.LastEditUserID = req.UserID
@@ -685,7 +699,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
//Direct modification
revisionDTO.Status = entity.RevisionReviewPassStatus
//update question to db
- saveerr := qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at", "post_update_time", "last_edit_user_id"})
+ saveerr := qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at", "post_update_time", "last_edit_user_id", "invite_user_id"})
if saveerr != nil {
return questionInfo, saveerr
}
diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.go
index d7845f22..54f4bf64 100644
--- a/internal/service/user_common/user.go
+++ b/internal/service/user_common/user.go
@@ -75,17 +75,17 @@ func (us *UserCommon) GetUserBasicInfoByUserName(ctx context.Context, username s
return info, exist, nil
}
-func (us *UserCommon) BatchGetUserBasicInfoByUserNames(ctx context.Context, usernames []string) ([]*schema.UserBasicInfo, error) {
- infolist := make([]*schema.UserBasicInfo, 0)
+func (us *UserCommon) BatchGetUserBasicInfoByUserNames(ctx context.Context, usernames []string) (map[string]*schema.UserBasicInfo, error) {
+ infomap := make(map[string]*schema.UserBasicInfo)
list, err := us.userRepo.GetByUsernames(ctx, usernames)
if err != nil {
- return infolist, err
+ return infomap, err
}
for _, user := range list {
info := us.FormatUserBasicInfo(ctx, user)
- infolist = append(infolist, info)
+ infomap[user.Username] = info
}
- return infolist, nil
+ return infomap, nil
}
func (us *UserCommon) UpdateAnswerCount(ctx context.Context, userID string, num int) error {