Remove Alpha from QueryOptions. Also add Filter, not implemented yet

This commit is contained in:
Deluan
2020-01-15 23:49:20 -05:00
parent 0a56fd8752
commit ca04a919ad
2 changed files with 15 additions and 9 deletions
+4 -4
View File
@@ -41,12 +41,12 @@ func (g *listGenerator) query(qo model.QueryOptions, offset int, size int) (Entr
} }
func (g *listGenerator) GetNewest(offset int, size int) (Entries, error) { func (g *listGenerator) GetNewest(offset int, size int) (Entries, error) {
qo := model.QueryOptions{SortBy: "CreatedAt", Desc: true, Alpha: true} qo := model.QueryOptions{SortBy: "CreatedAt", Desc: true}
return g.query(qo, offset, size) return g.query(qo, offset, size)
} }
func (g *listGenerator) GetRecent(offset int, size int) (Entries, error) { func (g *listGenerator) GetRecent(offset int, size int) (Entries, error) {
qo := model.QueryOptions{SortBy: "PlayDate", Desc: true, Alpha: true} qo := model.QueryOptions{SortBy: "PlayDate", Desc: true}
return g.query(qo, offset, size) return g.query(qo, offset, size)
} }
@@ -61,12 +61,12 @@ func (g *listGenerator) GetHighest(offset int, size int) (Entries, error) {
} }
func (g *listGenerator) GetByName(offset int, size int) (Entries, error) { func (g *listGenerator) GetByName(offset int, size int) (Entries, error) {
qo := model.QueryOptions{SortBy: "Name", Alpha: true} qo := model.QueryOptions{SortBy: "Name"}
return g.query(qo, offset, size) return g.query(qo, offset, size)
} }
func (g *listGenerator) GetByArtist(offset int, size int) (Entries, error) { func (g *listGenerator) GetByArtist(offset int, size int) (Entries, error) {
qo := model.QueryOptions{SortBy: "Artist", Alpha: true} qo := model.QueryOptions{SortBy: "Artist"}
return g.query(qo, offset, size) return g.query(qo, offset, size)
} }
+11 -5
View File
@@ -6,10 +6,16 @@ var (
ErrNotFound = errors.New("data not found") ErrNotFound = errors.New("data not found")
) )
// Filters use the same operators as Beego ORM: See https://beego.me/docs/mvc/model/query.md#operators
// Ex: var q = QueryOptions{Filters: Filters{"name__istartswith": "Deluan","age__gt": 25}}
// All conditions will be ANDed together
// TODO Implement filter in repositories' methods
type Filters map[string]interface{}
type QueryOptions struct { type QueryOptions struct {
SortBy string SortBy string
Alpha bool Desc bool
Desc bool Offset int
Offset int Size int
Size int Filters Filters
} }