Skip to content

Commit

Permalink
on récupère bien le libellé du tag
Browse files Browse the repository at this point in the history
  • Loading branch information
agallou committed Feb 26, 2023
1 parent 48011e3 commit e5d8729
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions gotoggl/gotoggl.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ type searchTimeEntry struct {
type searchTimeEntryDetail struct {
Start time.Time
Seconds int `json:"seconds"`
}

type TagItem struct {
Id int `json:"id"`
Name string `json:"name"`
}



// Range returns time entries started in a specific time range. Only the first
// 1000 found time entries are returned. There is no pagination.
func (tes *TimeEntriesService) Range(start, end time.Time) ([]TimeEntry, error) {
Expand All @@ -115,6 +121,14 @@ func (tes *TimeEntriesService) Range(start, end time.Time) ([]TimeEntry, error)
fmt.Println(fmt.Sprintf("Default workspace ID found : %d", me.DefaultWorkspaceId))


// on liste tous les ids
allTags := []TagItem{}
errTags := tes.client.GET(fmt.Sprintf("workspaces/%d/tags", me.DefaultWorkspaceId), &allTags)
if errTags != nil {
return nil, fmt.Errorf("Couldn't get tags: %v\n", errTags)
}

// on prépare le body pour récupérer les time entries
aa := searchRequest{
EndDate: end.Format("2006-01-02"),
StartDate: start.Format("2006-01-02"),
Expand All @@ -126,43 +140,46 @@ func (tes *TimeEntriesService) Range(start, end time.Time) ([]TimeEntry, error)

}


// on recherche les time entries
searchTimeEntries := []searchTimeEntry{}
// t0 := start.Format(time.RFC3339)
// t1 := end.Format(time.RFC3339)
path := fmt.Sprintf("workspace/%d/search/time_entries", me.DefaultWorkspaceId)
err := tes.client.POST(path, strings.NewReader(string(s)), &searchTimeEntries)
if err != nil {
return nil, fmt.Errorf("Couldn't get time entries: %v\n", err)
}

//fmt.Printf("%#v", searchTimeEntries)

// on met en forme les timeEntries
timeEntries := []TimeEntry{}

for _, searchTimeEntry := range searchTimeEntries {
te := TimeEntry{}
//fmt.Printf("%#v", searchTimeEntry)


te.Description = searchTimeEntry.Description
te.ProjectId = searchTimeEntry.ProjectId

for _, searchTimeEntryDetail := range searchTimeEntry.TimeEntries {
fmt.Println(fmt.Sprintf("-----------"))



te.Start = searchTimeEntryDetail.Start
fmt.Println(fmt.Sprintf("%ds", searchTimeEntryDetail.Seconds))
d, _ := time.ParseDuration(fmt.Sprintf("%ds", searchTimeEntryDetail.Seconds))
te.Duration = d
}

fmt.Println(fmt.Sprintf("%#v", searchTimeEntry.TagIds))

te.Tags = append(te.Tags, "Développement") //TODO corriger
var tags []string
for _, tagId := range searchTimeEntry.TagIds {
var tagName string
for _, allTag := range allTags {
if (allTag.Id == tagId) {
tagName = allTag.Name
}
}
if (0 == len(tagName)) {
panic(fmt.Sprintf("Name not found for tag id %d", tagId))
}

tags = append(tags, tagName) //TODO corriger
}

te.Tags = tags

timeEntries = append(timeEntries, te)
}
Expand Down

0 comments on commit e5d8729

Please sign in to comment.