@@ -8,38 +8,7 @@ import (
88 "time"
99)
1010
11- type TimeEntry struct {
12- Id string
13- Minutes domain.Minutes
14- Date domain.LocalDate
15- Note string
16- Billable bool
17- Locked bool
18- Revenue float64
19- HourlyRate int
20- UserId string
21- UserName string
22- ProjectId string
23- ProjectName string
24- CustomerId string
25- CustomerName string
26- ServiceId string
27- ServiceName string
28- CreatedAt time.Time
29- UpdatedAt time.Time
30- }
31-
32- type TimeEntryCommand struct {
33- Date * domain.LocalDate
34- Minutes * domain.Minutes
35- Note string
36- UserId string
37- ProjectId string
38- ServiceId string
39- Locked bool
40- }
41-
42- func (c * TimeEntryCommand ) toRequest () * timeEntryRequest {
11+ func fromCommand (c * domain.TimeEntryCommand ) * timeEntryRequest {
4312 r := & timeEntryRequest {}
4413 if c .Date != nil {
4514 r .TimeEntry .Date = c .Date .String ()
@@ -56,13 +25,7 @@ func (c *TimeEntryCommand) toRequest() *timeEntryRequest {
5625 return r
5726}
5827
59- type TimeEntryQuery struct {
60- From * domain.LocalDate
61- To * domain.LocalDate
62- Direction string
63- }
64-
65- func (q * TimeEntryQuery ) toValues () url.Values {
28+ func fromQuery (q * domain.TimeEntryQuery ) url.Values {
6629 v := url.Values {}
6730 if q != nil {
6831 if q .From != nil {
@@ -114,13 +77,13 @@ type timeEntryResponse struct {
11477 } `json:"time_entry"`
11578}
11679
117- func (r * timeEntryResponse ) toTimeEntry () * TimeEntry {
80+ func (r * timeEntryResponse ) toTimeEntry () * domain. TimeEntry {
11881 d , err := domain .ParseLocalDate (r .TimeEntry .Date )
11982 if err != nil {
12083 panic (err )
12184 }
12285
123- return & TimeEntry {
86+ return & domain. TimeEntry {
12487 Id : strconv .Itoa (r .TimeEntry .Id ),
12588 Minutes : domain .NewMinutes (r .TimeEntry .Minutes ),
12689 Date : d ,
@@ -142,22 +105,22 @@ func (r *timeEntryResponse) toTimeEntry() *TimeEntry {
142105 }
143106}
144107
145- func (a * api ) TimeEntries (query * TimeEntryQuery ) ([]* TimeEntry , error ) {
108+ func (a * api ) TimeEntries (query * domain. TimeEntryQuery ) ([]* domain. TimeEntry , error ) {
146109 var ter []timeEntryResponse
147- err := a .getParametrized ("time_entries.json" , query . toValues ( ), & ter )
110+ err := a .getParametrized ("time_entries.json" , fromQuery ( query ), & ter )
148111 if err != nil {
149112 return nil , err
150113 }
151114
152- var timeEntries []* TimeEntry
115+ var timeEntries []* domain. TimeEntry
153116 for _ , te := range ter {
154117 timeEntries = append (timeEntries , te .toTimeEntry ())
155118 }
156119
157120 return timeEntries , nil
158121}
159122
160- func (a * api ) TimeEntry (id string ) (* TimeEntry , error ) {
123+ func (a * api ) TimeEntry (id string ) (* domain. TimeEntry , error ) {
161124 ter := timeEntryResponse {}
162125 err := a .get (fmt .Sprintf ("/time_entries/%s.json" , id ), & ter )
163126 if err != nil {
@@ -167,18 +130,18 @@ func (a *api) TimeEntry(id string) (*TimeEntry, error) {
167130 return ter .toTimeEntry (), nil
168131}
169132
170- func (a * api ) CreateTimeEntry (command * TimeEntryCommand ) (* TimeEntry , error ) {
133+ func (a * api ) CreateTimeEntry (command * domain. TimeEntryCommand ) (* domain. TimeEntry , error ) {
171134 ter := timeEntryResponse {}
172- err := a .post ("/time_entries.json" , command . toRequest ( ), & ter )
135+ err := a .post ("/time_entries.json" , fromCommand ( command ), & ter )
173136 if err != nil {
174137 return nil , err
175138 }
176139
177140 return ter .toTimeEntry (), nil
178141}
179142
180- func (a * api ) EditTimeEntry (id string , command * TimeEntryCommand ) error {
181- return a .patch (fmt .Sprintf ("/time_entries/%s.json" , id ), command . toRequest ( ), nil )
143+ func (a * api ) EditTimeEntry (id string , command * domain. TimeEntryCommand ) error {
144+ return a .patch (fmt .Sprintf ("/time_entries/%s.json" , id ), fromCommand ( command ), nil )
182145}
183146
184147func (a * api ) DeleteTimeEntry (id string ) error {
0 commit comments