Skip to content
This repository has been archived by the owner on Apr 4, 2021. It is now read-only.

Commit

Permalink
配列で返すのやめる
Browse files Browse the repository at this point in the history
  • Loading branch information
syou6162 committed Nov 15, 2018
1 parent 48faaad commit b852884
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"os"
"strings"

"encoding/json"

"sort"

"syscall"
Expand Down Expand Up @@ -138,6 +136,10 @@ func getUrlsFromList(listName string) (example.Examples, error) {
return result, nil
}

type ExamplesFromList struct {
Examples example.Examples
}

func GetExamplesFromList(w http.ResponseWriter, r *http.Request) {
queryValues := r.URL.Query()
listName := queryValues.Get("listName")
Expand All @@ -154,7 +156,10 @@ func GetExamplesFromList(w http.ResponseWriter, r *http.Request) {

examples = util.FilterStatusCodeOkExamples(examples)
lightenExamples(examples)
json.NewEncoder(w).Encode(examples)

JSON(w, http.StatusOK, ExamplesFromList{
Examples: examples,
})
}

type ExampleWithSimilarExamples struct {
Expand Down
6 changes: 3 additions & 3 deletions lib/web/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ func TestGetExamplesFromList(t *testing.T) {
status, http.StatusOK)
}

examples := example.Examples{}
json.Unmarshal(w.Body.Bytes(), &examples)
examplesFromList := web.ExamplesFromList{}
json.Unmarshal(w.Body.Bytes(), &examplesFromList)

if len(examples) == 0 {
if len(examplesFromList.Examples) == 0 {
t.Error("Result must not be empty")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/ListExample.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default {
axios.get("/api/examples?listName=" + listname)
.then(response => {
this.examples = response.data.map(e => NewExample(e));
this.examples = response.data.Examples.map(e => NewExample(e));
this.listname = this.$route.params.listname;
this.title = `ML News - ${this.listname}`;
this.loading = false;
Expand Down

0 comments on commit b852884

Please sign in to comment.