Search gists on user profile with title, visibility, language & topics (#422)

This commit is contained in:
Thomas Miceli
2025-02-02 18:14:03 +01:00
committed by GitHub
parent 76fc129c09
commit 7aa8f84eff
23 changed files with 429 additions and 54 deletions

View File

@ -0,0 +1,27 @@
package db
type GistLanguage struct {
GistID uint `gorm:"primaryKey"`
Language string `gorm:"primaryKey;size:100"`
}
func GetGistLanguagesForUser(fromUserId, currentUserId uint) ([]struct {
Language string
Count int64
}, error) {
var results []struct {
Language string
Count int64
}
err := gistsFromUserStatement(fromUserId, currentUserId).Model(&GistLanguage{}).
Select("language, count(*) as count").
Joins("JOIN gists ON gists.id = gist_languages.gist_id").
Where("gists.user_id = ?", fromUserId).
Group("language").
Order("count DESC").
Limit(15). // Added limit of 15
Find(&results).Error
return results, err
}