| @@ -6,7 +6,6 @@ | |||||
| package models | package models | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/modules/blockchain" | |||||
| "container/list" | "container/list" | ||||
| "context" | "context" | ||||
| "crypto/md5" | "crypto/md5" | ||||
| @@ -25,6 +24,8 @@ import ( | |||||
| "time" | "time" | ||||
| "unicode/utf8" | "unicode/utf8" | ||||
| "code.gitea.io/gitea/modules/blockchain" | |||||
| "code.gitea.io/gitea/modules/avatar" | "code.gitea.io/gitea/modules/avatar" | ||||
| "code.gitea.io/gitea/modules/base" | "code.gitea.io/gitea/modules/base" | ||||
| "code.gitea.io/gitea/modules/generate" | "code.gitea.io/gitea/modules/generate" | ||||
| @@ -1498,6 +1499,17 @@ func GetUsersByIDs(ids []int64) (UserList, error) { | |||||
| return ous, err | return ous, err | ||||
| } | } | ||||
| func GetUsersByNames(names []string) (UserList, error) { | |||||
| ous := make([]*User, 0, len(names)) | |||||
| if len(names) == 0 { | |||||
| return ous, nil | |||||
| } | |||||
| err := x.In("name", names). | |||||
| Asc("name"). | |||||
| Find(&ous) | |||||
| return ous, err | |||||
| } | |||||
| // GetUserIDsByNames returns a slice of ids corresponds to names. | // GetUserIDsByNames returns a slice of ids corresponds to names. | ||||
| func GetUserIDsByNames(names []string, ignoreNonExistent bool) ([]int64, error) { | func GetUserIDsByNames(names []string, ignoreNonExistent bool) ([]int64, error) { | ||||
| ids := make([]int64, 0, len(names)) | ids := make([]int64, 0, len(names)) | ||||
| @@ -672,9 +672,14 @@ func getRecommendOrg() ([]map[string]interface{}, error) { | |||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| resultOrg := make([]map[string]interface{}, 0) | |||||
| names := make([]string, 0) | |||||
| for _, userName := range result { | for _, userName := range result { | ||||
| user, err := models.GetUserByName(userName) | |||||
| names = append(names, userName) | |||||
| } | |||||
| users, _ := models.GetUsersByNames(names) | |||||
| resultOrg := make([]map[string]interface{}, 0) | |||||
| for i, _ := range result { | |||||
| user := users[i] | |||||
| if err == nil { | if err == nil { | ||||
| userMap := make(map[string]interface{}) | userMap := make(map[string]interface{}) | ||||
| userMap["Name"] = user.Name | userMap["Name"] = user.Name | ||||
| @@ -789,24 +794,6 @@ func RecommendHomeInfo(ctx *context.Context) { | |||||
| ctx.JSON(http.StatusOK, mapInterface) | ctx.JSON(http.StatusOK, mapInterface) | ||||
| } | } | ||||
| // func RecommendOrgFromPromote(ctx *context.Context) { | |||||
| // resultOrg, err := GetRecommendOrg() | |||||
| // if err != nil { | |||||
| // ctx.ServerError("500", err) | |||||
| // return | |||||
| // } | |||||
| // ctx.JSON(200, resultOrg) | |||||
| // } | |||||
| func RecommendRepoFromPromote(ctx *context.Context) { | |||||
| result, err := repository.GetRecommendRepoFromPromote("projects") | |||||
| if err != nil { | |||||
| ctx.ServerError("500", err) | |||||
| } else { | |||||
| ctx.JSON(200, result) | |||||
| } | |||||
| } | |||||
| func HomeTerm(ctx *context.Context) { | func HomeTerm(ctx *context.Context) { | ||||
| ctx.HTML(200, tplHomeTerm) | ctx.HTML(200, tplHomeTerm) | ||||
| } | } | ||||
| @@ -131,11 +131,6 @@ func GetRecommendRepoFromPromote(filename string) ([]map[string]interface{}, err | |||||
| repoMap["ID"] = fmt.Sprint(repo.ID) | repoMap["ID"] = fmt.Sprint(repo.ID) | ||||
| repoMap["Name"] = repo.Name | repoMap["Name"] = repo.Name | ||||
| repoMap["Alias"] = repo.Alias | repoMap["Alias"] = repo.Alias | ||||
| if repo.RepoType == models.RepoCourse { | |||||
| //Load creator | |||||
| repo.GetCreator() | |||||
| repoMap["Creator"] = repo.Creator | |||||
| } | |||||
| repoMap["OwnerName"] = repo.OwnerName | repoMap["OwnerName"] = repo.OwnerName | ||||
| repoMap["NumStars"] = repo.NumStars | repoMap["NumStars"] = repo.NumStars | ||||