diff options
author | Teddy Wing | 2017-06-03 12:08:07 +0200 |
---|---|---|
committer | Teddy Wing | 2017-06-03 12:20:41 +0200 |
commit | 810b140b4a29b1159e76b51b90b9be7d22df1c3e (patch) | |
tree | 0fe9c570f3b629d4690e1ee17320a0b7a9d0f1f3 /timetask/http.go | |
parent | bd1a9e85c2ee87017208772b88190b75319874d2 (diff) | |
download | timetasker-810b140b4a29b1159e76b51b90b9be7d22df1c3e.tar.bz2 |
buildSubmissionParams(): Support new `TimeEntry`; Submit single entry
Change the function to use our new `TimeEntry` type, which doesn't
demand asking for IDs as it already has them built in.
Additionally, remove the loop here as we only want to submit a single
time entry at a time.
Add a new `Profile` type that holds onto the user's person_id. Forgot
that existed. We'll have users fill that into their config.toml file.
Diffstat (limited to 'timetask/http.go')
-rw-r--r-- | timetask/http.go | 146 |
1 files changed, 57 insertions, 89 deletions
diff --git a/timetask/http.go b/timetask/http.go index 4832d00..8b90230 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -6,7 +6,7 @@ import ( "net/http" "net/http/cookiejar" "net/url" - // "strconv" + "strconv" // "strings" "golang.org/x/net/publicsuffix" @@ -51,97 +51,65 @@ func SubmitTimeEntries(fields Fields, time_entries []TimeEntry) (resp *http.Resp return nil, nil } -func buildSubmissionParams(fields Fields, time_entries []TimeEntry) url.Values { +func buildSubmissionParams(profile Profile, time_entry TimeEntry) url.Values { v := url.Values{} - entry_indexes := []string{} - - for i, entry := range time_entries { - entry_indexes = append(entry_indexes, strconv.Itoa(i)) - - client, err := fields.ClientByName(entry.Client) - if err != nil { - log.Panic(err) - } - - project, err := client.ProjectByName(entry.Project) - if err != nil { - log.Panic(err) - } - - module, err := project.ModuleByName(entry.Module) - if err != nil { - log.Panic(err) - } - - task, err := project.TaskByName(entry.Task) - if err != nil { - log.Panic(err) - } - - work_type, err := project.WorkTypeByName(entry.WorkType) - if err != nil { - log.Panic(err) - } - - var billable string - if entry.Billable { - billable = "t" - } else { - billable = "f" - } - - v.Set( - fmt.Sprintf("f_personID%d", i), - strconv.Itoa(fields.PersonID), - ) - - v.Set( - fmt.Sprintf("f_clientID%d", i), - strconv.Itoa(client.ID), - ) - - v.Set( - fmt.Sprintf("f_projectID%d", i), - strconv.Itoa(project.ID), - ) - - v.Set( - fmt.Sprintf("f_moduleID%d", i), - strconv.Itoa(module.ID), - ) - - v.Set( - fmt.Sprintf("f_taskID%d", i), - strconv.Itoa(task.ID), - ) - - v.Set( - fmt.Sprintf("f_worktypeID%d", i), - strconv.Itoa(work_type.ID), - ) - - v.Set( - fmt.Sprintf("f_date%d", i), - entry.Date.Format("02/01/06"), // day/month/year - ) - - v.Set( - fmt.Sprintf("f_time%d", i), - strconv.Itoa(entry.Time), - ) - - v.Set( - fmt.Sprintf("f_billable%d", i), - billable, - ) - - v.Set( - fmt.Sprintf("f_description%d", i), - entry.Description, - ) + + v.Set( + "f_personID0", + strconv.Itoa(profile.PersonID), + ) + + v.Set( + "f_clientID0", + strconv.Itoa(time_entry.Client), + ) + + v.Set( + "f_projectID0", + strconv.Itoa(time_entry.Project), + ) + + v.Set( + "f_moduleID0", + strconv.Itoa(time_entry.Module), + ) + + v.Set( + "f_taskID0", + strconv.Itoa(time_entry.Task), + ) + + v.Set( + "f_worktypeID0", + strconv.Itoa(time_entry.WorkType), + ) + + v.Set( + "f_date0", + time_entry.Date.Format("02/01/06"), // day/month/year + ) + + v.Set( + "f_time0", + strconv.Itoa(time_entry.Time), + ) + + var billable string + if time_entry.Billable { + billable = "t" + } else { + billable = "f" } - v.Set("f_entryIndexes", strings.Join(entry_indexes, ",")) + v.Set( + "f_billable0", + billable, + ) + + v.Set( + "f_description0", + time_entry.Description, + ) return v } |