diff --git a/mite/time_entry.go b/mite/time_entry.go index c455604..61fd225 100644 --- a/mite/time_entry.go +++ b/mite/time_entry.go @@ -5,18 +5,29 @@ import ( "github.com/leanovate/mite-go/date" "math" "net/url" + "strconv" "time" ) type TimeEntry struct { - Id string - Note string - Date date.LocalDate - Duration time.Duration - ProjectId string - ProjectName string - ServiceId string - ServiceName string + Id string + Duration time.Duration + Date date.LocalDate + Note string + Billable bool + Locked bool + Revenue float64 + HourlyRate int + UserId string + UserName string + ProjectId string + ProjectName string + CustomerId string + CustomerName string + ServiceId string + ServiceName string + CreatedAt time.Time + UpdatedAt time.Time } type TimeEntryCommand struct { @@ -83,32 +94,52 @@ type timeEntryRequest struct { type timeEntryResponse struct { TimeEntry struct { - Id int `json:"id"` - Note string `json:"note"` - Minutes int `json:"minutes"` - Date string `json:"date_at"` - ProjectId int `json:"project_id"` - ProjectName string `json:"project_name"` - ServiceId int `json:"service_id"` - ServiceName string `json:"service_name"` + Id int `json:"id"` + Minutes int `json:"minutes"` + Date string `json:"date_at"` + Note string `json:"note"` + Billable bool `json:"billable"` + Locked bool `json:"locked"` + Revenue float64 `json:"revenue"` + HourlyRate int `json:"hourly_rate"` + UserId int `json:"user_id"` + UserName string `json:"user_name"` + ProjectId int `json:"project_id"` + ProjectName string `json:"project_name"` + CustomerId int `json:"customer_id"` + CustomerName string `json:"customer_name"` + ServiceId int `json:"service_id"` + ServiceName string `json:"service_name"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } `json:"time_entry"` } -func (r *timeEntryResponse) ToTimeEntry() *TimeEntry { +func (r *timeEntryResponse) toTimeEntry() *TimeEntry { d, err := date.Parse(r.TimeEntry.Date) if err != nil { panic(err) } return &TimeEntry{ - Id: fmt.Sprintf("%d", r.TimeEntry.Id), - Note: r.TimeEntry.Note, - Duration: time.Duration(r.TimeEntry.Minutes) * time.Minute, - Date: d, - ProjectId: fmt.Sprintf("%d", r.TimeEntry.ProjectId), - ProjectName: r.TimeEntry.ProjectName, - ServiceId: fmt.Sprintf("%d", r.TimeEntry.ServiceId), - ServiceName: r.TimeEntry.ServiceName, + Id: strconv.Itoa(r.TimeEntry.Id), + Duration: time.Duration(r.TimeEntry.Minutes) * time.Minute, + Date: d, + Note: r.TimeEntry.Note, + Billable: r.TimeEntry.Billable, + Locked: r.TimeEntry.Locked, + Revenue: r.TimeEntry.Revenue, + HourlyRate: r.TimeEntry.HourlyRate, + UserId: strconv.Itoa(r.TimeEntry.UserId), + UserName: r.TimeEntry.UserName, + ProjectId: strconv.Itoa(r.TimeEntry.ProjectId), + ProjectName: r.TimeEntry.ProjectName, + CustomerId: strconv.Itoa(r.TimeEntry.CustomerId), + CustomerName: r.TimeEntry.CustomerName, + ServiceId: strconv.Itoa(r.TimeEntry.ServiceId), + ServiceName: r.TimeEntry.ServiceName, + CreatedAt: r.TimeEntry.CreatedAt, + UpdatedAt: r.TimeEntry.UpdatedAt, } } @@ -121,7 +152,7 @@ func (a *api) TimeEntries(query *TimeEntryQuery) ([]*TimeEntry, error) { var timeEntries []*TimeEntry for _, te := range ter { - timeEntries = append(timeEntries, te.ToTimeEntry()) + timeEntries = append(timeEntries, te.toTimeEntry()) } return timeEntries, nil @@ -134,7 +165,7 @@ func (a *api) TimeEntry(id string) (*TimeEntry, error) { return nil, err } - return ter.ToTimeEntry(), nil + return ter.toTimeEntry(), nil } func (a *api) CreateTimeEntry(command *TimeEntryCommand) (*TimeEntry, error) { @@ -144,7 +175,7 @@ func (a *api) CreateTimeEntry(command *TimeEntryCommand) (*TimeEntry, error) { return nil, err } - return ter.ToTimeEntry(), nil + return ter.toTimeEntry(), nil } func (a *api) EditTimeEntry(id string, command *TimeEntryCommand) error {