From c59605d8065ddea9bc7efe8080add322124a31a6 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 5 May 2022 15:24:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/home.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/routers/home.go b/routers/home.go index 500ffbbd6..0cf09252c 100755 --- a/routers/home.go +++ b/routers/home.go @@ -8,6 +8,7 @@ package routers import ( "bytes" "net/http" + "strconv" "strings" "code.gitea.io/gitea/services/repository" @@ -641,6 +642,53 @@ func GetRecommendOrg() ([]map[string]interface{}, error) { return resultOrg, nil } +func GetRankUser() ([]map[string]interface{}, error) { + url := setting.RecommentRepoAddr + "user_rank" + result, err := repository.RecommendFromPromote(url) + + if err != nil { + return nil, err + } + resultOrg := make([]map[string]interface{}, 0) + for _, userRank := range result { + tmpIndex := strings.Index(userRank, " ") + userName := userRank + score := 0 + if tmpIndex != -1 { + userName = userRank[0:tmpIndex] + tmpScore, err := strconv.Atoi(userRank[tmpIndex+1:]) + if err != nil { + log.Info("convert to int error.") + } + score = tmpScore + } + user, err := models.GetUserByName(userName) + if err == nil { + userMap := make(map[string]interface{}) + userMap["Name"] = user.Name + userMap["Description"] = user.Description + userMap["FullName"] = user.FullName + userMap["HomeLink"] = user.HomeLink() + userMap["ID"] = user.ID + userMap["Avatar"] = user.RelAvatarLink() + userMap["Score"] = score + resultOrg = append(resultOrg, userMap) + } else { + log.Info("query user error," + err.Error()) + } + } + return resultOrg, nil +} + +func GetUserRankFromPromote(ctx *context.Context) { + resultUserRank, err := GetRankUser() + if err != nil { + ctx.ServerError("500", err) + return + } + ctx.JSON(200, resultUserRank) +} + func RecommendOrgFromPromote(ctx *context.Context) { resultOrg, err := GetRecommendOrg() if err != nil {