Skip to content

Commit

Permalink
Merge pull request #19 from TGoers-FNSB/dev
Browse files Browse the repository at this point in the history
update
  • Loading branch information
TristanGoers authored Oct 12, 2023
2 parents 9cb0afa + cfe6415 commit df4bace
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 90 deletions.
2 changes: 1 addition & 1 deletion folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func QueryFoldersByIds(config Config, params params.QueryFolders, pathId []strin

func CreateFoldersByFolder(config Config, params params.CreateFolders, pathId string) (resp.Folders, error) {
path := fmt.Sprintf("/folders/%s/folders", pathId)
body, err := query.Values(params)
body, err := Values(params)
if err != nil {
log.Println(err)
}
Expand Down
16 changes: 8 additions & 8 deletions parameters/folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ type QueryFolders struct {
}

type CreateFolders struct {
Title string `url:"title"`
Description *string `url:"description,omitempty"`
Shareds *[]string `url:"shareds,omitempty"`
Metadata *[]Metadata `url:"metadata,omitempty"`
CustomFields *[]CustomField `url:"customFields,omitempty"`
CustomColumns *[]string `url:"customColumns,omitempty"`
Project *Project `url:"project,omitempty"`
Fields *[]string `url:"fields,omitempty"`
Title string `url:"title"`
Description string `url:"description,omitempty"`
Shareds []string `url:"shareds,omitempty"`
Metadata []Metadata `url:"metadata,omitempty"`
CustomFields []CustomField `url:"customFields,omitempty"`
CustomColumns []string `url:"customColumns,omitempty"`
Project Project `url:"project,omitempty,struct"`
Fields []string `url:"fields,omitempty"`
}

type CreateFoldersCopy struct {
Expand Down
34 changes: 17 additions & 17 deletions parameters/sharedParamaters.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ type DateOrRange struct {
}

type TaskDates struct {
Type string `url:"type"`
Duration *int `url:"duration,omitempty"`
Start *string `url:"start,omitempty"`
Due *string `url:"due,omitempty"`
WorkOnWeekends *bool `url:"workOnWeekends,omitempty"`
Type string `url:"type"`
Duration int `url:"duration,omitempty"`
Start string `url:"start,omitempty"`
Due string `url:"due,omitempty"`
WorkOnWeekends bool `url:"workOnWeekends,omitempty"`
}

type Metadata struct {
Expand All @@ -33,22 +33,22 @@ type CustomField struct {
}

type EffortAllocation struct {
AllocatedEffort *int `url:"allocatedEffort,omitempty"`
DailyAllocationPercentage *int `url:"dailyAllocationPercentage,omitempty"`
AllocatedEffort int `url:"allocatedEffort,omitempty"`
DailyAllocationPercentage int `url:"dailyAllocationPercentage,omitempty"`
Mode string `url:"mode"`
TotalEffort *int `url:"totalEffort,omitempty"`
TotalEffort int `url:"totalEffort,omitempty"`
}

type Project struct {
OwnerIds *[]string `url:"ownerIds,omitempty"`
Status *string `url:"status,omitempty"`
CustomStatusId *string `url:"customStatusId,omitempty"`
StartDate *string `url:"startDate,omitempty"`
EndDate *string `url:"endDate,omitempty"`
ContractType *string `url:"contractType,omitempty"`
Budget *float64 `url:"budget,omitempty"`
OwnersAdd *[]string `url:"ownersAdd,omitempty"`
OwnersRemove *[]string `url:"ownersRemove,omitempty"`
OwnerIds []string `url:"ownerIds,omitempty"`
Status string `url:"status,omitempty"`
CustomStatusId string `url:"customStatusId,omitempty"`
StartDate string `url:"startDate,omitempty"`
EndDate string `url:"endDate,omitempty"`
ContractType string `url:"contractType,omitempty"`
Budget float64 `url:"budget,omitempty"`
OwnersAdd []string `url:"ownersAdd,omitempty"`
OwnersRemove []string `url:"ownersRemove,omitempty"`
}

type Avatar struct {
Expand Down
38 changes: 19 additions & 19 deletions parameters/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ type QueryTasksFieldsHistory struct {
}

type CreateTasks struct {
Title string `url:"title"`
Description string `url:"description,omitempty"`
Status string `url:"status,omitempty"`
Importance string `url:"importance,omitempty"`
Dates *TaskDates `url:"dates,omitempty"`
Shareds []string `url:"shareds,omitempty,slice"`
Parents []string `url:"parents,omitempty"`
Responsibles []string `url:"responsibles,omitempty"`
ResponsiblePlaceholders []string `url:"resopnsiblePlaceholders,omitempty"`
Followers []string `url:"followers,omitempty"`
Follow bool `url:"follow,omitempty"`
PriorityBefore string `url:"priorityBefore,omitempty"`
PriorityAfter string `url:"priorityAfter,omitempty"`
SuperTasks []string `url:"superTasks,omitempty"`
Metadata *[]Metadata `url:"metadata,omitempty"`
Title string `url:"title"`
Description string `url:"description,omitempty"`
Status string `url:"status,omitempty"`
Importance string `url:"importance,omitempty"`
Dates TaskDates `url:"dates,omitempty,struct"`
Shareds []string `url:"shareds,omitempty,slice"`
Parents []string `url:"parents,omitempty"`
Responsibles []string `url:"responsibles,omitempty"`
ResponsiblePlaceholders []string `url:"resopnsiblePlaceholders,omitempty"`
Followers []string `url:"followers,omitempty"`
Follow bool `url:"follow,omitempty"`
PriorityBefore string `url:"priorityBefore,omitempty"`
PriorityAfter string `url:"priorityAfter,omitempty"`
SuperTasks []string `url:"superTasks,omitempty"`
Metadata []Metadata `url:"metadata,omitempty"`
CustomFields []CustomField `url:"customFields,omitempty,slice+struct"`
CustomStatus string `url:"customStatus,omitempty"`
EffortAllocation *EffortAllocation `url:"effortAllocation,omitempty"`
BillingType string `url:"billingType,omitempty"`
Fields []string `url:"fields,omitempty"`
CustomStatus string `url:"customStatus,omitempty"`
EffortAllocation EffortAllocation `url:"effortAllocation,omitempty"`
BillingType string `url:"billingType,omitempty"`
Fields []string `url:"fields,omitempty"`
}

type ModifyTasks struct {
Expand Down
50 changes: 32 additions & 18 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,11 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error {
}

if sv.Kind() == reflect.Struct {
if err := reflectValue(values, sv, name); err != nil {
return err
if opts.Contains("struct") { //! Here
values.Add(name, valueString(sv, opts, sf))
}
continue
}
// fmt.Println(valueString(sv, opts, sf))

values.Add(name, valueString(sv, opts, sf))
}
Expand Down Expand Up @@ -221,31 +220,23 @@ func valueString(v reflect.Value, opts tagOptions, sf reflect.StructField) strin
return t.Format(time.RFC3339)
}

//! Here
if opts.Contains("slice") {
val := v.Interface().([]string)
newVal := sliceConvert(val)
var inter interface{}
inter = newVal
return fmt.Sprint(inter)
} else if opts.Contains("struct") {
newVal := objectConvert(v)
var inter interface{}
inter = newVal
return fmt.Sprint(inter)
} else if opts.Contains("slice+struct") {
newVal := "["
for i := 0; i < v.Len(); i++ {
newVal += "{"
val := v.Index(i)
for j := 0; j < val.NumField(); j++ {
key := val.Type().Field(j).Name
value := val.FieldByName(key).String()
if val.FieldByName(key).Kind() == reflect.Slice {
value = sliceConvert(val.FieldByName(key).Interface().([]string))
}
// Check if value is empty
_, opts2 := parseTag(val.Type().Field(j).Tag.Get("url"))
if opts2.Contains("omitempty") && isEmptyValue(val.FieldByName(key)) {
continue
}
newVal += `"` + strcase.ToLowerCamel(key) + `":"` + value + `",`
}
newVal = newVal[:len(newVal)-1] + "},"
newVal += objectConvert(val) + ","
}
newVal = newVal[:len(newVal)-1] + "]"
var inter interface{}
Expand All @@ -256,6 +247,7 @@ func valueString(v reflect.Value, opts tagOptions, sf reflect.StructField) strin
return fmt.Sprint(v.Interface())
}

//! Here
func sliceConvert(sl []string) string {
if len(sl) > 0 {
return `["` + strings.Join(sl, `","`) + `"]`
Expand All @@ -264,6 +256,28 @@ func sliceConvert(sl []string) string {
}
}

//! Here
func objectConvert(v reflect.Value) string {
newVal := "{"
val := v
for j := 0; j < val.NumField(); j++ {
key := val.Type().Field(j).Name
var value string // value := fmt.Sprint(val.FieldByName(key).Interface())
if val.FieldByName(key).Kind() == reflect.Slice {
value = sliceConvert(val.FieldByName(key).Interface().([]string))
} else {
value = `"` + fmt.Sprint(val.FieldByName(key).Interface()) + `"`
}
_, opts2 := parseTag(val.Type().Field(j).Tag.Get("url"))
if opts2.Contains("omitempty") && isEmptyValue(val.FieldByName(key)) {
continue
}
newVal += `"` + strcase.ToLowerCamel(key) + `":` + value + `,`
}
newVal = newVal[:len(newVal)-1] + "}"
return newVal
}

// isEmptyValue checks if a value should be considered empty for the purposes
// of omitting fields with the "omitempty" option.
func isEmptyValue(v reflect.Value) bool {
Expand Down
27 changes: 0 additions & 27 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import (
query "github.com/google/go-querystring/query"
)


func Parse(jsonString string) (string) {
test := ""

fmt.Println("Test:", test)

return ""
}

func QueryTasks(config Config, params params.QueryTasks) (resp.Tasks, error) {
path := "/tasks"
body, err := query.Values(params)
Expand All @@ -29,8 +20,6 @@ func QueryTasks(config Config, params params.QueryTasks) (resp.Tasks, error) {
return resp.TasksFromJSON(response)
}

// Working out how to encode slices properly and objects properly

func QueryTasksByFolder(config Config, params params.QueryTasks, pathId string) (resp.Tasks, error) {
path := fmt.Sprintf("/folders/%s/tasks", pathId)
body, err := query.Values(params)
Expand Down Expand Up @@ -74,27 +63,11 @@ func QueryTasksFieldsHistoryByTasks(config Config, params params.QueryTasksField
func CreateTasksByFolder(config Config, params params.CreateTasks, pathId string) (resp.Tasks, error) {
path := fmt.Sprintf("/folders/%s/tasks", pathId)
body, err := Values(params)





if err != nil {
log.Println(err)
}
response, _ := Post(config, path, body)
return resp.TasksFromJSON(response)




// path := fmt.Sprintf("/folders/%s/tasks", pathId)
// body, err := query.Values(params)
// if err != nil {
// log.Println(err)
// }
// response, _ := Post(config, path, body)
// return resp.TasksFromJSON(response)
}
//-----------------------
func ModifyTasksById(config Config, params params.ModifyTasks, pathId string) (resp.Tasks, error) {
Expand Down

0 comments on commit df4bace

Please sign in to comment.