mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-08 17:08:04 +02:00
Search gists on user profile with title, visibility, language & topics (#422)
This commit is contained in:
27
internal/db/gist_language.go
Normal file
27
internal/db/gist_language.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user