func (c *Customer) ListCustomersByName(customerName string) (Customers, error) { filter := invdendpoint.NewFilter() filter.Set("name", customerName) customers, apiError := c.ListAll(filter, nil) if apiError != nil { return nil, apiError } return customers, nil }
func TestAddFilterSortToEndPointWithOnlyFilter(t *testing.T) { f := invdendpoint.NewFilter() f.Set("id", 121123) f.Set("address", 121123) endPoint := "https://www.do.com" value := addFilterSortToEndPoint(endPoint, f, nil) correctValue := "https://www.do.com?filter%5Baddress%5D=121123&filter%5Bid%5D=121123" if value != correctValue { t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value) } }
func (c *Customer) ListCustomerByNumber(customerNumber string) (*Customer, error) { filter := invdendpoint.NewFilter() filter.Set("number", customerNumber) customers, apiError := c.ListAll(filter, nil) if apiError != nil { return nil, apiError } if len(customers) == 0 { return nil, nil } return customers[0], nil }
func (c *Invoice) ListInvoiceByNumber(invoiceNumber string) (*Invoice, error) { filter := invdendpoint.NewFilter() filter.Set("number", invoiceNumber) invoices, apiError := c.ListAll(filter, nil) if apiError != nil { return nil, apiError } if len(invoices) == 0 { return nil, nil } return invoices[0], nil }
func (c *Transaction) ListSuccessfulByInvoiceID(invoiceID int64) (Transactions, error) { invoiceIDString := strconv.FormatInt(invoiceID, 10) filter := invdendpoint.NewFilter() filter.Set("invoice", invoiceIDString) filter.Set("status", "succeeded") transactions, apiError := c.ListAll(filter, nil) if apiError != nil { return nil, apiError } if len(transactions) == 0 { return nil, nil } return transactions, nil }
func TestAddFilterSortToEndPointWithBothValues(t *testing.T) { f := invdendpoint.NewFilter() f.Set("id", 121123) f.Set("address", 121123) s := invdendpoint.NewSort() s.Set("name", invdendpoint.ASC) s.Set("age", invdendpoint.DESC) endPoint := "https://www.do.com" value := addFilterSortToEndPoint(endPoint, f, s) correctValue := "https://www.do.com?filter%5Baddress%5D=121123&filter%5Bid%5D=121123&sort=age+DESC%2Cname+ASC" if value != correctValue { t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value) } // endpoint2 := "https://www.do.com?" }