Skip to content

Commit

Permalink
Change Services() 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 1f35cad commit 503e07e
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 @@ -12,7 +12,7 @@ const layout = "2006-01-02"

type MiteApi interface {
Projects() ([]*Project, error)
Services() ([]Service, error)
Services() ([]*Service, error)
TimeEntries(params *TimeEntryParameters) ([]TimeEntry, error)
TimeEntry(id string) (*TimeEntry, error)
}
Expand Down
36 changes: 18 additions & 18 deletions mite/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ type Service struct {
Note string
}

func (a *miteApi) Services() ([]Service, error) {
srs := []ServiceResponse{}
err := a.get("services.json", &srs)
if err != nil {
return nil, err
}

services := []Service{}
for _, sr := range srs {
services = append(services, sr.ToService())
}

return services, nil
}

type ServiceResponse struct {
type serviceResponse struct {
Service struct {
Id int `json:"id"`
Name string `json:"name"`
Note string `json:"note"`
} `json:"service"`
}

func (r ServiceResponse) ToService() Service {
return Service{
func (r *serviceResponse) ToService() *Service {
return &Service{
Id: fmt.Sprintf("%d", r.Service.Id),
Name: r.Service.Name,
Note: r.Service.Note,
}
}

func (a *miteApi) Services() ([]*Service, error) {
srs := []serviceResponse{}
err := a.get("services.json", &srs)
if err != nil {
return nil, err
}

services := []*Service{}
for _, sr := range srs {
services = append(services, sr.ToService())
}

return services, nil
}

0 comments on commit 503e07e

Please sign in to comment.