Skip to content

Commit

Permalink
entries: implemented list ordering & refactored direction to string i…
Browse files Browse the repository at this point in the history
…n API
  • Loading branch information
phiros committed Apr 3, 2019
1 parent d25c900 commit df789d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
8 changes: 4 additions & 4 deletions cmd-entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var entriesListCommand = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
api := mite.NewMiteApi(configGetApiUrl(), configGetApiKey())

direction := mite.DirectionAsc
direction := listOrder

to, err := time.Parse("2006-01-02", listTo)
if err != nil {
Expand All @@ -54,7 +54,7 @@ var entriesListCommand = &cobra.Command{
entries, err := api.TimeEntries(&mite.TimeEntryParameters{
To: &to,
From: &from,
Direction: &direction,
Direction: direction,
})
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
Expand All @@ -65,9 +65,9 @@ var entriesListCommand = &cobra.Command{
t.AddHeader("id", "notes", "date", "time", "project,service")
for _, entry := range entries {
trimmedNotes := strings.Replace(entry.Note, "\r\n", ",", -1)
shortendNotes := fmt.Sprintf("%.50s", trimmedNotes)
shortenedNotes := fmt.Sprintf("%.50s", trimmedNotes)
shortenedProjectService := fmt.Sprintf("%.50s", entry.ProjectName+","+entry.ServiceName)
t.AddLine(entry.Id, shortendNotes, entry.Date, entry.Duration.String(), shortenedProjectService)
t.AddLine(entry.Id, shortenedNotes, entry.Date, entry.Duration.String(), shortenedProjectService)
}
t.Print()
},
Expand Down
18 changes: 3 additions & 15 deletions mite/time_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@ type TimeEntry struct {
ServiceName string
}

type Direction int

const (
DirectionAsc = Direction(0)
DirectionDesc = Direction(1)
)

type TimeEntryParameters struct {
From *time.Time
To *time.Time
Direction *Direction
Direction string
}

func (a *miteApi) TimeEntries(params *TimeEntryParameters) ([]TimeEntry, error) {
Expand All @@ -37,13 +30,8 @@ func (a *miteApi) TimeEntries(params *TimeEntryParameters) ([]TimeEntry, error)
if params.To != nil {
values.Add("to", params.To.Format(layout))
}
if params.Direction != nil {
switch *params.Direction {
case DirectionAsc:
values.Add("direction", "asc")
case DirectionDesc:
values.Add("direction", "desc")
}
if params.Direction != "" {
values.Add("direction", params.Direction)
}
}

Expand Down

0 comments on commit df789d9

Please sign in to comment.