@@ -2,6 +2,9 @@ package list
22
33import (
44 "fmt"
5+ "github.com/opf/openproject-cli/components/requests"
6+ "github.com/opf/openproject-cli/components/resources"
7+ "github.com/opf/openproject-cli/components/resources/work_packages/filters"
58 "os"
69 "regexp"
710 "strconv"
@@ -23,6 +26,10 @@ var typeFilter string
2326var includeSubProjects bool
2427var subProject string
2528
29+ var activeFilters = []resources.Filter {
30+ filters .NewTimestampFilter (),
31+ }
32+
2633var workPackagesCmd = & cobra.Command {
2734 Use : "workpackages" ,
2835 Aliases : []string {"wps" },
@@ -32,12 +39,19 @@ var workPackagesCmd = &cobra.Command{
3239}
3340
3441func listWorkPackages (_ * cobra.Command , _ []string ) {
42+ // This needs to be removed, once all filters are built the "new" way
3543 if errorText := validateCommandFlags (); len (errorText ) > 0 {
3644 printer .ErrorText (errorText )
3745 return
3846 }
3947
40- collection , err := work_packages .All (filterOptions (), showTotal )
48+ query , err := buildQuery ()
49+ if err != nil {
50+ printer .ErrorText (err .Error ())
51+ return
52+ }
53+
54+ collection , err := work_packages .All (filterOptions (), query , showTotal )
4155 switch {
4256 case err == nil && showTotal :
4357 printer .Number (collection .Total )
@@ -59,6 +73,21 @@ func validateCommandFlags() (errorText string) {
5973 }
6074}
6175
76+ func buildQuery () (requests.Query , error ) {
77+ var q requests.Query
78+
79+ for _ , filter := range activeFilters {
80+ err := filter .ValidateInput ()
81+ if err != nil {
82+ return requests .NewEmptyQuery (), err
83+ }
84+
85+ q = q .Merge (filter .Query ())
86+ }
87+
88+ return q , nil
89+ }
90+
6291func filterOptions () * map [work_packages.FilterOption ]string {
6392 options := make (map [work_packages.FilterOption ]string )
6493
0 commit comments