list project
This commit is contained in:
parent
bf8c2b1f5d
commit
2d8c7556db
|
@ -11,23 +11,33 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListArgs struct {
|
type ListArgs struct {
|
||||||
params storage.TaskListParams
|
fieldTPL map[string][]string
|
||||||
|
params storage.TaskListParams
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListArgs() ListArgs {
|
func NewListArgs() ListArgs {
|
||||||
return ListArgs{}
|
return ListArgs{
|
||||||
|
fieldTPL: map[string][]string{
|
||||||
|
"project": {"p", "project"},
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (la ListArgs) Parse(main []string, flags map[string]string) (Command, error) {
|
func (la ListArgs) Parse(main []string, fields map[string]string) (Command, error) {
|
||||||
if len(main) > 2 {
|
if len(main) > 2 {
|
||||||
return nil, ErrWrongCommand
|
return nil, ErrWrongCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fields, err := ResolveFields(fields, la.fieldTPL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
today := item.NewDate(now.Year(), int(now.Month()), now.Day())
|
today := item.NewDate(now.Year(), int(now.Month()), now.Day())
|
||||||
tomorrow := item.NewDate(now.Year(), int(now.Month()), now.Day()+1)
|
tomorrow := item.NewDate(now.Year(), int(now.Month()), now.Day()+1)
|
||||||
var date item.Date
|
var date item.Date
|
||||||
var includeBefore, recurrer bool
|
var includeBefore, recurrer bool
|
||||||
|
var project string
|
||||||
|
|
||||||
switch len(main) {
|
switch len(main) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -40,7 +50,10 @@ func (la ListArgs) Parse(main []string, flags map[string]string) (Command, error
|
||||||
includeBefore = true
|
includeBefore = true
|
||||||
case slices.Contains([]string{"tomorrow", "tom"}, main[0]):
|
case slices.Contains([]string{"tomorrow", "tom"}, main[0]):
|
||||||
date = tomorrow
|
date = tomorrow
|
||||||
case main[0] == "list":
|
case main[0] == "list" || main[0] == "l":
|
||||||
|
if val, ok := fields["project"]; ok {
|
||||||
|
project = val
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, ErrWrongCommand
|
return nil, ErrWrongCommand
|
||||||
}
|
}
|
||||||
|
@ -60,6 +73,7 @@ func (la ListArgs) Parse(main []string, flags map[string]string) (Command, error
|
||||||
Date: date,
|
Date: date,
|
||||||
IncludeBefore: includeBefore,
|
IncludeBefore: includeBefore,
|
||||||
Recurrer: recurrer,
|
Recurrer: recurrer,
|
||||||
|
Project: project,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -80,6 +80,10 @@ func (t *SqliteTask) FindMany(params storage.TaskListParams) ([]item.Task, error
|
||||||
where = append(where, `date <= ?`)
|
where = append(where, `date <= ?`)
|
||||||
args = append(args, params.Date.String())
|
args = append(args, params.Date.String())
|
||||||
}
|
}
|
||||||
|
if params.Project != "" {
|
||||||
|
where = append(where, `project = ?`)
|
||||||
|
args = append(args, params.Project)
|
||||||
|
}
|
||||||
|
|
||||||
if len(where) > 0 {
|
if len(where) > 0 {
|
||||||
query += ` WHERE ` + where[0]
|
query += ` WHERE ` + where[0]
|
||||||
|
|
|
@ -32,6 +32,7 @@ type TaskListParams struct {
|
||||||
Recurrer bool
|
Recurrer bool
|
||||||
Date item.Date
|
Date item.Date
|
||||||
IncludeBefore bool
|
IncludeBefore bool
|
||||||
|
Project string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Task interface {
|
type Task interface {
|
||||||
|
@ -53,6 +54,9 @@ func Match(tsk item.Task, params TaskListParams) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if params.Project != "" && params.Project != tsk.Project {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,16 @@ func TestMatch(t *testing.T) {
|
||||||
Date: item.NewDate(2024, 12, 29),
|
Date: item.NewDate(2024, 12, 29),
|
||||||
Recurrer: item.NewRecurrer("2024-12-29, daily"),
|
Recurrer: item.NewRecurrer("2024-12-29, daily"),
|
||||||
TaskBody: item.TaskBody{
|
TaskBody: item.TaskBody{
|
||||||
Title: "name",
|
Title: "name",
|
||||||
|
Project: "p1",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tskNotMatch := item.Task{
|
tskNotMatch := item.Task{
|
||||||
ID: "id",
|
ID: "id",
|
||||||
Date: item.NewDate(2024, 12, 28),
|
Date: item.NewDate(2024, 12, 28),
|
||||||
TaskBody: item.TaskBody{
|
TaskBody: item.TaskBody{
|
||||||
Title: "name",
|
Title: "name",
|
||||||
|
Project: "p2",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +44,12 @@ func TestMatch(t *testing.T) {
|
||||||
Recurrer: true,
|
Recurrer: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "project",
|
||||||
|
params: storage.TaskListParams{
|
||||||
|
Project: "p1",
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
if !storage.Match(tskMatch, tc.params) {
|
if !storage.Match(tskMatch, tc.params) {
|
||||||
|
|
Loading…
Reference in New Issue