Skip to content

Commit

Permalink
Extract Project model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 8, 2019
1 parent 5e22017 commit e154bbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
7 changes: 7 additions & 0 deletions domain/project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package domain

type Project struct {
Id string
Name string
Note string
}
3 changes: 2 additions & 1 deletion mite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/leanovate/mite-go/domain"
"net/http"
"net/url"
)
Expand All @@ -30,7 +31,7 @@ type TrackerApi interface {
type CustomerApi interface{}

type ProjectApi interface {
Projects() ([]*Project, error)
Projects() ([]*domain.Project, error)
}

type ServiceApi interface {
Expand Down
17 changes: 6 additions & 11 deletions mite/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ package mite

import (
"fmt"
"github.com/leanovate/mite-go/domain"
)

type Project struct {
Id string
Name string
Note string
}

type projectResponse struct {
Project struct {
Id int `json:"id"`
Expand All @@ -18,24 +13,24 @@ type projectResponse struct {
} `json:"project"`
}

func (r *projectResponse) ToProject() *Project {
return &Project{
func (r *projectResponse) toProject() *domain.Project {
return &domain.Project{
Id: fmt.Sprintf("%d", r.Project.Id),
Name: r.Project.Name,
Note: r.Project.Note,
}
}

func (a *api) Projects() ([]*Project, error) {
func (a *api) Projects() ([]*domain.Project, error) {
var prs []projectResponse
err := a.get("projects.json", &prs)
if err != nil {
return nil, err
}

var projects []*Project
var projects []*domain.Project
for _, pr := range prs {
projects = append(projects, pr.ToProject())
projects = append(projects, pr.toProject())
}

return projects, nil
Expand Down

0 comments on commit e154bbb

Please sign in to comment.