-
Notifications
You must be signed in to change notification settings - Fork 4
/
queryopts.go
80 lines (65 loc) · 1.59 KB
/
queryopts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package jellyfin
import "time"
type SortField string
const (
SortByName SortField = "SortName"
SortByYear SortField = "ProductionYear,PremiereDate"
SortByArtist SortField = "AlbumArtist"
SortByPlayCount SortField = "PlayCount"
SortByRandom SortField = "Random"
SortByDateCreated SortField = "DateCreated"
SortByDatePlayed SortField = "DatePlayed"
SortByCommunityRating SortField = "CommunityRating"
)
type SortOrder string
const (
SortAsc SortOrder = "ASC"
SortDesc SortOrder = "DESC"
)
// Sort describes sorting
type Sort struct {
Field SortField
Mode SortOrder
}
type Paging struct {
StartIndex int
Limit int
}
type FilterPlayStatus string
const (
FilterIsPlayed = "Played"
FilterIsNotPlayed = "Not played"
)
// Filter contains filter for reducing results. Some fields are exclusive,
type Filter struct {
// Played
FilterPlayed FilterPlayStatus
// Favorite marks items as being starred / favorite.
Favorite bool
// Include only results from the given artist.
ArtistID string
// Include only results with the given parentID.
ParentID string
// Genres contains list of genres to include.
Genres []string
// YearRange contains two elements, items must be within these boundaries.
YearRange [2]int
}
type QueryOpts struct {
Paging Paging
Filter Filter
Sort Sort
}
func (f Filter) yearRangeValid() bool {
if f.YearRange == [2]int{0, 0} {
return true
}
if f.YearRange[0] > f.YearRange[1] {
return false
}
if f.YearRange[0] < 0 {
return false
}
year := time.Now().Year()
return f.YearRange[1] <= year+10
}