update genres formatting

This commit is contained in:
sentriz
2020-03-12 14:11:56 +00:00
parent d535a0d4e5
commit 4b2bc3aec6
2 changed files with 6 additions and 4 deletions

View File

@@ -116,7 +116,8 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
params.GetIntOr("toYear", 2200))
q = q.Order("tag_year")
case "byGenre":
q = q.Joins("JOIN genres ON albums.tag_genre_id=genres.id AND genres.name=?", params.GetOr("genre", "Unknown Genre"))
q = q.Joins("JOIN genres ON albums.tag_genre_id=genres.id AND genres.name=?",
params.GetOr("genre", "Unknown Genre"))
case "frequent":
user := r.Context().Value(CtxUser).(*db.User)
q = q.Joins("JOIN plays ON albums.id=plays.album_id AND plays.user_id=?",
@@ -282,8 +283,8 @@ func (c *Controller) ServeGetGenres(r *http.Request) *spec.Response {
var genres []*db.Genre
c.DB.
Select(`*,
(SELECT count(id) FROM albums WHERE tag_genre_id=genres.id) album_count,
(SELECT count(id) FROM tracks WHERE tag_genre_id=genres.id) track_count`).
(SELECT count(id) FROM albums WHERE tag_genre_id=genres.id) album_count,
(SELECT count(id) FROM tracks WHERE tag_genre_id=genres.id) track_count`).
Group("genres.id").
Find(&genres)

View File

@@ -288,7 +288,8 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
params := r.Context().Value(CtxParams).(params.Params)
var tracks []*db.Track
q := c.DB.DB.Joins("JOIN albums ON tracks.album_id=albums.id").
q := c.DB.DB.
Joins("JOIN albums ON tracks.album_id=albums.id").
Limit(params.GetIntOr("size", 10)).
Preload("Album").
Order(gorm.Expr("random()"))