From d4028619daa21565356ca3e06f468a7faae391dd Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Thu, 3 Mar 2022 10:49:06 +0800 Subject: [PATCH] #1250 add org topics --- models/org.go | 4 ++-- models/topic.go | 13 +++++++++++++ routers/org/home.go | 7 +++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/models/org.go b/models/org.go index e8006d55f..85fb157ae 100755 --- a/models/org.go +++ b/models/org.go @@ -180,8 +180,8 @@ func CreateOrganization(org, owner *User) (err error) { // Add initial creator to organization and owner team. if _, err = sess.Insert(&OrgUser{ - UID: owner.ID, - OrgID: org.ID, + UID: owner.ID, + OrgID: org.ID, IsPublic: setting.Service.DefaultOrgMemberVisible, }); err != nil { return fmt.Errorf("insert org-user relation: %v", err) diff --git a/models/topic.go b/models/topic.go index 5533da7bc..e95e0ed40 100644 --- a/models/topic.go +++ b/models/topic.go @@ -324,3 +324,16 @@ func SaveTopics(repoID int64, topicNames ...string) error { return sess.Commit() } + +func GetOrgTopics(orgId int64) ([]Topic, error) { + result := make([]Topic, 0) + sql := "select t.* from repository r " + + "inner join repo_topic rt on rt.repo_id = r.id " + + "inner join topic t on rt.topic_id = t.id " + + "where r.owner_id = ? order by repo_count desc" + if e := x.SQL(sql, orgId).Find(&result); e != nil { + return nil, e + } + + return result, nil +} diff --git a/routers/org/home.go b/routers/org/home.go index c9769f559..3ffb4fd86 100755 --- a/routers/org/home.go +++ b/routers/org/home.go @@ -94,6 +94,13 @@ func Home(ctx *context.Context) { recommendCourseKeyWords, _ := repository.GetRecommendCourseKeyWords() ctx.Data["CoursesKeywords"] = recommendCourseKeyWords + } else { + orgTopics, err := models.GetOrgTopics(org.ID) + if err != nil { + ctx.Error(500, "GetOrgTopics failed") + return + } + ctx.Data["OrgTopics"] = orgTopics } repos, count, err = models.SearchRepository(&models.SearchRepoOptions{