-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcustomer.go
55 lines (45 loc) · 1.7 KB
/
customer.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
package mite
import (
"fmt"
"time"
)
// -------------------------------------------------------------
// ~ Types
// -------------------------------------------------------------
// Customer mite customer type
type Customer struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Note string `json:"note"`
ActiveHourlyRate string `json:"active_hourly_rate"`
HourlyRate uint64 `json:"hourly_rate"`
Archived bool `json:"archived"`
HourlyRatesPerService []ServiceHourlyRates `json:"hourly_rates_per_service"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (c *Customer) String() string {
return fmt.Sprintf("%d: %s for %s (archived: %t)", c.ID, c.Name, c.Name, c.Archived)
}
type getCustomersResponseWrapper struct {
Customer *Customer `json:"customer"`
}
// -------------------------------------------------------------
// ~ Functions
// -------------------------------------------------------------
// GetCustomers returns all customers if filters are nil otherwise a filtered subset
// filters can be looked up on the mite page e.g. name
func (m *Mite) GetCustomers(filters map[string]string) ([]*Customer, error) {
var cusRes []*getCustomersResponseWrapper
err := m.getAndDecodeFromSuffix("customers.json", &cusRes, filters)
if err != nil {
return nil, err
}
customers := make([]*Customer, len(cusRes))
// Unwrap all the data
for i, c := range cusRes {
customers[i] = c.Customer
//fmt.Println("Customer", c.Customer)
}
return customers, nil
}