Skip to content

Commit

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

type Service struct {
Id string
Name string
Note string
}
2 changes: 1 addition & 1 deletion mite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ProjectApi interface {
}

type ServiceApi interface {
Services() ([]*Service, error)
Services() ([]*domain.Service, error)
}

type UserApi interface{}
Expand Down
17 changes: 6 additions & 11 deletions mite/service.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 Service struct {
Id string
Name string
Note string
}

type serviceResponse struct {
Service struct {
Id int `json:"id"`
Expand All @@ -18,24 +13,24 @@ type serviceResponse struct {
} `json:"service"`
}

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

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

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

return services, nil
Expand Down

0 comments on commit eb9fda3

Please sign in to comment.