Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add due as params for adding/modifying item #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion add.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func Add(c *cli.Context) error {
return names
}(c.String("label-names"))

item.DateString = c.String("date")
if date := c.String("date"); date != "" {
item.Due = &todoist.Due{Date: date}
}
item.AutoReminder = c.Bool("reminder")

if err := client.AddItem(context.Background(), item); err != nil {
Expand Down
24 changes: 24 additions & 0 deletions lib/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func (item Item) AddParam() interface{} {
}
param["auto_reminder"] = item.AutoReminder

if item.Due != nil {
param["due"] = item.Due.Param()
}
return param
}

Expand All @@ -193,6 +196,9 @@ func (item Item) UpdateParam() interface{} {
if item.Priority != 0 {
param["priority"] = item.Priority
}
if item.Due != nil {
param["due"] = item.Due.Param()
}
return param
}

Expand Down Expand Up @@ -258,3 +264,21 @@ func (c *Client) MoveItem(ctx context.Context, item *Item, projectId string) err
}
return c.ExecCommands(ctx, commands)
}

func (d *Due) Param() map[string]interface{} {
if d != nil {
due := map[string]interface{}{}
if d.Date != "" {
due["date"] = d.Date
}
if d.IsRecurring {
due["is_recurring"] = d.IsRecurring
}
if d.String != "" {
due["string"] = d.String
due["lang"] = d.Lang
}
return due
}
return nil
}
5 changes: 4 additions & 1 deletion modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
todoist "github.com/sachaos/todoist/lib"
"strings"

"github.com/urfave/cli"
Expand Down Expand Up @@ -34,7 +35,9 @@ func Modify(c *cli.Context) error {
return names
}(c.String("label-names"))

item.DateString = c.String("date")
if date := c.String("date"); date != "" {
item.Due = &todoist.Due{Date: date}
}

projectID := c.String("project-id")
if projectID == "" {
Expand Down