From 2f6a05c303b2406b2c5f8cbe3f991ef534b83255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20Liss=C3=A9?= Date: Mon, 8 Apr 2019 11:27:09 +0200 Subject: [PATCH] Introduce domain package --- cmd/entries.go | 18 +++++++++--------- cmd/tracker.go | 4 ++-- {datetime => domain}/local_date.go | 2 +- {datetime => domain}/local_date_test.go | 18 +++++++++--------- {datetime => domain}/minutes.go | 2 +- {datetime => domain}/minutes_test.go | 16 ++++++++-------- mite/time_entry.go | 18 +++++++++--------- mite/tracker.go | 10 +++++----- 8 files changed, 44 insertions(+), 44 deletions(-) rename {datetime => domain}/local_date.go (97%) rename {datetime => domain}/local_date_test.go (53%) rename {datetime => domain}/minutes.go (96%) rename {datetime => domain}/minutes_test.go (57%) diff --git a/cmd/entries.go b/cmd/entries.go index 6b91ddd..79eed3f 100644 --- a/cmd/entries.go +++ b/cmd/entries.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" "github.com/cheynewallace/tabby" - "github.com/leanovate/mite-go/datetime" + "github.com/leanovate/mite-go/domain" "github.com/leanovate/mite-go/mite" "github.com/spf13/cobra" "strings" @@ -31,9 +31,9 @@ var ( ) func init() { - today := datetime.Today() + today := domain.Today() defaultFrom := today.Add(0, 0, -7) - defaultMinutes := datetime.NewMinutes(0).String() + defaultMinutes := domain.NewMinutes(0).String() // list entriesListCommand.Flags().StringVarP(&listTo, "to", "t", today.String(), "list only entries until date (in YYYY-MM-DD format)") @@ -75,11 +75,11 @@ var entriesListCommand = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { direction := listOrder - to, err := datetime.ParseLocalDate(listTo) + to, err := domain.ParseLocalDate(listTo) if err != nil { return err } - from, err := datetime.ParseLocalDate(listFrom) + from, err := domain.ParseLocalDate(listFrom) if err != nil { return err } @@ -121,11 +121,11 @@ var entriesCreateCommand = &cobra.Command{ return errors.New("please set both the project AND service id (either via arguments or config)") } - cDate, err := datetime.ParseLocalDate(createDate) + cDate, err := domain.ParseLocalDate(createDate) if err != nil { return err } - cMinutes, err := datetime.ParseMinutes(createMinutes) + cMinutes, err := domain.ParseMinutes(createMinutes) if err != nil { return err } @@ -190,7 +190,7 @@ var entriesEditCommand = &cobra.Command{ // override only fields affected by set parameters of edit if editDate != "" { - eDate, err := datetime.ParseLocalDate(editDate) + eDate, err := domain.ParseLocalDate(editDate) if err != nil { return err } @@ -198,7 +198,7 @@ var entriesEditCommand = &cobra.Command{ } if editMinutes != "" { - eMinutes, err := datetime.ParseMinutes(editMinutes) + eMinutes, err := domain.ParseMinutes(editMinutes) if err != nil { return err } diff --git a/cmd/tracker.go b/cmd/tracker.go index a532635..6a5c818 100644 --- a/cmd/tracker.go +++ b/cmd/tracker.go @@ -3,7 +3,7 @@ package cmd import ( "errors" "github.com/cheynewallace/tabby" - "github.com/leanovate/mite-go/datetime" + "github.com/leanovate/mite-go/domain" "github.com/leanovate/mite-go/mite" "github.com/spf13/cobra" ) @@ -102,7 +102,7 @@ var trackerStopCommand = &cobra.Command{ } func fetchLatestTimeEntryForToday() (string, error) { - today := datetime.Today() + today := domain.Today() entries, err := deps.miteApi.TimeEntries(&mite.TimeEntryQuery{ To: &today, diff --git a/datetime/local_date.go b/domain/local_date.go similarity index 97% rename from datetime/local_date.go rename to domain/local_date.go index 8fe6954..40a6ac3 100644 --- a/datetime/local_date.go +++ b/domain/local_date.go @@ -1,4 +1,4 @@ -package datetime +package domain import "time" diff --git a/datetime/local_date_test.go b/domain/local_date_test.go similarity index 53% rename from datetime/local_date_test.go rename to domain/local_date_test.go index 938d5a6..21f8eeb 100644 --- a/datetime/local_date_test.go +++ b/domain/local_date_test.go @@ -1,7 +1,7 @@ -package datetime_test +package domain_test import ( - "github.com/leanovate/mite-go/datetime" + "github.com/leanovate/mite-go/domain" "github.com/stretchr/testify/assert" "testing" "time" @@ -9,26 +9,26 @@ import ( func TestToday(t *testing.T) { expected := time.Now().Local().Format("2006-01-02") - actual := datetime.Today().String() + actual := domain.Today().String() assert.Equal(t, expected, actual) } func TestParseLocalDate(t *testing.T) { - expected := datetime.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)) - actual, err := datetime.ParseLocalDate("1970-01-01") + expected := domain.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)) + actual, err := domain.ParseLocalDate("1970-01-01") assert.Nil(t, err) assert.Equal(t, expected, actual) - _, err = datetime.ParseLocalDate("1970-01-01T00:00:00Z") + _, err = domain.ParseLocalDate("1970-01-01T00:00:00Z") assert.IsType(t, &time.ParseError{}, err) } func TestLocalDate_Add(t *testing.T) { - expected := datetime.NewLocalDate(time.Date(1971, time.February, 2, 0, 0, 0, 0, time.Local)) - actual := datetime. + expected := domain.NewLocalDate(time.Date(1971, time.February, 2, 0, 0, 0, 0, time.Local)) + actual := domain. NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)). Add(1, 1, 1) @@ -37,7 +37,7 @@ func TestLocalDate_Add(t *testing.T) { func TestLocalDate_String(t *testing.T) { expected := "1970-01-01" - actual := datetime.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)).String() + actual := domain.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)).String() assert.Equal(t, expected, actual) } diff --git a/datetime/minutes.go b/domain/minutes.go similarity index 96% rename from datetime/minutes.go rename to domain/minutes.go index 6347559..1b2953b 100644 --- a/datetime/minutes.go +++ b/domain/minutes.go @@ -1,4 +1,4 @@ -package datetime +package domain import ( "math" diff --git a/datetime/minutes_test.go b/domain/minutes_test.go similarity index 57% rename from datetime/minutes_test.go rename to domain/minutes_test.go index 41a8fb3..d305832 100644 --- a/datetime/minutes_test.go +++ b/domain/minutes_test.go @@ -1,37 +1,37 @@ -package datetime_test +package domain_test import ( - "github.com/leanovate/mite-go/datetime" + "github.com/leanovate/mite-go/domain" "github.com/stretchr/testify/assert" "testing" ) func Test_ParseMinutes(t *testing.T) { - expected := datetime.NewMinutes(23) - actual, err := datetime.ParseMinutes("23m") + expected := domain.NewMinutes(23) + actual, err := domain.ParseMinutes("23m") assert.Nil(t, err) assert.Equal(t, expected, actual) - actual, err = datetime.ParseMinutes("22m33s") + actual, err = domain.ParseMinutes("22m33s") assert.Nil(t, err) assert.Equal(t, expected, actual) - _, err = datetime.ParseMinutes("1970-01-01") + _, err = domain.ParseMinutes("1970-01-01") assert.NotNil(t, err) } func TestMinutes_Value(t *testing.T) { expected := 23 - actual := datetime.NewMinutes(23).Value() + actual := domain.NewMinutes(23).Value() assert.Equal(t, expected, actual) } func TestMinutes_String(t *testing.T) { expected := "23m" - actual := datetime.NewMinutes(23).String() + actual := domain.NewMinutes(23).String() assert.Equal(t, expected, actual) } diff --git a/mite/time_entry.go b/mite/time_entry.go index b0d04ee..7c879e4 100644 --- a/mite/time_entry.go +++ b/mite/time_entry.go @@ -2,7 +2,7 @@ package mite import ( "fmt" - "github.com/leanovate/mite-go/datetime" + "github.com/leanovate/mite-go/domain" "net/url" "strconv" "time" @@ -10,8 +10,8 @@ import ( type TimeEntry struct { Id string - Minutes datetime.Minutes - Date datetime.LocalDate + Minutes domain.Minutes + Date domain.LocalDate Note string Billable bool Locked bool @@ -30,8 +30,8 @@ type TimeEntry struct { } type TimeEntryCommand struct { - Date *datetime.LocalDate - Minutes *datetime.Minutes + Date *domain.LocalDate + Minutes *domain.Minutes Note string UserId string ProjectId string @@ -57,8 +57,8 @@ func (c *TimeEntryCommand) toRequest() *timeEntryRequest { } type TimeEntryQuery struct { - From *datetime.LocalDate - To *datetime.LocalDate + From *domain.LocalDate + To *domain.LocalDate Direction string } @@ -115,14 +115,14 @@ type timeEntryResponse struct { } func (r *timeEntryResponse) toTimeEntry() *TimeEntry { - d, err := datetime.ParseLocalDate(r.TimeEntry.Date) + d, err := domain.ParseLocalDate(r.TimeEntry.Date) if err != nil { panic(err) } return &TimeEntry{ Id: strconv.Itoa(r.TimeEntry.Id), - Minutes: datetime.NewMinutes(r.TimeEntry.Minutes), + Minutes: domain.NewMinutes(r.TimeEntry.Minutes), Date: d, Note: r.TimeEntry.Note, Billable: r.TimeEntry.Billable, diff --git a/mite/tracker.go b/mite/tracker.go index 97ed1d2..6485d99 100644 --- a/mite/tracker.go +++ b/mite/tracker.go @@ -2,20 +2,20 @@ package mite import ( "fmt" - "github.com/leanovate/mite-go/datetime" + "github.com/leanovate/mite-go/domain" "strconv" "time" ) type TrackingTimeEntry struct { Id string - Minutes datetime.Minutes + Minutes domain.Minutes Since time.Time } type StoppedTimeEntry struct { Id string - Minutes datetime.Minutes + Minutes domain.Minutes } type trackerResponse struct { @@ -39,7 +39,7 @@ func (r *trackerResponse) toTrackingTimeEntry() *TrackingTimeEntry { return &TrackingTimeEntry{ Id: strconv.Itoa(r.Tracker.TrackingTimeEntry.Id), - Minutes: datetime.NewMinutes(r.Tracker.TrackingTimeEntry.Minutes), + Minutes: domain.NewMinutes(r.Tracker.TrackingTimeEntry.Minutes), Since: r.Tracker.TrackingTimeEntry.Since, } } @@ -51,7 +51,7 @@ func (r *trackerResponse) toStoppedTimeEntry() *StoppedTimeEntry { return &StoppedTimeEntry{ Id: strconv.Itoa(r.Tracker.StoppedTimeEntry.Id), - Minutes: datetime.NewMinutes(r.Tracker.StoppedTimeEntry.Minutes), + Minutes: domain.NewMinutes(r.Tracker.StoppedTimeEntry.Minutes), } }