From 48eb049f4903a6da34f5b54eb2cbcb81e0e2d1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20Liss=C3=A9?= Date: Mon, 8 Apr 2019 11:46:29 +0200 Subject: [PATCH] Extract Tracker model --- domain/tracker.go | 14 ++++++++++++++ mite/api.go | 6 +++--- mite/tracker.go | 25 +++++++------------------ 3 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 domain/tracker.go diff --git a/domain/tracker.go b/domain/tracker.go new file mode 100644 index 0000000..151ceb4 --- /dev/null +++ b/domain/tracker.go @@ -0,0 +1,14 @@ +package domain + +import "time" + +type TrackingTimeEntry struct { + Id string + Minutes Minutes + Since time.Time +} + +type StoppedTimeEntry struct { + Id string + Minutes Minutes +} diff --git a/mite/api.go b/mite/api.go index 11db8e8..316d4e5 100644 --- a/mite/api.go +++ b/mite/api.go @@ -23,9 +23,9 @@ type TimeEntryApi interface { } type TrackerApi interface { - Tracker() (*TrackingTimeEntry, error) - StartTracker(id string) (*TrackingTimeEntry, *StoppedTimeEntry, error) - StopTracker(id string) (*StoppedTimeEntry, error) + Tracker() (*domain.TrackingTimeEntry, error) + StartTracker(id string) (*domain.TrackingTimeEntry, *domain.StoppedTimeEntry, error) + StopTracker(id string) (*domain.StoppedTimeEntry, error) } type CustomerApi interface{} diff --git a/mite/tracker.go b/mite/tracker.go index 6485d99..3e43bac 100644 --- a/mite/tracker.go +++ b/mite/tracker.go @@ -7,17 +7,6 @@ import ( "time" ) -type TrackingTimeEntry struct { - Id string - Minutes domain.Minutes - Since time.Time -} - -type StoppedTimeEntry struct { - Id string - Minutes domain.Minutes -} - type trackerResponse struct { Tracker struct { TrackingTimeEntry *struct { @@ -32,30 +21,30 @@ type trackerResponse struct { } `json:"tracker"` } -func (r *trackerResponse) toTrackingTimeEntry() *TrackingTimeEntry { +func (r *trackerResponse) toTrackingTimeEntry() *domain.TrackingTimeEntry { if r.Tracker.TrackingTimeEntry == nil { return nil } - return &TrackingTimeEntry{ + return &domain.TrackingTimeEntry{ Id: strconv.Itoa(r.Tracker.TrackingTimeEntry.Id), Minutes: domain.NewMinutes(r.Tracker.TrackingTimeEntry.Minutes), Since: r.Tracker.TrackingTimeEntry.Since, } } -func (r *trackerResponse) toStoppedTimeEntry() *StoppedTimeEntry { +func (r *trackerResponse) toStoppedTimeEntry() *domain.StoppedTimeEntry { if r.Tracker.StoppedTimeEntry == nil { return nil } - return &StoppedTimeEntry{ + return &domain.StoppedTimeEntry{ Id: strconv.Itoa(r.Tracker.StoppedTimeEntry.Id), Minutes: domain.NewMinutes(r.Tracker.StoppedTimeEntry.Minutes), } } -func (a *api) Tracker() (*TrackingTimeEntry, error) { +func (a *api) Tracker() (*domain.TrackingTimeEntry, error) { tr := trackerResponse{} err := a.get("/tracker.json", &tr) if err != nil { @@ -65,7 +54,7 @@ func (a *api) Tracker() (*TrackingTimeEntry, error) { return tr.toTrackingTimeEntry(), nil } -func (a *api) StartTracker(id string) (*TrackingTimeEntry, *StoppedTimeEntry, error) { +func (a *api) StartTracker(id string) (*domain.TrackingTimeEntry, *domain.StoppedTimeEntry, error) { tr := &trackerResponse{} err := a.patch(fmt.Sprintf("/tracker/%s.json", id), nil, tr) if err != nil { @@ -75,7 +64,7 @@ func (a *api) StartTracker(id string) (*TrackingTimeEntry, *StoppedTimeEntry, er return tr.toTrackingTimeEntry(), tr.toStoppedTimeEntry(), nil } -func (a *api) StopTracker(id string) (*StoppedTimeEntry, error) { +func (a *api) StopTracker(id string) (*domain.StoppedTimeEntry, error) { tr := &trackerResponse{} err := a.delete(fmt.Sprintf("/tracker/%s.json", id), tr) if err != nil {