diff options
| author | Teddy Wing | 2017-06-03 12:00:17 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-03 12:00:17 +0200 | 
| commit | bd1a9e85c2ee87017208772b88190b75319874d2 (patch) | |
| tree | 6f76048210cb7b81498adc548081ed502c7ab6b0 | |
| parent | 302fbc3a9db675c24e3ca2cb0c99d1ae5b88180e (diff) | |
| download | timetasker-bd1a9e85c2ee87017208772b88190b75319874d2.tar.bz2 | |
http.go: Restore `SubmitTimeEntries` & `buildSubmissionParams`
Uncomment these functions. Looks like they'll still be useful after all.
Just need a little munging to fit them into the usage of submitting a
single time entry and using our new `Project` and `TimeEntry` types.
| -rw-r--r-- | timetask/http.go | 212 | 
1 files changed, 109 insertions, 103 deletions
| diff --git a/timetask/http.go b/timetask/http.go index 94a1597..4832d00 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -36,106 +36,112 @@ func Login(username, password string) (resp *http.Response, err error) {  	return resp, err  } -// func SubmitTimeEntries(fields Fields, time_entries []TimeEntry) (resp *http.Response, err error) { -// 	v := buildSubmissionParams(fields, time_entries) -// -// 	v.Set("module", "time") -// 	v.Set("action", "submitmultipletime") -// -// 	return nil, nil -// } -// -// func buildSubmissionParams(fields Fields, time_entries []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_entryIndexes", strings.Join(entry_indexes, ",")) -// -// 	return v -// } +func SubmitTimeEntry( +	project Project, +	time_entry TimeEntry, +) (resp *http.Response, err error) { +} + +func SubmitTimeEntries(fields Fields, time_entries []TimeEntry) (resp *http.Response, err error) { +	v := buildSubmissionParams(fields, time_entries) + +	v.Set("module", "time") +	v.Set("action", "submitmultipletime") + +	return nil, nil +} + +func buildSubmissionParams(fields Fields, time_entries []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_entryIndexes", strings.Join(entry_indexes, ",")) + +	return v +} | 
