Add Genre filters to UI

This commit is contained in:
Deluan
2021-07-16 19:41:49 -04:00
committed by Deluan Quintão
parent c56c7c865e
commit 20b7e5c49b
13 changed files with 108 additions and 32 deletions
+6 -1
View File
@@ -82,7 +82,12 @@ func artistFilter(field string, value interface{}) Sqlizer {
}
func (r *albumRepository) CountAll(options ...model.QueryOptions) (int64, error) {
return r.count(r.selectAlbum(), options...)
sql := r.selectAlbum()
sql = sql.LeftJoin("album_genres ag on album.id = ag.album_id").
LeftJoin("genre on ag.genre_id = genre.id").
GroupBy("album.id")
return r.count(sql, options...)
}
func (r *albumRepository) Exists(id string) (bool, error) {
+5 -1
View File
@@ -49,7 +49,11 @@ func (r *artistRepository) selectArtist(options ...model.QueryOptions) SelectBui
}
func (r *artistRepository) CountAll(options ...model.QueryOptions) (int64, error) {
return r.count(r.newSelectWithAnnotation("artist.id"), options...)
sql := r.newSelectWithAnnotation("artist.id")
sql = sql.LeftJoin("artist_genres ag on artist.id = ag.artist_id").
LeftJoin("genre on ag.genre_id = genre.id").
GroupBy("artist.id")
return r.count(sql, options...)
}
func (r *artistRepository) Exists(id string) (bool, error) {
+3
View File
@@ -22,6 +22,9 @@ func NewGenreRepository(ctx context.Context, o orm.Ormer) model.GenreRepository
r.ctx = ctx
r.ormer = o
r.tableName = "genre"
r.filterMappings = map[string]filterFunc{
"name": containsFilter,
}
return r
}
+5 -1
View File
@@ -38,7 +38,11 @@ func NewMediaFileRepository(ctx context.Context, o orm.Ormer) *mediaFileReposito
}
func (r *mediaFileRepository) CountAll(options ...model.QueryOptions) (int64, error) {
return r.count(r.newSelectWithAnnotation("media_file.id"), options...)
sql := r.newSelectWithAnnotation("media_file.id")
sql = sql.LeftJoin("media_file_genres mfg on media_file.id = mfg.media_file_id").
LeftJoin("genre on mfg.genre_id = genre.id").
GroupBy("media_file.id")
return r.count(sql, options...)
}
func (r *mediaFileRepository) Exists(id string) (bool, error) {
+2
View File
@@ -88,6 +88,8 @@ func (s *SQLStore) Resource(ctx context.Context, m interface{}) model.ResourceRe
return s.Album(ctx).(model.ResourceRepository)
case model.MediaFile:
return s.MediaFile(ctx).(model.ResourceRepository)
case model.Genre:
return s.Genre(ctx).(model.ResourceRepository)
case model.Playlist:
return s.Playlist(ctx).(model.ResourceRepository)
case model.Share: