Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.5.1^2
zouap 4 years ago
parent
commit
c59605d806
1 changed files with 48 additions and 0 deletions
  1. +48
    -0
      routers/home.go

+ 48
- 0
routers/home.go View File

@@ -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 {


Loading…
Cancel
Save