Skip to content

Commit 74f23bf

Browse files
committed
more wprk
1 parent 5be043c commit 74f23bf

File tree

4 files changed

+88
-54
lines changed

4 files changed

+88
-54
lines changed

cmd/bill.go

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ package cmd
66
import (
77
"fmt"
88
"github.com/JankariTech/OpenProjectTmetricIntegration/config"
9+
"github.com/JankariTech/OpenProjectTmetricIntegration/openproject"
910
"github.com/JankariTech/OpenProjectTmetricIntegration/tmetric"
11+
"github.com/Masterminds/sprig/v3"
1012
"github.com/spf13/cobra"
11-
"math"
1213
"os"
1314
"strings"
1415
"text/template"
1516
"time"
1617
)
1718

19+
var billNumber string
20+
var tmplFile string
21+
1822
// billCmd represents the bill command
1923
var billCmd = &cobra.Command{
2024
Use: "bill",
@@ -33,17 +37,14 @@ var billCmd = &cobra.Command{
3337
},
3438
Run: func(cmd *cobra.Command, args []string) {
3539
config := config.NewConfig()
36-
//
3740
tmetricUser := tmetric.NewUser()
38-
tmetricTimeEntries, err := tmetric.GetAllTimeEntries(config, tmetricUser, startDate, endDate)
39-
if err != nil {
40-
_, _ = fmt.Fprint(os.Stderr, err)
41-
os.Exit(1)
42-
}
4341

4442
funcMap := template.FuncMap{
43+
"BillNumber": func() string {
44+
return billNumber
45+
},
4546
"DetailedReport": func(clientName string, tagName string, groupName string) tmetric.Report {
46-
report, _ := tmetric.GetDetailedReport(clientName, tagName, groupName, startDate, endDate)
47+
report, _ := tmetric.GetDetailedReport(config, tmetricUser, clientName, tagName, groupName, startDate, endDate)
4748
return report
4849
},
4950
"AllWorkTypes": func() []tmetric.Tag {
@@ -54,40 +55,43 @@ var billCmd = &cobra.Command{
5455
teams, _ := tmetric.GetAllTeams(config, tmetricUser)
5556
return teams
5657
},
57-
"Increment": func(i int) int {
58-
return i + 1
59-
},
60-
"Round": func(f float64) float64 {
61-
return math.Round(f*100) / 100
62-
},
63-
"FormatFloat": func(f float64) string {
58+
"formatFloat": func(f float64) string {
6459
s := fmt.Sprintf("%.2f", f)
6560
return strings.Replace(s, ".", ",", -1)
6661
},
67-
"Add": func(a float64, b float64) float64 {
68-
return a + b
69-
},
70-
"Multiply": func(a float64, b float64) float64 {
71-
return a * b
72-
},
7362
"ServiceDate": func() string {
7463
startTime, _ := time.Parse("2006-01-02", startDate)
7564
return startTime.Format("01/2006")
7665
},
66+
"AllTimeEntries": func(user string) []openproject.TimeEntry {
67+
var openProjectUser openproject.User
68+
openProjectUser, err := openproject.FindUserByName(config, user)
69+
if err != nil {
70+
_, _ = fmt.Fprint(os.Stderr, err)
71+
os.Exit(1)
72+
}
73+
openProjectTimeEntries, err := openproject.GetAllTimeEntries(config, openProjectUser, startDate, endDate)
74+
if err != nil {
75+
_, _ = fmt.Fprint(os.Stderr, err)
76+
os.Exit(1)
77+
}
78+
return openProjectTimeEntries
79+
},
7780
}
78-
if err != nil {
79-
_, _ = fmt.Fprint(os.Stderr, err)
80-
os.Exit(1)
81+
// add all the functions from sprig
82+
for i, f := range sprig.FuncMap() {
83+
funcMap[i] = f
8184
}
82-
var tmplFile = "openproject.tmpl"
8385

84-
tmpl, err := template.New(tmplFile).Funcs(funcMap).ParseFiles(tmplFile)
86+
tmpl, err := template.New("bill").Funcs(funcMap).ParseFiles(tmplFile)
8587
if err != nil {
86-
panic(err)
88+
_, _ = fmt.Fprint(os.Stderr, fmt.Errorf("could not parse template file '%v': %v", tmplFile, err))
89+
os.Exit(1)
8790
}
88-
err = tmpl.Execute(os.Stdout, tmetricTimeEntries)
91+
err = tmpl.Execute(os.Stdout, nil)
8992
if err != nil {
90-
panic(err)
93+
_, _ = fmt.Fprint(os.Stderr, fmt.Errorf("could not execute template: %v", err))
94+
os.Exit(1)
9195
}
9296
},
9397
}
@@ -101,4 +105,8 @@ func init() {
101105
billCmd.Flags().StringVarP(&startDate, "start", "s", firstDayOfMonth, "start date")
102106
today := time.Now().Format("2006-01-02")
103107
billCmd.Flags().StringVarP(&endDate, "end", "e", today, "end date")
108+
billCmd.Flags().StringVarP(&billNumber, "billNumber", "b", today, "the bill number")
109+
billCmd.MarkFlagRequired("billNumber")
110+
billCmd.Flags().StringVarP(&tmplFile, "template", "t", today, "the template file")
111+
billCmd.MarkFlagRequired("template")
104112
}

go.mod

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,58 @@ module github.com/JankariTech/OpenProjectTmetricIntegration
33
go 1.21.7
44

55
require (
6+
github.com/Masterminds/sprig/v3 v3.3.0
7+
github.com/briandowns/spinner v1.23.1
8+
github.com/go-chrono/chrono v0.0.0-20240102183611-532f0d0d7c34
69
github.com/go-resty/resty/v2 v2.15.3
10+
github.com/jedib0t/go-pretty/v6 v6.6.1
711
github.com/manifoldco/promptui v0.9.0
812
github.com/spf13/cobra v1.8.1
913
github.com/spf13/viper v1.19.0
1014
github.com/stretchr/testify v1.9.0
1115
github.com/tidwall/gjson v1.18.0
16+
golang.org/x/term v0.25.0
1217
)
1318

1419
require (
15-
github.com/briandowns/spinner v1.23.1 // indirect
20+
dario.cat/mergo v1.0.1 // indirect
21+
github.com/Masterminds/goutils v1.1.1 // indirect
22+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
1623
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
1724
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1825
github.com/fatih/color v1.14.1 // indirect
1926
github.com/fsnotify/fsnotify v1.7.0 // indirect
20-
github.com/go-chrono/chrono v0.0.0-20240102183611-532f0d0d7c34 // indirect
27+
github.com/google/uuid v1.6.0 // indirect
2128
github.com/hashicorp/hcl v1.0.0 // indirect
29+
github.com/huandu/xstrings v1.5.0 // indirect
2230
github.com/inconshreveable/mousetrap v1.1.0 // indirect
23-
github.com/jedib0t/go-pretty/v6 v6.6.1 // indirect
2431
github.com/magiconair/properties v1.8.7 // indirect
2532
github.com/mattn/go-colorable v0.1.13 // indirect
2633
github.com/mattn/go-isatty v0.0.17 // indirect
2734
github.com/mattn/go-runewidth v0.0.15 // indirect
35+
github.com/mitchellh/copystructure v1.2.0 // indirect
2836
github.com/mitchellh/mapstructure v1.5.0 // indirect
37+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
2938
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
3039
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3140
github.com/rivo/uniseg v0.2.0 // indirect
3241
github.com/sagikazarmark/locafero v0.4.0 // indirect
3342
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
43+
github.com/shopspring/decimal v1.4.0 // indirect
3444
github.com/sourcegraph/conc v0.3.0 // indirect
3545
github.com/spf13/afero v1.11.0 // indirect
36-
github.com/spf13/cast v1.6.0 // indirect
46+
github.com/spf13/cast v1.7.0 // indirect
3747
github.com/spf13/pflag v1.0.5 // indirect
3848
github.com/subosito/gotenv v1.6.0 // indirect
3949
github.com/tidwall/match v1.1.1 // indirect
4050
github.com/tidwall/pretty v1.2.0 // indirect
4151
go.uber.org/atomic v1.9.0 // indirect
4252
go.uber.org/multierr v1.9.0 // indirect
53+
golang.org/x/crypto v0.26.0 // indirect
4354
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
4455
golang.org/x/net v0.27.0 // indirect
4556
golang.org/x/sys v0.26.0 // indirect
46-
golang.org/x/term v0.25.0 // indirect
47-
golang.org/x/text v0.16.0 // indirect
57+
golang.org/x/text v0.17.0 // indirect
4858
gopkg.in/ini.v1 v1.67.0 // indirect
4959
gopkg.in/yaml.v3 v3.0.1 // indirect
5060
)

go.sum

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
2+
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
3+
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
4+
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
5+
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
6+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
7+
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
8+
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
19
github.com/briandowns/spinner v1.23.1 h1:t5fDPmScwUjozhDj4FA46p5acZWIPXYE30qW2Ptu650=
210
github.com/briandowns/spinner v1.23.1/go.mod h1:LaZeM4wm2Ywy6vO571mvhQNRcWfRUnXOs0RcKV0wYKM=
311
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
@@ -21,10 +29,14 @@ github.com/go-chrono/chrono v0.0.0-20240102183611-532f0d0d7c34 h1:eG+4Rhfp++D0gL
2129
github.com/go-chrono/chrono v0.0.0-20240102183611-532f0d0d7c34/go.mod h1:uTWQdzrjtft2vWY+f+KQ9e3DXHsP0SzhE5SLIicFo08=
2230
github.com/go-resty/resty/v2 v2.15.3 h1:bqff+hcqAflpiF591hhJzNdkRsFhlB96CYfBwSFvql8=
2331
github.com/go-resty/resty/v2 v2.15.3/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
24-
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
25-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
32+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
33+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
34+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
35+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2636
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
2737
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
38+
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
39+
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
2840
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
2941
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
3042
github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtxYVWyc=
@@ -44,8 +56,12 @@ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPn
4456
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
4557
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
4658
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
59+
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
60+
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
4761
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
4862
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
63+
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
64+
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
4965
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
5066
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
5167
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -60,12 +76,14 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
6076
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
6177
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
6278
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
79+
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
80+
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
6381
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
6482
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
6583
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
6684
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
67-
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
68-
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
85+
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
86+
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
6987
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
7088
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
7189
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -94,22 +112,20 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
94112
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
95113
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
96114
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
115+
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
116+
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
97117
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
98118
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
99119
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
100120
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
101121
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
102122
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
103-
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
104-
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
105123
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
106124
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
107-
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
108-
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
109125
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
110126
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
111-
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
112-
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
127+
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
128+
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
113129
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
114130
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
115131
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

tmetric/report.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
type ReportItem struct {
1414
StartTime string `json:"startTime"`
1515
EndTime string `json:"endTime"`
16+
User string `json:"user"`
1617
}
1718

1819
type Report struct {
@@ -53,25 +54,24 @@ func (reportItem *ReportItem) getDuration() (time.Duration, error) {
5354
return duration, nil
5455
}
5556

56-
func GetDetailedReport(clientName string, tagName string, groupName string, startDate string, endDate string) (Report, error) {
57-
conf := config.NewConfig()
58-
tmetricUser := NewUser()
59-
60-
client, err := getClientByName(conf, tmetricUser, clientName)
57+
func GetDetailedReport(
58+
config *config.Config, tmetricUser User, clientName string, tagName string, groupName string, startDate string, endDate string,
59+
) (Report, error) {
60+
client, err := getClientByName(config, tmetricUser, clientName)
6161
if err != nil {
6262
return Report{}, err
6363
}
6464

65-
team, err := getTeamByName(conf, tmetricUser, groupName)
65+
team, err := getTeamByName(config, tmetricUser, groupName)
6666
if err != nil {
6767
return Report{}, err
6868
}
6969
httpClient := resty.New()
70-
tmetricUrl, _ := url.JoinPath(conf.TmetricAPIBaseUrl, "reports/detailed")
70+
tmetricUrl, _ := url.JoinPath(config.TmetricAPIBaseUrl, "reports/detailed")
7171
request := httpClient.R()
7272

7373
if tagName != "" {
74-
workType, err := getWorkTypeByName(conf, tmetricUser, tagName)
74+
workType, err := getWorkTypeByName(config, tmetricUser, tagName)
7575
if err != nil {
7676
return Report{}, err
7777
}
@@ -83,7 +83,7 @@ func GetDetailedReport(clientName string, tagName string, groupName string, star
8383
endDate = endTime.AddDate(0, 0, 1).Format("2006-01-02")
8484

8585
resp, err := request.
86-
SetAuthToken(conf.TmetricToken).
86+
SetAuthToken(config.TmetricToken).
8787
SetQueryParam("AccountId", strconv.Itoa(tmetricUser.ActiveAccountId)).
8888
SetQueryParam("ClientList", strconv.Itoa(client.Id)).
8989
SetQueryParam("GroupList", strconv.Itoa(team.Id)).

0 commit comments

Comments
 (0)