From 1f35cad3146d677c7e2bca3862eb4277400ec3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20Liss=C3=A9?= Date: Wed, 3 Apr 2019 11:07:57 +0200 Subject: [PATCH] Change Projects() to return pointers --- mite/api.go | 2 +- mite/project.go | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/mite/api.go b/mite/api.go index 257d4d3..12d5028 100644 --- a/mite/api.go +++ b/mite/api.go @@ -11,7 +11,7 @@ const userAgent = "mite-go/0.1 (+github.com/leanovate/mite-go)" const layout = "2006-01-02" type MiteApi interface { - Projects() ([]Project, error) + Projects() ([]*Project, error) Services() ([]Service, error) TimeEntries(params *TimeEntryParameters) ([]TimeEntry, error) TimeEntry(id string) (*TimeEntry, error) diff --git a/mite/project.go b/mite/project.go index 1983f1e..8a59f8a 100644 --- a/mite/project.go +++ b/mite/project.go @@ -10,22 +10,7 @@ type Project struct { Note string } -func (a *miteApi) Projects() ([]Project, error) { - prs := []ProjectResponse{} - err := a.get("projects.json", &prs) - if err != nil { - return nil, err - } - - projects := []Project{} - for _, pr := range prs { - projects = append(projects, pr.ToProject()) - } - - return projects, nil -} - -type ProjectResponse struct { +type projectResponse struct { Project struct { Id int `json:"id"` Name string `json:"name"` @@ -33,10 +18,25 @@ type ProjectResponse struct { } `json:"project"` } -func (r ProjectResponse) ToProject() Project { - return Project{ +func (r *projectResponse) ToProject() *Project { + return &Project{ Id: fmt.Sprintf("%d", r.Project.Id), Name: r.Project.Name, Note: r.Project.Note, } } + +func (a *miteApi) Projects() ([]*Project, error) { + prs := []projectResponse{} + err := a.get("projects.json", &prs) + if err != nil { + return nil, err + } + + projects := []*Project{} + for _, pr := range prs { + projects = append(projects, pr.ToProject()) + } + + return projects, nil +}