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 invite
aichy126bbf7849fb7f6
diff --git a/internal/entity/question_entity.go b/internal/entity/question_entity.goindex 41c9236b..bfcc24ef 100644--- a/internal/entity/question_entity.go+++ b/internal/entity/question_entity.go@@ -32,6 +32,7 @@ type Question struct {CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`UpdatedAt time.Time `xorm:"updated_at TIMESTAMP"`UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`+ InviteUserID string `xorm:"TEXT invite_user_id"`LastEditUserID string `xorm:"not null default 0 BIGINT(20) last_edit_user_id"`Title string `xorm:"not null default '' VARCHAR(150) title"`OriginalText string `xorm:"not null MEDIUMTEXT original_text"`diff --git a/internal/migrations/v13.go b/internal/migrations/v13.goindex f86f38f8..74ae8aea 100644--- a/internal/migrations/v13.go+++ b/internal/migrations/v13.go@@ -2,6 +2,7 @@ package migrationsimport ("fmt"+ "time""github.com/answerdev/answer/internal/entity""github.com/segmentfault/pacman/log"@@ -13,6 +14,7 @@ func updateCount(x *xorm.Engine) error {updateTagCount(x)updateUserQuestionCount(x)updateUserAnswerCount(x)+ inviteAnswer(x)return nil}@@ -215,3 +217,36 @@ func updateUserAnswerCount(x *xorm.Engine) error {}return nil}++func inviteAnswer(x *xorm.Engine) error {+ type Question struct {+ ID string `xorm:"not null pk BIGINT(20) id"`+ CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`+ UpdatedAt time.Time `xorm:"updated_at TIMESTAMP"`+ UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`+ InviteUserID string `xorm:"TEXT invite_user_id"`+ LastEditUserID string `xorm:"not null default 0 BIGINT(20) last_edit_user_id"`+ Title string `xorm:"not null default '' VARCHAR(150) title"`+ OriginalText string `xorm:"not null MEDIUMTEXT original_text"`+ ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`+ Status int `xorm:"not null default 1 INT(11) status"`+ Pin int `xorm:"not null default 1 INT(11) pin"`+ Show int `xorm:"not null default 1 INT(11) show"`+ ViewCount int `xorm:"not null default 0 INT(11) view_count"`+ UniqueViewCount int `xorm:"not null default 0 INT(11) unique_view_count"`+ VoteCount int `xorm:"not null default 0 INT(11) vote_count"`+ AnswerCount int `xorm:"not null default 0 INT(11) answer_count"`+ CollectionCount int `xorm:"not null default 0 INT(11) collection_count"`+ FollowCount int `xorm:"not null default 0 INT(11) follow_count"`+ AcceptedAnswerID string `xorm:"not null default 0 BIGINT(20) accepted_answer_id"`+ LastAnswerID string `xorm:"not null default 0 BIGINT(20) last_answer_id"`+ PostUpdateTime time.Time `xorm:"post_update_time TIMESTAMP"`+ RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`+ }+ err := x.Sync(new(Question))+ if err != nil {+ return err+ }++ return nil+}diff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.goindex 53c46ca0..b26bcaa1 100644--- a/internal/repo/user/user_repo.go+++ b/internal/repo/user/user_repo.go@@ -195,6 +195,17 @@ func (ur *userRepo) GetByUsername(ctx context.Context, username string) (userInfreturn}+func (ur *userRepo) GetByUsernames(ctx context.Context, usernames []string) ([]*entity.User, error) {+ list := make([]*entity.User, 0)+ err := ur.data.DB.Where("status =?", entity.UserStatusAvailable).In("username", usernames).Find(&list)+ if err != nil {+ err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ return list, err+ }+ tryToDecorateUserListFromUserCenter(ctx, ur.data, list)+ return list, nil+}+// GetByEmail get user by emailfunc (ur *userRepo) GetByEmail(ctx context.Context, email string) (userInfo *entity.User, exist bool, err error) {userInfo = &entity.User{}diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.goindex 60af4f14..9a0f4073 100644--- a/internal/schema/question_schema.go+++ b/internal/schema/question_schema.go@@ -61,7 +61,8 @@ type QuestionAdd struct {// tagsTags []*TagItem `validate:"required,dive" json:"tags"`// user id- UserID string `json:"-"`+ UserID string `json:"-"`+ InviteUser []string `validate:"omitempty" json:"invite_user"`QuestionPermission}@@ -87,7 +88,8 @@ type QuestionAddByAnswer struct {// tagsTags []*TagItem `validate:"required,dive" json:"tags"`// user id- UserID string `json:"-"`+ UserID string `json:"-"`+ MentionUsernameList []string `validate:"omitempty" json:"mention_username_list"`QuestionPermission}diff --git a/internal/service/question_service.go b/internal/service/question_service.goindex 25820563..7c141123 100644--- a/internal/service/question_service.go+++ b/internal/service/question_service.go@@ -28,6 +28,7 @@ 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"@@ -258,6 +259,13 @@ 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.UserIDdiff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.goindex c5786746..d7845f22 100644--- a/internal/service/user_common/user.go+++ b/internal/service/user_common/user.go@@ -32,6 +32,7 @@ type UserRepo interface {GetByUserID(ctx context.Context, userID string) (userInfo *entity.User, exist bool, err error)BatchGetByID(ctx context.Context, ids []string) ([]*entity.User, error)GetByUsername(ctx context.Context, username string) (userInfo *entity.User, exist bool, err error)+ GetByUsernames(ctx context.Context, usernames []string) ([]*entity.User, error)GetByEmail(ctx context.Context, email string) (userInfo *entity.User, exist bool, err error)GetUserCount(ctx context.Context) (count int64, err error)}@@ -74,6 +75,19 @@ func (us *UserCommon) GetUserBasicInfoByUserName(ctx context.Context, username sreturn info, exist, nil}+func (us *UserCommon) BatchGetUserBasicInfoByUserNames(ctx context.Context, usernames []string) ([]*schema.UserBasicInfo, error) {+ infolist := make([]*schema.UserBasicInfo, 0)+ list, err := us.userRepo.GetByUsernames(ctx, usernames)+ if err != nil {+ return infolist, err+ }+ for _, user := range list {+ info := us.FormatUserBasicInfo(ctx, user)+ infolist = append(infolist, info)+ }+ return infolist, nil+}+func (us *UserCommon) UpdateAnswerCount(ctx context.Context, userID string, num int) error {return us.userRepo.UpdateAnswerCount(ctx, userID, num)}