package lulu import ( "fmt" "net/url" "time" ) type PrintJobQuery func(*printJobQueries) type printJobQueries struct { creatAfter, creatBefore, modAfter, modBefore *time.Time status *OrderStatus id, orderId *uint excludeLineItems bool } func (q *printJobQueries) apply(f ...PrintJobQuery) { for i := range f { f[i](q) } } func (q *printJobQueries) vals() url.Values { v := url.Values{} if q.creatAfter != nil { v.Set("created_after", q.creatAfter.UTC().Format(time.RFC3339)) } if q.creatBefore != nil { v.Set("created_before", q.creatBefore.UTC().Format(time.RFC3339)) } if q.modAfter != nil { v.Set("modified_after", q.modAfter.UTC().Format(time.RFC3339)) } if q.modBefore != nil { v.Set("modified_before", q.modBefore.UTC().Format(time.RFC3339)) } if q.status != nil { v.Set("status", string(*q.status)) } if q.id != nil { v.Set("id", fmt.Sprint(*q.id)) } if q.orderId != nil { v.Set("order_id", fmt.Sprint(*q.orderId)) } if q.excludeLineItems { v.Set("exclude_line_items", "true") } return v } // 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 } }