Skip to content

Commit 8fe638d

Browse files
committed
return only the data that we need
Track have extra data we don't really need. Start with a simple data type and add to it as needed.
1 parent 519f429 commit 8fe638d

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func Submit(url string, iter *Iteration) (*Submission, error) {
129129
}
130130

131131
// List available problems for a language
132-
func List(language, host string) (*Track, error) {
132+
func List(language, host string) ([]string, error) {
133133
url := fmt.Sprintf("%s/tracks/%s", host, language)
134134

135135
req, err := http.NewRequest("GET", url, nil)
@@ -150,7 +150,7 @@ func List(language, host string) (*Track, error) {
150150
return nil, err
151151
}
152152

153-
return &payload.Track, nil
153+
return payload.Track.Problems, nil
154154
}
155155

156156
// Unsubmit deletes a submission.

api/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func TestListTrack(t *testing.T) {
2525
}))
2626
defer ts.Close()
2727

28-
track, err := List("ruby", ts.URL)
28+
problems, err := List("ruby", ts.URL)
2929
assert.NoError(t, err)
3030

31-
assert.Equal(t, len(track.Problems), 34)
31+
assert.Equal(t, len(problems), 34)
3232
}

cmd/list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ func List(ctx *cli.Context) {
2828

2929
language := args[0]
3030

31-
track, err := api.List(language, c.XAPI)
31+
problems, err := api.List(language, c.XAPI)
3232
if err != nil {
3333
log.Fatal(err)
3434
}
35-
GenerateOutput(track, os.Stdout)
35+
GenerateOutput(problems, os.Stdout)
3636
}
3737

3838
// Output writes out the list of assignments
39-
func GenerateOutput(t *api.Track, w io.Writer) {
40-
for _, p := range t.Problems {
39+
func GenerateOutput(problems []string, w io.Writer) {
40+
for _, p := range problems {
4141
fmt.Fprintf(w, "%s\n", p)
4242
}
4343
fmt.Fprintf(w, "\n%s\n\n", msgExplainFetch)

cmd/list_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import (
44
"bytes"
55
"testing"
66

7-
"github.com/exercism/cli/api"
87
"github.com/stretchr/testify/assert"
98
)
109

1110
func TestProducesCorrectOutput(t *testing.T) {
1211
b := bytes.Buffer{}
13-
track := api.Track{Problems: []string{"ruby/bob", "ruby/word-count"}}
12+
problems := []string{"ruby/bob", "ruby/word-count"}
1413

15-
GenerateOutput(&track, &b)
14+
GenerateOutput(problems, &b)
1615

1716
expected := "ruby/bob\nruby/word-count\n\n" + msgExplainFetch + "\n\n"
1817
assert.Equal(t, expected, b.String())

0 commit comments

Comments
 (0)