Browse Source

#1250

add org topics
pull/1603/head
chenyifan01 3 years ago
parent
commit
d4028619da
3 changed files with 22 additions and 2 deletions
  1. +2
    -2
      models/org.go
  2. +13
    -0
      models/topic.go
  3. +7
    -0
      routers/org/home.go

+ 2
- 2
models/org.go View File

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


+ 13
- 0
models/topic.go View File

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

+ 7
- 0
routers/org/home.go View File

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


Loading…
Cancel
Save