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.
feat: all users display part Add user status
LinkinStarb90ec5e11ebf
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.goindex 120f515a..6579ba25 100644--- a/cmd/answer/wire_gen.go+++ b/cmd/answer/wire_gen.go@@ -102,13 +102,14 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,userController := controller.NewUserController(authService, userService, captchaService, emailService, uploaderService)commentRepo := comment.NewCommentRepo(dataData, uniqueIDRepo)commentCommonRepo := comment.NewCommentCommonRepo(dataData, uniqueIDRepo)+ userCommon := usercommon.NewUserCommon(userRepo)answerRepo := repo.NewAnswerRepo(dataData, uniqueIDRepo, userRankRepo, activityRepo)questionRepo := repo.NewQuestionRepo(dataData, uniqueIDRepo)tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo)objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagRepo)voteRepo := activity_common.NewVoteRepo(dataData, activityRepo)- commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userRepo, objService, voteRepo)- rankService := rank2.NewRankService(userRepo, userRankRepo, objService, configRepo)+ commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo)+ rankService := rank2.NewRankService(userCommon, userRankRepo, objService, configRepo)commentController := controller.NewCommentController(commentService, rankService)reportRepo := report.NewReportRepo(dataData, uniqueIDRepo)reportService := report2.NewReportService(reportRepo, objService)@@ -128,7 +129,6 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,collectionGroupRepo := collection.NewCollectionGroupRepo(dataData)tagRelRepo := tag.NewTagListRepo(dataData)tagCommonService := tagcommon.NewTagCommonService(tagRepo, tagRelRepo, revisionService)- userCommon := usercommon.NewUserCommon(userRepo)collectionCommon := collectioncommon.NewCollectionCommon(collectionRepo)answerCommon := answercommon.NewAnswerCommon(answerRepo)metaRepo := meta.NewMetaRepo(dataData)@@ -143,10 +143,10 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,questionController := controller.NewQuestionController(questionService, rankService)answerService := service.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo)answerController := controller.NewAnswerController(answerService, rankService)- searchRepo := repo.NewSearchRepo(dataData, uniqueIDRepo, userRepo)- searchService := service.NewSearchService(searchRepo, tagRepo, userRepo, followRepo)+ searchRepo := repo.NewSearchRepo(dataData, uniqueIDRepo, userCommon)+ searchService := service.NewSearchService(searchRepo, tagRepo, userCommon, followRepo)searchController := controller.NewSearchController(searchService)- serviceRevisionService := service.NewRevisionService(revisionRepo, userRepo, questionCommon, answerService)+ serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService)revisionController := controller.NewRevisionController(serviceRevisionService)rankController := controller.NewRankController(rankService)commonRepo := common.NewCommonRepo(dataData, uniqueIDRepo)diff --git a/docs/docs.go b/docs/docs.goindex 577af397..b9b29980 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -4246,6 +4246,10 @@ const docTemplate = `{"description": "reply user id","type": "string"},+ "reply_user_status": {+ "description": "reply user status",+ "type": "string"+ },"reply_username": {"description": "reply user username","type": "string"@@ -4262,6 +4266,10 @@ const docTemplate = `{"description": "user id","type": "string"},+ "user_status": {+ "description": "user status",+ "type": "string"+ },"username": {"description": "username","type": "string"@@ -5504,7 +5512,7 @@ const docTemplate = `{},"status": {"description": "status",- "type": "integer"+ "type": "string"},"username": {"description": "name",diff --git a/docs/swagger.json b/docs/swagger.jsonindex 2661dd62..f76df152 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -4234,6 +4234,10 @@"description": "reply user id","type": "string"},+ "reply_user_status": {+ "description": "reply user status",+ "type": "string"+ },"reply_username": {"description": "reply user username","type": "string"@@ -4250,6 +4254,10 @@"description": "user id","type": "string"},+ "user_status": {+ "description": "user status",+ "type": "string"+ },"username": {"description": "username","type": "string"@@ -5492,7 +5500,7 @@},"status": {"description": "status",- "type": "integer"+ "type": "string"},"username": {"description": "name",diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex 5871e940..3800c298 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -299,6 +299,9 @@ definitions:reply_user_id:description: reply user idtype: string+ reply_user_status:+ description: reply user status+ type: stringreply_username:description: reply user usernametype: string@@ -311,6 +314,9 @@ definitions:user_id:description: user idtype: string+ user_status:+ description: user status+ type: stringusername:description: usernametype: string@@ -1209,7 +1215,7 @@ definitions:type: integerstatus:description: status- type: integer+ type: stringusername:description: nametype: stringdiff --git a/go.mod b/go.modindex 08c2a30c..2ebab9eb 100644--- a/go.mod+++ b/go.mod@@ -19,17 +19,17 @@ require (github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatiblegithub.com/mojocn/base64Captcha v1.3.5github.com/segmentfault/pacman v1.0.1- github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220926035018-18f894415e5b- github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220926035018-18f894415e5b- github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220926035018-18f894415e5b- github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220926035018-18f894415e5b- github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220926035018-18f894415e5b+ github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347+ github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220929065758-260b3093a347+ github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220929065758-260b3093a347+ github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220929065758-260b3093a347+ github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220929065758-260b3093a347github.com/stretchr/testify v1.8.0github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97agithub.com/swaggo/gin-swagger v1.5.3github.com/swaggo/swag v1.8.6golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be- golang.org/x/net v0.0.0-20220926192436-02166a98028e+ golang.org/x/net v0.0.0-20220927171203-f486391704dcxorm.io/builder v0.3.12xorm.io/core v0.7.3xorm.io/xorm v1.3.2@@ -76,7 +76,7 @@ require (go.uber.org/multierr v1.8.0 // indirectgo.uber.org/zap v1.23.0 // indirectgolang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect- golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 // indirect+ golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirectgolang.org/x/text v0.3.7 // indirectgolang.org/x/tools v0.1.12 // indirectgoogle.golang.org/protobuf v1.28.1 // indirectdiff --git a/go.sum b/go.sumindex 902e19fb..3d5ad3eb 100644--- a/go.sum+++ b/go.sum@@ -525,14 +525,24 @@ github.com/segmentfault/pacman v1.0.1 h1:GFdvPtNxvVVjnDM4ty02D/+4unHwG9PmjcOZSc2github.com/segmentfault/pacman v1.0.1/go.mod h1:5lNp5REd8QMThmBUvR3Fi9Y3AsOB4GRq7soCB4QLqOs=github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220926035018-18f894415e5b h1:jSnRy3z3KVtVuGM2YTZihXwc4zEhW+TvyyJbBm8rjh4=github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220926035018-18f894415e5b/go.mod h1:rmf1TCwz67dyM+AmTwSd1BxTo2AOYHj262lP93bOZbs=+github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347 h1:0xWBBXHHuemzMY61KYJXh7F5FW/4K8g98RYKNXodTCc=+github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347/go.mod h1:rmf1TCwz67dyM+AmTwSd1BxTo2AOYHj262lP93bOZbs=github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220926035018-18f894415e5b h1:Gx3Brm+VMAyBJn4aBsxgKl+EIhFHc/YH5cLGeFHAW4g=github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220926035018-18f894415e5b/go.mod h1:prPjFam7MyZ5b3S9dcDOt2tMPz6kf7C9c243s9zSwPY=+github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220929065758-260b3093a347 h1:WpnEbmZFE8FYIgvseX+NJtDgGJlM1KSaKJhoxJywUgo=+github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20220929065758-260b3093a347/go.mod h1:prPjFam7MyZ5b3S9dcDOt2tMPz6kf7C9c243s9zSwPY=github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220926035018-18f894415e5b h1:uQmSgcV2w4OVXU6l3bQb9O+cSAVuzDQ9adJArQyFBa4=github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220926035018-18f894415e5b/go.mod h1:5Afm+OQdau/HQqSOp/ALlSUp0vZsMMMbv//kJhxuoi8=+github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220929065758-260b3093a347 h1:Q29Ky9ZUGhdLIygfX6jwPYeEa7Wqn8o3f1NJWb8LvvE=+github.com/segmentfault/pacman/contrib/i18n v0.0.0-20220929065758-260b3093a347/go.mod h1:5Afm+OQdau/HQqSOp/ALlSUp0vZsMMMbv//kJhxuoi8=github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220926035018-18f894415e5b h1:TaOBmAglooq+qKdnNTK2sy11t26ud7psHFB7/AV7l5U=github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220926035018-18f894415e5b/go.mod h1:L4GqtXLoR73obTYqUQIzfkm8NG8pvZafxFb6KZFSSHk=+github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220929065758-260b3093a347 h1:7Adjc296AKv32dg88S0T8t9K3+N+PFYLSCctpPnCUr0=+github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20220929065758-260b3093a347/go.mod h1:L4GqtXLoR73obTYqUQIzfkm8NG8pvZafxFb6KZFSSHk=github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220926035018-18f894415e5b h1:n5n5VPeYGuZCmVppKPgWR/CaINHnL+ipEp9iE1XkcQc=github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220926035018-18f894415e5b/go.mod h1:UjNiOFYv1uGCq1ZCcONaKq4eE7MW3nbgpLqgl8f9N40=+github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220929065758-260b3093a347 h1:CfuRhTPK2CBQIZruq5ceuTVthspe8U1FDjWXXI2RWdo=+github.com/segmentfault/pacman/contrib/server/http v0.0.0-20220929065758-260b3093a347/go.mod h1:UjNiOFYv1uGCq1ZCcONaKq4eE7MW3nbgpLqgl8f9N40=github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=@@ -737,6 +747,8 @@ golang.org/x/net v0.0.0-20220923203811-8be639271d50 h1:vKyz8L3zkd+xrMeIaBsQ/MNVPgolang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=golang.org/x/net v0.0.0-20220926192436-02166a98028e h1:I51lVG9ykW5AQeTE50sJ0+gJCAF0J78Hf1+1VUCGxDI=golang.org/x/net v0.0.0-20220926192436-02166a98028e/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=+golang.org/x/net v0.0.0-20220927171203-f486391704dc h1:FxpXZdoBqT8RjqTy6i1E8nXHhW21wK7ptQ/EPIGxzPQ=+golang.org/x/net v0.0.0-20220927171203-f486391704dc/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=@@ -821,6 +833,8 @@ golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAgolang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 h1:nwzwVf0l2Y/lkov/+IYgMMbFyI+QypZDds9RxlSmsFQ=golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=+golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.goindex e8dfc000..5865e1ef 100644--- a/internal/base/constant/constant.go+++ b/internal/base/constant/constant.go@@ -13,6 +13,7 @@ const (UserTokenCacheTime = 7 * 24 * time.HourAdminTokenCacheKey = "answer:admin:token:"AdminTokenCacheTime = 7 * 24 * time.Hour+ AcceptLanguageFlag = "Accept-Language")const (diff --git a/internal/base/handler/handler.go b/internal/base/handler/handler.goindex 774db9ab..ea06a945 100644--- a/internal/base/handler/handler.go+++ b/internal/base/handler/handler.go@@ -5,6 +5,7 @@ import ("net/http""github.com/gin-gonic/gin"+ "github.com/segmentfault/answer/internal/base/constant""github.com/segmentfault/answer/internal/base/reason""github.com/segmentfault/answer/internal/base/validator"myErrors "github.com/segmentfault/pacman/errors"@@ -44,13 +45,15 @@ func HandleResponse(ctx *gin.Context, err error, data interface{}) {// BindAndCheck bind request and checkfunc BindAndCheck(ctx *gin.Context, data interface{}) bool {+ lang := GetLang(ctx)+ ctx.Set(constant.AcceptLanguageFlag, lang)if err := ctx.ShouldBind(data); err != nil {log.Errorf("http_handle BindAndCheck fail, %s", err.Error())HandleResponse(ctx, myErrors.New(http.StatusBadRequest, reason.RequestFormatError), nil)return true}- errField, err := validator.GetValidatorByLang(GetLang(ctx).Abbr()).Check(data)+ errField, err := validator.GetValidatorByLang(lang.Abbr()).Check(data)if err != nil {HandleResponse(ctx, myErrors.New(http.StatusBadRequest, reason.RequestFormatError).WithMsg(err.Error()), errField)return truediff --git a/internal/base/handler/lang.go b/internal/base/handler/lang.goindex 38bbccf1..c55c1e5d 100644--- a/internal/base/handler/lang.go+++ b/internal/base/handler/lang.go@@ -2,12 +2,13 @@ package handlerimport ("github.com/gin-gonic/gin"+ "github.com/segmentfault/answer/internal/base/constant""github.com/segmentfault/pacman/i18n")// GetLang get language from headerfunc GetLang(ctx *gin.Context) i18n.Language {- acceptLanguage := ctx.GetHeader("Accept-Language")+ acceptLanguage := ctx.GetHeader(constant.AcceptLanguageFlag)switch i18n.Language(acceptLanguage) {case i18n.LanguageChinese:return i18n.LanguageChinesediff --git a/internal/base/pager/pagination.go b/internal/base/pager/pagination.goindex 239c2945..fecf05e1 100644--- a/internal/base/pager/pagination.go+++ b/internal/base/pager/pagination.go@@ -17,7 +17,7 @@ type PageCond struct {}// NewPageModel new page model-func NewPageModel(page, pageSize int, totalRecords int64, records interface{}) *PageModel {+func NewPageModel(totalRecords int64, records interface{}) *PageModel {sliceValue := reflect.Indirect(reflect.ValueOf(records))if sliceValue.Kind() != reflect.Slice {panic("not a slice")diff --git a/internal/controller/notification_controller.go b/internal/controller/notification_controller.goindex 31770c7e..fc05efda 100644--- a/internal/controller/notification_controller.go+++ b/internal/controller/notification_controller.go@@ -93,16 +93,16 @@ func (nc *NotificationController) ClearIDUnRead(ctx *gin.Context) {handler.HandleResponse(ctx, err, gin.H{})}-// GetList-// @Summary GetRedDot-// @Description GetRedDot+// GetList get notification list+// @Summary get notification list+// @Description get notification list// @Tags Notification// @Accept json// @Produce json// @Security ApiKeyAuth// @Param page query int false "page size"// @Param page_size query int false "page size"-// @Param type query string false "type" Enums(inbox,achievement)+// @Param type query string true "type" Enums(inbox,achievement)// @Success 200 {object} handler.RespBody// @Router /answer/api/v1/notification/page [get]func (nc *NotificationController) GetList(ctx *gin.Context) {@@ -111,9 +111,6 @@ func (nc *NotificationController) GetList(ctx *gin.Context) {return}req.UserID = middleware.GetLoginUserIDFromContext(ctx)- list, count, err := nc.notificationService.GetList(ctx, req)- handler.HandleResponse(ctx, err, gin.H{- "list": list,- "count": count,- })+ resp, err := nc.notificationService.GetList(ctx, req)+ handler.HandleResponse(ctx, err, resp)}diff --git a/internal/repo/search_repo.go b/internal/repo/search_repo.goindex ff042da5..c190f0d0 100644--- a/internal/repo/search_repo.go+++ b/internal/repo/search_repo.go@@ -22,16 +22,16 @@ import (// searchRepo tag repositorytype searchRepo struct {data *data.Data- userRepo usercommon.UserRepo+ userCommon *usercommon.UserCommonuniqueIDRepo unique.UniqueIDRepo}// NewSearchRepo new repository-func NewSearchRepo(data *data.Data, uniqueIDRepo unique.UniqueIDRepo, userRepo usercommon.UserRepo) search_common.SearchRepo {+func NewSearchRepo(data *data.Data, uniqueIDRepo unique.UniqueIDRepo, userCommon *usercommon.UserCommon) search_common.SearchRepo {return &searchRepo{data: data,uniqueIDRepo: uniqueIDRepo,- userRepo: userRepo,+ userCommon: userCommon,}}@@ -213,9 +213,7 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAcfunc (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte) (resp []schema.SearchResp, err error) {for _, r := range res {var (- objectKey string- uInfo *schema.UserBasicInfo-+ objectKey stringtags []schema.TagResptagsEntity []entity.Tagobject schema.SearchObject@@ -228,16 +226,12 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte)tp, _ := time.ParseInLocation("2006-01-02 15:04:05", string(r["created_at"]), time.Local)// get user info- userInfo, exist, e := sr.userRepo.GetByUserID(ctx, string(r["user_id"]))+ userInfo, _, e := sr.userCommon.GetUserBasicInfoByID(ctx, string(r["user_id"]))if e != nil {err = errors.InternalServer(reason.DatabaseError).WithError(e).WithStack()return}- if exist {- uInfo = sr.userBasicInfoFormat(ctx, userInfo)- }-// get tagserr = sr.data.DB.Select("`display_name`,`slug_name`,`main_tag_slug_name`").@@ -258,7 +252,7 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte)Title: string(r["title"]),Excerpt: cutOutParsedText(string(r["original_text"])),CreatedAtParsed: tp.Unix(),- UserInfo: uInfo,+ UserInfo: userInfo,Tags: tags,VoteCount: converter.StringToInt(string(r["vote_count"])),Accepted: string(r["accepted"]) == "2",@@ -275,8 +269,8 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte)// userBasicInfoFormatfunc (sr *searchRepo) userBasicInfoFormat(ctx context.Context, dbinfo *entity.User) *schema.UserBasicInfo {return &schema.UserBasicInfo{- UserId: dbinfo.ID,- UserName: dbinfo.Username,+ ID: dbinfo.ID,+ Username: dbinfo.Username,Rank: dbinfo.Rank,DisplayName: dbinfo.DisplayName,Avatar: dbinfo.Avatar,diff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.goindex 49968e7b..74c4111c 100644--- a/internal/schema/answer_schema.go+++ b/internal/schema/answer_schema.go@@ -1,95 +1,13 @@package schema-import (- "time"-)-// RemoveAnswerReq delete answer requesttype RemoveAnswerReq struct {// answer id- ID string `validate:"required" comment:"answer id" json:"id"`+ ID string `validate:"required" json:"id"`// user idUserID string `json:"-"`}-// GetAnswerListReq get answer list all request-type GetAnswerListReq struct {- // question id- QuestionID int64 `validate:"omitempty" comment:"question id" form:"question_id"`- // answer user id- UserID int64 `validate:"omitempty" comment:"answer user id" form:"user_id"`- // content markdown- Content string `validate:"omitempty" comment:"content markdown" form:"content"`- // content html- Html string `validate:"omitempty" comment:"content html" form:"html"`- // answer status(available: 1; deleted: 10)- Status int `validate:"omitempty" comment:" answer status(available: 1; deleted: 10)" form:"status"`- // adopted (1 failed 2 adopted)- Adopted int `validate:"omitempty" comment:"adopted (1 failed 2 adopted)" form:"adopted"`- // comment count- CommentCount int `validate:"omitempty" comment:"comment count" form:"comment_count"`- // vote count- VoteCount int `validate:"omitempty" comment:"vote count" form:"vote_count"`- //- CreateTime time.Time `validate:"omitempty" comment:"" form:"create_time"`- //- UpdateTime time.Time `validate:"omitempty" comment:"" form:"update_time"`-}--// GetAnswerWithPageReq get answer list page request-type GetAnswerWithPageReq struct {- // page- Page int `validate:"omitempty,min=1" form:"page"`- // page size- PageSize int `validate:"omitempty,min=1" form:"page_size"`- // question id- QuestionID int64 `validate:"omitempty" comment:"question id" form:"question_id"`- // answer user id- UserID int64 `validate:"omitempty" comment:"answer user id" form:"user_id"`- // content markdown- Content string `validate:"omitempty" comment:"content markdown" form:"content"`- // content html- Html string `validate:"omitempty" comment:"content html" form:"html"`- // answer status(available: 1; deleted: 10)- Status int `validate:"omitempty" comment:" answer status(available: 1; deleted: 10)" form:"status"`- // adopted (1 failed 2 adopted)- Adopted int `validate:"omitempty" comment:"adopted (1 failed 2 adopted)" form:"adopted"`- // comment count- CommentCount int `validate:"omitempty" comment:"comment count" form:"comment_count"`- // vote count- VoteCount int `validate:"omitempty" comment:"vote count" form:"vote_count"`- //- CreateTime time.Time `validate:"omitempty" comment:"" form:"create_time"`- //- UpdateTime time.Time `validate:"omitempty" comment:"" form:"update_time"`-}--// GetAnswerResp get answer response-type GetAnswerResp struct {- // answer id- ID int64 `json:"id"`- // question id- QuestionID int64 `json:"question_id"`- // answer user id- UserID int64 `json:"user_id"`- // content markdown- Content string `json:"content"`- // content html- Html string `json:"html"`- // answer status(available: 1; deleted: 10)- Status int `json:"status"`- // adopted (1 failed 2 adopted)- Adopted int `json:"adopted"`- // comment count- CommentCount int `json:"comment_count"`- // vote count- VoteCount int `json:"vote_count"`- //- CreateTime time.Time `json:"create_time"`- //- UpdateTime time.Time `json:"update_time"`-}-const (Answer_Adopted_Failed = 1Answer_Adopted_Enable = 2diff --git a/internal/schema/backyard_user_schema.go b/internal/schema/backyard_user_schema.goindex 690bbfc9..bccf1b63 100644--- a/internal/schema/backyard_user_schema.go+++ b/internal/schema/backyard_user_schema.go@@ -9,16 +9,16 @@ type UpdateUserStatusReq struct {}const (- Normal = "normal"- Suspended = "suspended"- Deleted = "deleted"- Inactive = "inactive"+ UserNormal = "normal"+ UserSuspended = "suspended"+ UserDeleted = "deleted"+ UserInactive = "inactive")-func (r *UpdateUserStatusReq) IsNormal() bool { return r.Status == Normal }-func (r *UpdateUserStatusReq) IsSuspended() bool { return r.Status == Suspended }-func (r *UpdateUserStatusReq) IsDeleted() bool { return r.Status == Deleted }-func (r *UpdateUserStatusReq) IsInactive() bool { return r.Status == Inactive }+func (r *UpdateUserStatusReq) IsNormal() bool { return r.Status == UserNormal }+func (r *UpdateUserStatusReq) IsSuspended() bool { return r.Status == UserSuspended }+func (r *UpdateUserStatusReq) IsDeleted() bool { return r.Status == UserDeleted }+func (r *UpdateUserStatusReq) IsInactive() bool { return r.Status == UserInactive }// GetUserPageReq get user list page requesttype GetUserPageReq struct {@@ -34,9 +34,9 @@ type GetUserPageReq struct {Status string `validate:"omitempty,oneof=suspended deleted inactive" form:"status"`}-func (r *GetUserPageReq) IsSuspended() bool { return r.Status == Suspended }-func (r *GetUserPageReq) IsDeleted() bool { return r.Status == Deleted }-func (r *GetUserPageReq) IsInactive() bool { return r.Status == Inactive }+func (r *GetUserPageReq) IsSuspended() bool { return r.Status == UserSuspended }+func (r *GetUserPageReq) IsDeleted() bool { return r.Status == UserDeleted }+func (r *GetUserPageReq) IsInactive() bool { return r.Status == UserInactive }// GetUserPageResp get user responsetype GetUserPageResp struct {diff --git a/internal/schema/collection_group_schema.go b/internal/schema/collection_group_schema.goindex a8c5a6bd..19d6f4d5 100644--- a/internal/schema/collection_group_schema.go+++ b/internal/schema/collection_group_schema.go@@ -43,12 +43,6 @@ type AddCollectionGroupReq struct {UpdateTime time.Time `validate:"required" comment:"" json:"update_time"`}-// RemoveCollectionGroupReq delete collection group request-type RemoveCollectionGroupReq struct {- //- ID int64 `validate:"required" comment:"" json:"id"`-}-// UpdateCollectionGroupReq update collection group requesttype UpdateCollectionGroupReq struct {//@@ -65,38 +59,6 @@ type UpdateCollectionGroupReq struct {UpdateTime time.Time `validate:"omitempty" comment:"" json:"update_time"`}-// GetCollectionGroupListReq get collection group list all request-type GetCollectionGroupListReq struct {- //- UserID int64 `validate:"omitempty" comment:"" form:"user_id"`- // the collection group name- Name string `validate:"omitempty,gt=0,lte=50" comment:"the collection group name" form:"name"`- // mark this group is default, default 1- DefaultGroup int `validate:"omitempty" comment:"mark this group is default, default 1" form:"default_group"`- //- CreateTime time.Time `validate:"omitempty" comment:"" form:"create_time"`- //- UpdateTime time.Time `validate:"omitempty" comment:"" form:"update_time"`-}--// GetCollectionGroupWithPageReq get collection group list page request-type GetCollectionGroupWithPageReq struct {- // page- Page int `validate:"omitempty,min=1" form:"page"`- // page size- PageSize int `validate:"omitempty,min=1" form:"page_size"`- //- UserID int64 `validate:"omitempty" comment:"" form:"user_id"`- // the collection group name- Name string `validate:"omitempty,gt=0,lte=50" comment:"the collection group name" form:"name"`- // mark this group is default, default 1- DefaultGroup int `validate:"omitempty" comment:"mark this group is default, default 1" form:"default_group"`- //- CreateTime time.Time `validate:"omitempty" comment:"" form:"create_time"`- //- UpdateTime time.Time `validate:"omitempty" comment:"" form:"update_time"`-}-// GetCollectionGroupResp get collection group responsetype GetCollectionGroupResp struct {//diff --git a/internal/schema/collection_schema.go b/internal/schema/collection_schema.godeleted file mode 100644index af549e6f..00000000--- a/internal/schema/collection_schema.go+++ /dev/null@@ -1,87 +0,0 @@-package schema--import "time"--// AddCollectionReq add collection request-type AddCollectionReq struct {- // user id- UserID int64 `validate:"required" comment:"user id" json:"user_id"`- // object id- ObjectID int64 `validate:"required" comment:"object id" json:"object_id"`- // user collection group id- UserCollectionGroupID int64 `validate:"required" comment:"user collection group id" json:"user_collection_group_id"`- //- CreateTime time.Time `validate:"required" comment:"" json:"create_time"`- //- UpdateTime time.Time `validate:"required" comment:"" json:"update_time"`-}--// RemoveCollectionReq delete collection request-type RemoveCollectionReq struct {- // collection id- ID int64 `validate:"required" comment:"collection id" json:"id"`-}--// UpdateCollectionReq update collection request-type UpdateCollectionReq struct {- // collection id- ID int64 `validate:"required" comment:"collection id" json:"id"`- // user id- UserID int64 `validate:"omitempty" comment:"user id" json:"user_id"`- // object id- ObjectID int64 `validate:"omitempty" comment:"object id" json:"object_id"`- // user collection group id- UserCollectionGroupID int64 `validate:"omitempty" comment:"user collection group id" json:"user_collection_group_id"`- //- CreateTime time.Time `validate:"omitempty" comment:"" json:"create_time"`- //- UpdateTime time.Time `validate:"omitempty" comment:"" json:"update_time"`-}--// GetCollectionListReq get collection list all request-type GetCollectionListReq struct {- // user id- UserID int64 `validate:"omitempty" comment:"user id" form:"user_id"`- // object id- ObjectID int64 `validate:"omitempty" comment:"object id" form:"object_id"`- // user collection group id- UserCollectionGroupID int64 `validate:"omitempty" comment:"user collection group id" form:"user_collection_group_id"`- //- CreateTime time.Time `validate:"omitempty" comment:"" form:"create_time"`- //- UpdateTime time.Time `validate:"omitempty" comment:"" form:"update_time"`-}--// GetCollectionWithPageReq get collection list page request-type GetCollectionWithPageReq struct {- // page- Page int `validate:"omitempty,min=1" form:"page"`- // page size- PageSize int `validate:"omitempty,min=1" form:"page_size"`- // user id- UserID int64 `validate:"omitempty" comment:"user id" form:"user_id"`- // object id- ObjectID int64 `validate:"omitempty" comment:"object id" form:"object_id"`- // user collection group id- UserCollectionGroupID int64 `validate:"omitempty" comment:"user collection group id" form:"user_collection_group_id"`- //- CreateTime time.Time `validate:"omitempty" comment:"" form:"create_time"`- //- UpdateTime time.Time `validate:"omitempty" comment:"" form:"update_time"`-}--// GetCollectionResp get collection response-type GetCollectionResp struct {- // collection id- ID int64 `json:"id"`- // user id- UserID int64 `json:"user_id"`- // object id- ObjectID int64 `json:"object_id"`- // user collection group id- UserCollectionGroupID int64 `json:"user_collection_group_id"`- //- CreateTime time.Time `json:"create_time"`- //- UpdateTime time.Time `json:"update_time"`-}diff --git a/internal/schema/comment_schema.go b/internal/schema/comment_schema.goindex dfba4607..41c46f9d 100644--- a/internal/schema/comment_schema.go+++ b/internal/schema/comment_schema.go@@ -109,6 +109,8 @@ type GetCommentResp struct {UserDisplayName string `json:"user_display_name"`// user avatarUserAvatar string `json:"user_avatar"`+ // user status+ UserStatus string `json:"user_status"`// reply user idReplyUserID string `json:"reply_user_id"`@@ -118,6 +120,8 @@ type GetCommentResp struct {ReplyUserDisplayName string `json:"reply_user_display_name"`// reply comment idReplyCommentID string `json:"reply_comment_id"`+ // reply user status+ ReplyUserStatus string `json:"reply_user_status"`// MemberActionsMemberActions []*PermissionMemberAction `json:"member_actions"`diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.goindex df21eda7..0fded2fe 100644--- a/internal/schema/question_schema.go+++ b/internal/schema/question_schema.go@@ -166,7 +166,7 @@ type CmsQuestionSearch struct {Page int `json:"page" form:"page"` //Query number of pagesPageSize int `json:"page_size" form:"page_size"` //Search page sizeStatus int `json:"-" form:"-"`- StatusStr string `json:"status" form:"status"` //Status 1 Available 2 closed 10 Deleted+ StatusStr string `json:"status" form:"status"` //Status 1 Available 2 closed 10 UserDeleted}type AdminSetQuestionStatusRequest struct {diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.goindex f2bb5896..c384058a 100644--- a/internal/schema/user_schema.go+++ b/internal/schema/user_schema.go@@ -166,7 +166,7 @@ const (var UserStatusShow = map[int]string{1: "normal",9: "forbidden",- 10: "delete",+ 10: "deleted",}var UserStatusShowMsg = map[int]string{1: "",@@ -282,15 +282,15 @@ type ActionRecordResp struct {}type UserBasicInfo struct {- UserId string `json:"-" ` // user_id- UserName string `json:"username" ` // name+ ID string `json:"-" ` // user_id+ Username string `json:"username" ` // nameRank int `json:"rank" ` // rankDisplayName string `json:"display_name"` // display_nameAvatar string `json:"avatar" ` // avatarWebsite string `json:"website" ` // websiteLocation string `json:"location" ` // locationIpInfo string `json:"ip_info"` // ip info- Status int `json:"status"` // status+ Status string `json:"status"` // status}type GetOtherUserInfoByUsernameReq struct {diff --git a/internal/service/comment/comment_service.go b/internal/service/comment/comment_service.goindex 7212ac49..fe5e2ad0 100644--- a/internal/service/comment/comment_service.go+++ b/internal/service/comment/comment_service.go@@ -32,7 +32,7 @@ type CommentRepo interface {type CommentService struct {commentRepo CommentRepocommentCommonRepo comment_common.CommentCommonRepo- userRepo usercommon.UserRepo+ userCommon *usercommon.UserCommonvoteCommon activity_common.VoteRepoobjectInfoService *object_info.ObjService}@@ -61,13 +61,13 @@ func (c *CommentQuery) GetOrderBy() string {func NewCommentService(commentRepo CommentRepo,commentCommonRepo comment_common.CommentCommonRepo,- userRepo usercommon.UserRepo,+ userCommon *usercommon.UserCommon,objectInfoService *object_info.ObjService,voteCommon activity_common.VoteRepo) *CommentService {return &CommentService{commentRepo: commentRepo,commentCommonRepo: commentCommonRepo,- userRepo: userRepo,+ userCommon: userCommon,voteCommon: voteCommon,objectInfoService: objectInfoService,}@@ -124,19 +124,20 @@ func (cs *CommentService) AddComment(ctx context.Context, req *schema.AddComment// get reply user infoif len(resp.ReplyUserID) > 0 {- replyUser, exist, err := cs.userRepo.GetByUserID(ctx, resp.ReplyUserID)+ replyUser, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, resp.ReplyUserID)if err != nil {return nil, err}if exist {resp.ReplyUsername = replyUser.Usernameresp.ReplyUserDisplayName = replyUser.DisplayName+ resp.ReplyUserStatus = replyUser.Status}cs.notificationCommentReply(ctx, replyUser.ID, objInfo.QuestionID, req.UserID)}// get user info- userInfo, exist, err := cs.userRepo.GetByUserID(ctx, resp.UserID)+ userInfo, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, resp.UserID)if err != nil {return nil, err}@@ -144,6 +145,7 @@ func (cs *CommentService) AddComment(ctx context.Context, req *schema.AddCommentresp.Username = userInfo.Usernameresp.UserDisplayName = userInfo.DisplayNameresp.UserAvatar = userInfo.Avatar+ resp.UserStatus = userInfo.Status}return resp, nil}@@ -191,7 +193,7 @@ func (cs *CommentService) GetComment(ctx context.Context, req *schema.GetComment// get comment user infoif len(resp.UserID) > 0 {- commentUser, exist, err := cs.userRepo.GetByUserID(ctx, resp.UserID)+ commentUser, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, resp.UserID)if err != nil {return nil, err}@@ -199,18 +201,20 @@ func (cs *CommentService) GetComment(ctx context.Context, req *schema.GetCommentresp.Username = commentUser.Usernameresp.UserDisplayName = commentUser.DisplayNameresp.UserAvatar = commentUser.Avatar+ resp.UserStatus = commentUser.Status}}// get reply user infoif len(resp.ReplyUserID) > 0 {- replyUser, exist, err := cs.userRepo.GetByUserID(ctx, resp.ReplyUserID)+ replyUser, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, resp.ReplyUserID)if err != nil {return nil, err}if exist {resp.ReplyUsername = replyUser.Usernameresp.ReplyUserDisplayName = replyUser.DisplayName+ resp.ReplyUserStatus = replyUser.Status}}@@ -249,7 +253,7 @@ func (cs *CommentService) GetCommentWithPage(ctx context.Context, req *schema.Ge// get comment user infoif len(commentResp.UserID) > 0 {- commentUser, exist, err := cs.userRepo.GetByUserID(ctx, commentResp.UserID)+ commentUser, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, commentResp.UserID)if err != nil {return nil, err}@@ -257,18 +261,20 @@ func (cs *CommentService) GetCommentWithPage(ctx context.Context, req *schema.GecommentResp.Username = commentUser.UsernamecommentResp.UserDisplayName = commentUser.DisplayNamecommentResp.UserAvatar = commentUser.Avatar+ commentResp.UserStatus = commentUser.Status}}// get reply user infoif len(commentResp.ReplyUserID) > 0 {- replyUser, exist, err := cs.userRepo.GetByUserID(ctx, commentResp.ReplyUserID)+ replyUser, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, commentResp.ReplyUserID)if err != nil {return nil, err}if exist {commentResp.ReplyUsername = replyUser.UsernamecommentResp.ReplyUserDisplayName = replyUser.DisplayName+ commentResp.ReplyUserStatus = replyUser.Status}}@@ -278,7 +284,7 @@ func (cs *CommentService) GetCommentWithPage(ctx context.Context, req *schema.GecommentResp.MemberActions = permission.GetCommentPermission(req.UserID, commentResp.UserID)resp = append(resp, commentResp)}- return pager.NewPageModel(req.Page, req.PageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}func (cs *CommentService) checkCommentWhetherOwner(ctx context.Context, userID, commentID string) error {@@ -305,7 +311,7 @@ func (cs *CommentService) checkIsVote(ctx context.Context, userID, commentID strfunc (cs *CommentService) GetCommentPersonalWithPage(ctx context.Context, req *schema.GetCommentPersonalWithPageReq) (pageModel *pager.PageModel, err error) {if len(req.Username) > 0 {- userInfo, exist, err := cs.userRepo.GetByUsername(ctx, req.Username)+ userInfo, exist, err := cs.userCommon.GetUserBasicInfoByUserName(ctx, req.Username)if err != nil {return nil, err}@@ -348,7 +354,7 @@ func (cs *CommentService) GetCommentPersonalWithPage(ctx context.Context, req *s}resp = append(resp, commentResp)}- return pager.NewPageModel(req.Page, req.PageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}func (cs *CommentService) notificationQuestionComment(ctx context.Context, questionUserID, commentID, commentUserID string) {@@ -389,7 +395,7 @@ func (cs *CommentService) notificationCommentReply(ctx context.Context, replyUsefunc (cs *CommentService) notificationMention(ctx context.Context, mentionUsernameList []string, commentID, commentUserID string) {for _, username := range mentionUsernameList {- userInfo, exist, err := cs.userRepo.GetByUsername(ctx, username)+ userInfo, exist, err := cs.userCommon.GetUserBasicInfoByUserName(ctx, username)if err != nil {log.Error(err)continuediff --git a/internal/service/notification/notification_read_service.go b/internal/service/notification/notification_read_service.goindex 791c8d93..8c0b2c8f 100644--- a/internal/service/notification/notification_read_service.go+++ b/internal/service/notification/notification_read_service.go@@ -97,5 +97,5 @@ func (ns *NotificationReadService) GetNotificationReadWithPage(ctx context.Conteresp := &[]schema.GetNotificationReadResp{}_ = copier.Copy(resp, notificationReads)- return pager.NewPageModel(page, pageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}diff --git a/internal/service/notification/notification_service.go b/internal/service/notification/notification_service.goindex 4b6e896b..7ebfa27a 100644--- a/internal/service/notification/notification_service.go+++ b/internal/service/notification/notification_service.go@@ -5,9 +5,13 @@ import ("encoding/json""fmt"+ "github.com/segmentfault/answer/internal/base/constant""github.com/segmentfault/answer/internal/base/data"+ "github.com/segmentfault/answer/internal/base/pager"+ "github.com/segmentfault/answer/internal/base/translator""github.com/segmentfault/answer/internal/schema"notficationcommon "github.com/segmentfault/answer/internal/service/notification_common"+ "github.com/segmentfault/pacman/i18n""github.com/segmentfault/pacman/log")@@ -91,30 +95,33 @@ func (ns *NotificationService) ClearIDUnRead(ctx context.Context, userID string,return nil}-func (ns *NotificationService) GetList(ctx context.Context, search *schema.NotificationSearch) ([]*schema.NotificationContent, int64, error) {- list := make([]*schema.NotificationContent, 0)+func (ns *NotificationService) GetList(ctx context.Context, search *schema.NotificationSearch) (+ pageModel *pager.PageModel, err error) {+ resp := make([]*schema.NotificationContent, 0)searchType, ok := schema.NotificationType[search.TypeStr]if !ok {- return list, 0, nil+ return pager.NewPageModel(0, resp), nil}search.Type = searchType- dblist, count, err := ns.notificationRepo.SearchList(ctx, search)+ notifications, count, err := ns.notificationRepo.SearchList(ctx, search)if err != nil {- return list, count, err+ return nil, err}- for _, dbitem := range dblist {+ for _, notificationInfo := range notifications {item := &schema.NotificationContent{}- err := json.Unmarshal([]byte(dbitem.Content), item)+ err := json.Unmarshal([]byte(notificationInfo.Content), item)if err != nil {log.Error("NotificationContent Unmarshal Error", err.Error())continue}- item.ID = dbitem.ID- item.UpdateTime = dbitem.UpdatedAt.Unix()- if dbitem.IsRead == schema.NotificationRead {+ lang, _ := ctx.Value(constant.AcceptLanguageFlag).(i18n.Language)+ item.NotificationAction = translator.GlobalTrans.Tr(lang, item.NotificationAction)+ item.ID = notificationInfo.ID+ item.UpdateTime = notificationInfo.UpdatedAt.Unix()+ if notificationInfo.IsRead == schema.NotificationRead {item.IsRead = true}- list = append(list, item)+ resp = append(resp, item)}- return list, count, nil+ return pager.NewPageModel(count, resp), nil}diff --git a/internal/service/question_service.go b/internal/service/question_service.goindex 70cdd27a..eb6284b6 100644--- a/internal/service/question_service.go+++ b/internal/service/question_service.go@@ -265,7 +265,7 @@ func (qs *QuestionService) SearchUserList(ctx context.Context, userName, order ssearch.Order = ordersearch.Page = pagesearch.PageSize = pageSize- search.UserID = userinfo.UserId+ search.UserID = userinfo.IDquestionlist, count, err := qs.SearchList(ctx, search, loginUserID)if err != nil {return userlist, 0, err@@ -289,7 +289,7 @@ func (qs *QuestionService) SearchUserAnswerList(ctx context.Context, userName, oreturn userAnswerlist, 0, nil}answersearch := &entity.AnswerSearch{}- answersearch.UserID = userinfo.UserId+ answersearch.UserID = userinfo.IDanswersearch.PageSize = pageSizeanswersearch.Page = pageif order == "newest" {@@ -337,7 +337,7 @@ func (qs *QuestionService) SearchUserCollectionList(ctx context.Context, page, preturn list, 0, nil}collectionSearch := &entity.CollectionSearch{}- collectionSearch.UserID = userinfo.UserId+ collectionSearch.UserID = userinfo.IDcollectionSearch.Page = pagecollectionSearch.PageSize = pageSizecollectionlist, count, err := qs.collectionCommon.SearchList(ctx, collectionSearch)@@ -384,13 +384,13 @@ func (qs *QuestionService) SearchUserTopList(ctx context.Context, userName strinsearch.Order = "score"search.Page = 0search.PageSize = 5- search.UserID = userinfo.UserId+ search.UserID = userinfo.IDquestionlist, _, err := qs.SearchList(ctx, search, loginUserID)if err != nil {return userQuestionlist, userAnswerlist, err}answersearch := &entity.AnswerSearch{}- answersearch.UserID = userinfo.UserId+ answersearch.UserID = userinfo.IDanswersearch.PageSize = 5answersearch.Order = entity.Answer_Search_OrderBy_VotequestionIDs := make([]string, 0)@@ -494,7 +494,7 @@ func (qs *QuestionService) SearchList(ctx context.Context, req *schema.QuestionSif !exist {return list, 0, err}- req.UserID = userinfo.UserId+ req.UserID = userinfo.ID}questionList, count, err := qs.questionRepo.SearchList(ctx, req)if err != nil {diff --git a/internal/service/rank/rank_service.go b/internal/service/rank/rank_service.goindex 8eca2a9b..90fa15f2 100644--- a/internal/service/rank/rank_service.go+++ b/internal/service/rank/rank_service.go@@ -47,7 +47,7 @@ type UserRankRepo interface {// RankService rank servicetype RankService struct {- userRepo usercommon.UserRepo+ userCommon *usercommon.UserCommonconfigRepo config.ConfigRepouserRankRepo UserRankRepoobjectInfoService *object_info.ObjService@@ -55,12 +55,12 @@ type RankService struct {// NewRankService new rank servicefunc NewRankService(- userRepo usercommon.UserRepo,+ userCommon *usercommon.UserCommon,userRankRepo UserRankRepo,objectInfoService *object_info.ObjService,configRepo config.ConfigRepo) *RankService {return &RankService{- userRepo: userRepo,+ userCommon: userCommon,configRepo: configRepo,userRankRepo: userRankRepo,objectInfoService: objectInfoService,@@ -74,7 +74,7 @@ func (rs *RankService) CheckRankPermission(ctx context.Context, userID string, a}// get the rank of the current user- userInfo, exist, err := rs.userRepo.GetByUserID(ctx, userID)+ userInfo, exist, err := rs.userCommon.GetUserBasicInfoByID(ctx, userID)if err != nil {return false, err}@@ -101,7 +101,7 @@ func (rs *RankService) CheckRankPermission(ctx context.Context, userID string, afunc (rs *RankService) GetRankPersonalWithPage(ctx context.Context, req *schema.GetRankPersonalWithPageReq) (pageModel *pager.PageModel, err error) {if len(req.Username) > 0 {- userInfo, exist, err := rs.userRepo.GetByUsername(ctx, req.Username)+ userInfo, exist, err := rs.userCommon.GetUserBasicInfoByUserName(ctx, req.Username)if err != nil {return nil, err}@@ -140,5 +140,5 @@ func (rs *RankService) GetRankPersonalWithPage(ctx context.Context, req *schema.}resp = append(resp, commentResp)}- return pager.NewPageModel(req.Page, req.PageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}diff --git a/internal/service/report_backyard/report_backyard.go b/internal/service/report_backyard/report_backyard.goindex aa8dac44..3aaa1db6 100644--- a/internal/service/report_backyard/report_backyard.go+++ b/internal/service/report_backyard/report_backyard.go@@ -2,9 +2,10 @@ package report_backyardimport ("context"- "github.com/segmentfault/answer/internal/service/config""strings"+ "github.com/segmentfault/answer/internal/service/config"+"github.com/jinzhu/copier""github.com/segmentfault/answer/internal/base/pager""github.com/segmentfault/answer/internal/base/reason"@@ -93,7 +94,7 @@ func (rs *ReportBackyardService) ListReportPage(ctx context.Context, dto schema.}rs.parseObject(ctx, &resp)- return pager.NewPageModel(dto.Page, dto.PageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}// HandleReported handle the reported objectdiff --git a/internal/service/revision_service.go b/internal/service/revision_service.goindex d732c184..20b71a66 100644--- a/internal/service/revision_service.go+++ b/internal/service/revision_service.go@@ -18,19 +18,19 @@ import (// RevisionService user servicetype RevisionService struct {revisionRepo revision.RevisionRepo- userRepo usercommon.UserRepo+ userCommon *usercommon.UserCommonquestionCommon *questioncommon.QuestionCommonanswerService *AnswerService}func NewRevisionService(revisionRepo revision.RevisionRepo,- userRepo usercommon.UserRepo,+ userCommon *usercommon.UserCommon,questionCommon *questioncommon.QuestionCommon,answerService *AnswerService) *RevisionService {return &RevisionService{revisionRepo: revisionRepo,- userRepo: userRepo,+ userCommon: userCommon,questionCommon: questionCommon,answerService: answerService,}@@ -69,7 +69,6 @@ func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetR)resp = []schema.GetRevisionResp{}-_ = copier.Copy(&rev, req)revs, err = rs.revisionRepo.GetRevisionList(ctx, &rev)@@ -79,29 +78,24 @@ func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetRfor _, r := range revs {var (- userInfo *entity.User- uinfo schema.UserBasicInfo- item schema.GetRevisionResp- exists bool+ uinfo schema.UserBasicInfo+ item schema.GetRevisionResp)_ = copier.Copy(&item, r)rs.parseItem(ctx, &item)// get user info- userInfo, exists, err = rs.userRepo.GetByUserID(ctx, item.UserID)- if err != nil {- return+ userInfo, exists, e := rs.userCommon.GetUserBasicInfoByID(ctx, item.UserID)+ if e != nil {+ return nil, e}-if exists {err = copier.Copy(&uinfo, userInfo)item.UserInfo = uinfo}-resp = append(resp, item)}-return}diff --git a/internal/service/search/author.go b/internal/service/search/author.goindex 29bba1a0..e25f1087 100644--- a/internal/service/search/author.go+++ b/internal/service/search/author.go@@ -5,25 +5,24 @@ import ("regexp""strings"- "github.com/segmentfault/answer/internal/entity""github.com/segmentfault/answer/internal/schema""github.com/segmentfault/answer/internal/service/search_common"usercommon "github.com/segmentfault/answer/internal/service/user_common")type AuthorSearch struct {- repo search_common.SearchRepo- userRepo usercommon.UserRepo- exp string- w string- page int- size int+ repo search_common.SearchRepo+ userCommon *usercommon.UserCommon+ exp string+ w string+ page int+ size int}-func NewAuthorSearch(repo search_common.SearchRepo, userRepo usercommon.UserRepo) *AuthorSearch {+func NewAuthorSearch(repo search_common.SearchRepo, userCommon *usercommon.UserCommon) *AuthorSearch {return &AuthorSearch{- repo: repo,- userRepo: userRepo,+ repo: repo,+ userCommon: userCommon,}}@@ -37,9 +36,6 @@ func (s *AuthorSearch) Parse(dto *schema.SearchDTO) (ok bool) {p,me,name string- user *entity.User- has bool- err error)exp = ""q = dto.Query@@ -51,8 +47,7 @@ func (s *AuthorSearch) Parse(dto *schema.SearchDTO) (ok bool) {res := re.FindStringSubmatch(q)if len(res) == 2 {name = res[1]- user, has, err = s.userRepo.GetByUsername(nil, name)-+ user, has, err := s.userCommon.GetUserBasicInfoByUserName(nil, name)if err == nil && has {exp = user.IDtrimLen := len(res[0])diff --git a/internal/service/search_service.go b/internal/service/search_service.goindex 04a4ba59..b292a99c 100644--- a/internal/service/search_service.go+++ b/internal/service/search_service.go@@ -35,14 +35,14 @@ type SearchService struct {func NewSearchService(searchRepo search_common.SearchRepo,tagRepo tagcommon.TagRepo,- userRepo usercommon.UserRepo,+ userCommon *usercommon.UserCommon,followCommon activity_common.FollowRepo,) *SearchService {return &SearchService{searchRepo: searchRepo,tagSearch: search.NewTagSearch(searchRepo, tagRepo, followCommon),withinSearch: search.NewWithinSearch(searchRepo),- authorSearch: search.NewAuthorSearch(searchRepo, userRepo),+ authorSearch: search.NewAuthorSearch(searchRepo, userCommon),scoreSearch: search.NewScoreSearch(searchRepo),answersSearch: search.NewAnswersSearch(searchRepo),acceptedAnswerSearch: search.NewAcceptedAnswerSearch(searchRepo),diff --git a/internal/service/tag/tag_service.go b/internal/service/tag/tag_service.goindex dcbb9304..44747ca0 100644--- a/internal/service/tag/tag_service.go+++ b/internal/service/tag/tag_service.go@@ -358,7 +358,7 @@ func (ts *TagService) GetTagWithPage(ctx context.Context, req *schema.GetTagWithUpdatedAt: tag.UpdatedAt.Unix(),})}- return pager.NewPageModel(page, pageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}// checkTagIsFollow get tag list pagediff --git a/internal/service/user_backyard/user_backyard.go b/internal/service/user_backyard/user_backyard.goindex 570b1531..7fb79b6c 100644--- a/internal/service/user_backyard/user_backyard.go+++ b/internal/service/user_backyard/user_backyard.go@@ -108,17 +108,17 @@ func (us *UserBackyardService) GetUserPage(ctx context.Context, req *schema.GetUAvatar: u.Avatar,}if u.Status == entity.UserStatusDeleted {- t.Status = schema.Deleted+ t.Status = schema.UserDeletedt.DeletedAt = u.DeletedAt.Unix()} else if u.Status == entity.UserStatusSuspended {- t.Status = schema.Suspended+ t.Status = schema.UserSuspendedt.SuspendedAt = u.SuspendedAt.Unix()} else if u.MailStatus == entity.EmailStatusToBeVerified {- t.Status = schema.Inactive+ t.Status = schema.UserInactive} else {- t.Status = schema.Normal+ t.Status = schema.UserNormal}resp = append(resp, t)}- return pager.NewPageModel(req.Page, req.PageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.goindex 9a7be622..12ecf641 100644--- a/internal/service/user_common/user.go+++ b/internal/service/user_common/user.go@@ -35,12 +35,12 @@ func NewUserCommon(userRepo UserRepo) *UserCommon {}func (us *UserCommon) GetUserBasicInfoByID(ctx context.Context, ID string) (*schema.UserBasicInfo, bool, error) {- dbInfo, has, err := us.userRepo.GetByUserID(ctx, ID)+ userInfo, exist, err := us.userRepo.GetByUserID(ctx, ID)if err != nil {- return nil, has, err+ return nil, exist, err}- info := us.UserBasicInfoFormat(ctx, dbInfo)- return info, has, nil+ info := us.UserBasicInfoFormat(ctx, userInfo)+ return info, exist, nil}func (us *UserCommon) GetUserBasicInfoByUserName(ctx context.Context, username string) (*schema.UserBasicInfo, bool, error) {@@ -74,16 +74,20 @@ func (us *UserCommon) BatchUserBasicInfoByID(ctx context.Context, IDs []string)}// UserBasicInfoFormat-func (us *UserCommon) UserBasicInfoFormat(ctx context.Context, dbinfo *entity.User) *schema.UserBasicInfo {- info := new(schema.UserBasicInfo)- info.UserId = dbinfo.ID- info.UserName = dbinfo.Username- info.Rank = dbinfo.Rank- info.DisplayName = dbinfo.DisplayName- info.Avatar = dbinfo.Avatar- info.Website = dbinfo.Website- info.Location = dbinfo.Location- info.IpInfo = dbinfo.IPInfo- info.Status = dbinfo.Status- return info+func (us *UserCommon) UserBasicInfoFormat(ctx context.Context, userInfo *entity.User) *schema.UserBasicInfo {+ userBasicInfo := &schema.UserBasicInfo{}+ userBasicInfo.ID = userInfo.ID+ userBasicInfo.Username = userInfo.Username+ userBasicInfo.Rank = userInfo.Rank+ userBasicInfo.DisplayName = userInfo.DisplayName+ userBasicInfo.Avatar = userInfo.Avatar+ userBasicInfo.Website = userInfo.Website+ userBasicInfo.Location = userInfo.Location+ userBasicInfo.IpInfo = userInfo.IPInfo+ userBasicInfo.Status = schema.UserStatusShow[userInfo.Status]+ if userBasicInfo.Status == schema.UserDeleted {+ userBasicInfo.Avatar = ""+ userBasicInfo.DisplayName = "Anonymous"+ }+ return userBasicInfo}diff --git a/internal/service/user_group_service.go b/internal/service/user_group_service.goindex 9a7e833d..0145350b 100644--- a/internal/service/user_group_service.go+++ b/internal/service/user_group_service.go@@ -97,5 +97,5 @@ func (us *UserGroupService) GetUserGroupWithPage(ctx context.Context, req *schemresp := &[]schema.GetUserGroupResp{}_ = copier.Copy(resp, userGroups)- return pager.NewPageModel(page, pageSize, total, resp), nil+ return pager.NewPageModel(total, resp), nil}diff --git a/internal/service/vote_service.go b/internal/service/vote_service.goindex ecf12712..50f90deb 100644--- a/internal/service/vote_service.go+++ b/internal/service/vote_service.go@@ -193,5 +193,5 @@ func (vs *VoteService) ListUserVotes(ctx context.Context, req schema.GetVoteWithresp = append(resp, item)}- return pager.NewPageModel(req.Page, req.PageSize, total, resp), err+ return pager.NewPageModel(total, resp), err}diff --git a/pkg/library/captcha/captcha.go b/pkg/library/captcha/captcha.godeleted file mode 100644index 5c278aff..00000000--- a/pkg/library/captcha/captcha.go+++ /dev/null@@ -1,75 +0,0 @@-package captcha--import (- "fmt"- "image/color"- "sync"-- "github.com/mojocn/base64Captcha"-)--var store base64Captcha.Store-var once sync.Once--func NewCaptcha() {- once.Do(func() {- //var err error- //RedisDb, err = arch.App.Cache.GetQuestion("cache")- //if err != nil {- // store = base64Captcha.DefaultMemStore- // return- //}- //var ctx = context.Background()- //_, err = RedisDb.Ping(ctx).Result()- //- //if err != nil {- // store = base64Captcha.DefaultMemStore- // return- //}- store = RedisStore{}- })-}--// CaptchaClient-type CaptchaClient struct {-}--// NewCaptchaClient-func NewCaptchaClient() *CaptchaClient {- return &CaptchaClient{}-}--func MakeCaptcha() (id, b64s string, err error) {- var driver base64Captcha.Driver- //Configure the parameters of the CAPTCHA- driverString := base64Captcha.DriverString{- Height: 40,- Width: 100,- NoiseCount: 0,- ShowLineOptions: 2 | 4,- Length: 4,- Source: "1234567890qwertyuioplkjhgfdsazxcvbnm",- BgColor: &color.RGBA{R: 3, G: 102, B: 214, A: 125},- Fonts: []string{"wqy-microhei.ttc"},- }- //ConvertFonts Load fonts by name- driver = driverString.ConvertFonts()- //Create Captcha- captcha := base64Captcha.NewCaptcha(driver, store)- //Generate- id, b64s, err = captcha.Generate()- return id, b64s, err--}--// VerifyCaptcha Verification code-func VerifyCaptcha(id string, VerifyValue string) bool {- fmt.Println(id, VerifyValue)- if store.Verify(id, VerifyValue, true) {- //verify successfully- return true- } else {- //Verification failed- return false- }-}diff --git a/pkg/library/captcha/redis.go b/pkg/library/captcha/redis.godeleted file mode 100644index 3536b018..00000000--- a/pkg/library/captcha/redis.go+++ /dev/null@@ -1,46 +0,0 @@-package captcha--import (- "context"- "fmt"-- "github.com/segmentfault/pacman/contrib/cache/memory"-)--const CAPTCHA = "captcha:"--var RedisDb = memory.NewCache()--type RedisStore struct {-}--func (r RedisStore) Set(id string, value string) error {- key := CAPTCHA + id- ctx := context.Background()- err := RedisDb.SetString(ctx, key, value, 2)- return err-}--func (r RedisStore) Get(id string, clear bool) string {- key := CAPTCHA + id- ctx := context.Background()- val, err := RedisDb.GetString(ctx, key)- if err != nil {- fmt.Println(err)- return ""- }- if clear {- err := RedisDb.Del(ctx, key)- if err != nil {- fmt.Println(err)- return ""- }- }- return val-}--func (r RedisStore) Verify(id, answer string, clear bool) bool {- v := RedisStore{}.Get(id, clear)- fmt.Println("key:" + id + ";value:" + v + ";answer:" + answer)- return v == answer-}diff --git a/pkg/library/email/email.go b/pkg/library/email/email.godeleted file mode 100644index 4f37070e..00000000--- a/pkg/library/email/email.go+++ /dev/null@@ -1,103 +0,0 @@-package email--import (- "bytes"- "fmt"- "net/smtp"- "text/template"-- "github.com/jordan-wright/email"- "github.com/segmentfault/pacman/log"-)--// EmailClient-type EmailClient struct {- email *email.Email- config *Config-}--// Config .-type Config struct {- WebName string `json:"web_name"`- WebHost string `json:"web_host"`- SecretKey string `json:"secret_key"`- UserSessionKey string `json:"user_session_key"`- EmailFrom string `json:"email_from"`- EmailFromPass string `json:"email_from_pass"`- EmailFromHostname string `json:"email_from_hostname"`- EmailFromSMTP string `json:"email_from_smtp"`- EmailFromName string `json:"email_from_name"`- RegisterTitle string `json:"register_title"`- RegisterBody string `json:"register_body"`- PassResetTitle string `json:"pass_reset_title"`- PassResetBody string `json:"pass_reset_body"`-}--// NewEmailClient-func NewEmailClient() *EmailClient {- return &EmailClient{- email: email.NewEmail(),- }-}--func (s *EmailClient) Send(ToEmail, Title, Body string) {- from := s.config.EmailFrom- fromPass := s.config.EmailFromPass- fromName := s.config.EmailFromName- fromSmtp := s.config.EmailFromSMTP- fromHostName := s.config.EmailFromHostname- s.email.From = fmt.Sprintf("%s <%s>", fromName, from)- s.email.To = []string{ToEmail}- s.email.Subject = Title- s.email.HTML = []byte(Body)- err := s.email.Send(fromSmtp, smtp.PlainAuth("", from, fromPass, fromHostName))- if err != nil {- log.Error(err)- }-}--func (s *EmailClient) RegisterTemplate(RegisterUrl string) (Title, Body string, err error) {- webName := s.config.WebName- templateData := RegisterTemplateData{webName, RegisterUrl}- tmpl, err := template.New("register_title").Parse(s.config.RegisterTitle)- if err != nil {- return "", "", err- }- title := new(bytes.Buffer)- body := new(bytes.Buffer)- err = tmpl.Execute(title, templateData)- if err != nil {- return "", "", err- }-- tmpl, err = template.New("register_body").Parse(s.config.RegisterBody)- err = tmpl.Execute(body, templateData)- if err != nil {- return "", "", err- }-- return title.String(), body.String(), nil-}--func (s *EmailClient) PassResetTemplate(PassResetUrl string) (Title, Body string, err error) {- webName := s.config.WebName- templateData := PassResetTemplateData{webName, PassResetUrl}- tmpl, err := template.New("pass_reset_title").Parse(s.config.PassResetTitle)- if err != nil {- return "", "", err- }- title := new(bytes.Buffer)- body := new(bytes.Buffer)- err = tmpl.Execute(title, templateData)- if err != nil {- return "", "", err- }-- tmpl, err = template.New("pass_reset_body").Parse(s.config.PassResetBody)- err = tmpl.Execute(body, templateData)- if err != nil {- return "", "", err- }-- return title.String(), body.String(), nil-}diff --git a/pkg/library/email/models.go b/pkg/library/email/models.godeleted file mode 100644index 315c5386..00000000--- a/pkg/library/email/models.go+++ /dev/null@@ -1,11 +0,0 @@-package email--type RegisterTemplateData struct {- SiteName string- RegisterUrl string-}--type PassResetTemplateData struct {- SiteName string- PassResetUrl string-}