update inviteUser

This commit is contained in:
aichy126 2023-05-23 12:15:52 +08:00
parent bbf7849fb7
commit 80b6b786c5
6 changed files with 63 additions and 17 deletions

View File

@ -7618,6 +7618,12 @@ const docTemplate = `{
"maxLength": 65535, "maxLength": 65535,
"minLength": 6 "minLength": 6
}, },
"mention_username_list": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": { "tags": {
"description": "tags", "description": "tags",
"type": "array", "type": "array",
@ -7781,6 +7787,12 @@ const docTemplate = `{
"description": "question id", "description": "question id",
"type": "string" "type": "string"
}, },
"invite_user": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": { "tags": {
"description": "tags", "description": "tags",
"type": "array", "type": "array",

View File

@ -7606,6 +7606,12 @@
"maxLength": 65535, "maxLength": 65535,
"minLength": 6 "minLength": 6
}, },
"mention_username_list": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": { "tags": {
"description": "tags", "description": "tags",
"type": "array", "type": "array",
@ -7769,6 +7775,12 @@
"description": "question id", "description": "question id",
"type": "string" "type": "string"
}, },
"invite_user": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": { "tags": {
"description": "tags", "description": "tags",
"type": "array", "type": "array",

View File

@ -1218,6 +1218,10 @@ definitions:
maxLength: 65535 maxLength: 65535
minLength: 6 minLength: 6
type: string type: string
mention_username_list:
items:
type: string
type: array
tags: tags:
description: tags description: tags
items: items:
@ -1334,6 +1338,10 @@ definitions:
id: id:
description: question id description: question id
type: string type: string
invite_user:
items:
type: string
type: array
tags: tags:
description: tags description: tags
items: items:

View File

@ -61,8 +61,7 @@ type QuestionAdd struct {
// tags // tags
Tags []*TagItem `validate:"required,dive" json:"tags"` Tags []*TagItem `validate:"required,dive" json:"tags"`
// user id // user id
UserID string `json:"-"` UserID string `json:"-"`
InviteUser []string `validate:"omitempty" json:"invite_user"`
QuestionPermission QuestionPermission
} }
@ -141,7 +140,8 @@ type QuestionUpdate struct {
// content // content
Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"` Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"`
// html // html
HTML string `json:"-"` HTML string `json:"-"`
InviteUser []string `validate:"omitempty" json:"invite_user"`
// tags // tags
Tags []*TagItem `validate:"required,dive" json:"tags"` Tags []*TagItem `validate:"required,dive" json:"tags"`
// edit summary // edit summary

View File

@ -28,7 +28,6 @@ import (
usercommon "github.com/answerdev/answer/internal/service/user_common" usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/answerdev/answer/pkg/htmltext" "github.com/answerdev/answer/pkg/htmltext"
"github.com/answerdev/answer/pkg/uid" "github.com/answerdev/answer/pkg/uid"
"github.com/davecgh/go-spew/spew"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors" "github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/i18n" "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{} question := &entity.Question{}
now := time.Now() now := time.Now()
question.UserID = req.UserID question.UserID = req.UserID
@ -585,6 +577,27 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
return nil, err 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() now := time.Now()
question := &entity.Question{} question := &entity.Question{}
question.Title = req.Title question.Title = req.Title
@ -592,6 +605,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
question.ParsedText = req.HTML question.ParsedText = req.HTML
question.ID = uid.DeShortID(req.ID) question.ID = uid.DeShortID(req.ID)
question.UpdatedAt = now question.UpdatedAt = now
question.InviteUserID = inviteUserStr
question.PostUpdateTime = now question.PostUpdateTime = now
question.UserID = dbinfo.UserID question.UserID = dbinfo.UserID
question.LastEditUserID = req.UserID question.LastEditUserID = req.UserID
@ -685,7 +699,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
//Direct modification //Direct modification
revisionDTO.Status = entity.RevisionReviewPassStatus revisionDTO.Status = entity.RevisionReviewPassStatus
//update question to db //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 { if saveerr != nil {
return questionInfo, saveerr return questionInfo, saveerr
} }

View File

@ -75,17 +75,17 @@ func (us *UserCommon) GetUserBasicInfoByUserName(ctx context.Context, username s
return info, exist, nil return info, exist, nil
} }
func (us *UserCommon) BatchGetUserBasicInfoByUserNames(ctx context.Context, usernames []string) ([]*schema.UserBasicInfo, error) { func (us *UserCommon) BatchGetUserBasicInfoByUserNames(ctx context.Context, usernames []string) (map[string]*schema.UserBasicInfo, error) {
infolist := make([]*schema.UserBasicInfo, 0) infomap := make(map[string]*schema.UserBasicInfo)
list, err := us.userRepo.GetByUsernames(ctx, usernames) list, err := us.userRepo.GetByUsernames(ctx, usernames)
if err != nil { if err != nil {
return infolist, err return infomap, err
} }
for _, user := range list { for _, user := range list {
info := us.FormatUserBasicInfo(ctx, user) 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 { func (us *UserCommon) UpdateAnswerCount(ctx context.Context, userID string, num int) error {