Skip to content

Commit

Permalink
Change Projects() to return pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 3, 2019
1 parent d8cd0df commit 1f35cad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 18 additions & 18 deletions mite/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ 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"`
Note string `json:"note"`
} `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
}

0 comments on commit 1f35cad

Please sign in to comment.