Filter playlists by names and comments

This commit is contained in:
Deluan 2021-10-28 13:58:06 -04:00
parent 66a9cbb7d9
commit 074732b1dc
3 changed files with 20 additions and 1 deletions

View File

@ -30,9 +30,19 @@ func NewPlaylistRepository(ctx context.Context, o orm.Ormer) model.PlaylistRepos
r.ctx = ctx
r.ormer = o
r.tableName = "playlist"
r.filterMappings = map[string]filterFunc{
"q": playlistFilter,
}
return r
}
func playlistFilter(field string, value interface{}) Sqlizer {
return Or{
substringFilter("name", value),
substringFilter("comment", value),
}
}
func (r *playlistRepository) userFilter() Sqlizer {
user := loggedUser(r.ctx)
if user.IsAdmin {

View File

@ -68,6 +68,15 @@ func fullTextFilter(field string, value interface{}) Sqlizer {
return fullTextExpr(value.(string))
}
func substringFilter(field string, value interface{}) Sqlizer {
parts := strings.Split(value.(string), " ")
filters := And{}
for _, part := range parts {
filters = append(filters, Like{field: "%" + part + "%"})
}
return filters
}
func idFilter(tableName string) func(string, interface{}) Sqlizer {
return func(field string, value interface{}) Sqlizer {
return Eq{tableName + ".id": value}

View File

@ -26,7 +26,7 @@ import PlaylistListActions from './PlaylistListActions'
const PlaylistFilter = (props) => (
<Filter {...props} variant={'outlined'}>
<SearchInput source="name" alwaysOn />
<SearchInput source="q" alwaysOn />
</Filter>
)