aboutsummaryrefslogtreecommitdiffstats
path: root/query.go
blob: cf56bdd3242a6210fba4434cd8c5aea617390879 (plain) (blame)
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
package lulu

import "time"

type printJobQueries struct {
	creatAfter, creatBefore, modAfter, modBefore *time.Time
	status                                       *OrderStatus
	id, orderId                                  *uint
	excludeLineItems                             bool
}

func parsePrintJobQueries(qs []PrintJobQuery) printJobQueries {
	var q printJobQueries
	for i := range qs {
		qs[i](&q)
	}
	return q
}

type PrintJobQuery func(*printJobQueries)

// Include only print jobs created after t.
func FilterCreatedAfter(t time.Time) PrintJobQuery {
	return func(q *printJobQueries) {
		q.creatAfter = &t
	}
}

// Include only print jobs created before t.
func FilterCreatedBefore(t time.Time) PrintJobQuery {
	return func(q *printJobQueries) {
		q.creatBefore = &t
	}
}

// Include only print jobs modified after t.
func FilterModifiedAfter(t time.Time) PrintJobQuery {
	return func(q *printJobQueries) {
		q.modAfter = &t
	}
}

// Include only print jobs modified before t.
func FilterModifiedBefore(t time.Time) PrintJobQuery {
	return func(q *printJobQueries) {
		q.modBefore = &t
	}
}

// Include only print jobs with status s.
func FilterStatus(s OrderStatus) PrintJobQuery {
	return func(q *printJobQueries) {
		q.status = &s
	}
}

// Include only print jobs with the given id.
func FilterId(id uint) PrintJobQuery {
	return func(q *printJobQueries) {
		q.id = &id
	}
}

// Include only print jobs with the given order_id.
func FilterOrderId(orderId uint) PrintJobQuery {
	return func(q *printJobQueries) {
		q.orderId = &orderId
	}
}

// Leave the list of line items out of the print jobs response.
func ExcludeLineItems() PrintJobQuery {
	return func(q *printJobQueries) {
		q.excludeLineItems = true
	}
}