From 53ec7d5178f18871307bb9299fd0665864e236f5 Mon Sep 17 00:00:00 2001 From: pawlaczyk Date: Sun, 13 Jan 2019 06:18:43 +0100 Subject: [PATCH] [couchdb] Pobranie wszystkich danych z dokuemntu --- backend/connector_couchdb.go | 32 +++++++++++++++----------------- backend/models.go | 3 ++- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/backend/connector_couchdb.go b/backend/connector_couchdb.go index 371703b..13dce60 100644 --- a/backend/connector_couchdb.go +++ b/backend/connector_couchdb.go @@ -105,36 +105,34 @@ func getAllDoc() { keys := reflect.ValueOf(generic).MapKeys() fmt.Println("KEYS: ", keys) + // allCards := []Card{} + for k, v := range generic { if k == "rows" { switch val := v.(type) { - // case string: - // fmt.Println(k, "is string", val) - // case int: - // fmt.Println(k, "is int", val) case []interface{}: fmt.Println(k, "is an array") for _, v := range val { - // fmt.Println(v) //, i) - // fmt.Println(reflect.TypeOf(v)) - // fmt.Println(i) + var tmpCard Card + mResult := v.(map[string]interface{}) - // fmt.Println(mResult["doc"]) - // fmt.Println(reflect.TypeOf(mResult["doc"])) - mResult2 := mResult["doc"].(map[string]interface{}) - // fmt.Println(reflect.TypeOf(mResult2)) fmt.Println(mResult2["Text"]) + fmt.Println(reflect.TypeOf(mResult2["Text"])) + tmpCard.Text = mResult2["Text"].(string) fmt.Println(mResult2["Timestamp"]) - fmt.Println(mResult2["_id"]) - fmt.Println(mResult2["blank"]) + tmpCard.Timestamp = mResult2["Timestamp"].(float64) - // mResult2 := mResult.(map[string]interface{}) - // fmt.Println(mResult2["Timestamp"]) + fmt.Println(mResult2["_id"]) + tmpCard.Id = mResult2["_id"].(string) + + fmt.Println(mResult2["blank"]) + tmpCard.Blank = int(mResult2["blank"].(float64)) + + fmt.Println(mResult2["isquestion"]) + tmpCard.IsQuestion = mResult2["isquestion"].(bool) } - // default: - // fmt.Println(k, "is unknown type") } } } diff --git a/backend/models.go b/backend/models.go index 55bde46..f18db9d 100644 --- a/backend/models.go +++ b/backend/models.go @@ -29,8 +29,9 @@ type User struct { */ type Card struct { couchdb.Document - Id int `json:"id" binding:"required"` + Id string `json:"id" binding:"required"` IsQuestion bool `json:"isQuestion"` //0 karta pytanie, 1 karta odpowiedź Blank int `json:"blank" binding:"required"` //ile kart odpowiedzi na pytanie Text string `json:"text" binding:"required"` // podłoga to luka + Timestamp float64 }