diff --git a/backend/connector_couchdb.go b/backend/connector_couchdb.go index 13dce60..a0b7c7a 100644 --- a/backend/connector_couchdb.go +++ b/backend/connector_couchdb.go @@ -86,11 +86,10 @@ func getJson(url string, target interface{}) error { return json.NewDecoder(r.Body).Decode(target) } -func getAllDoc() { - // db := connectCouchdb() - // zmiena := db.AllDocs() - // allCards := []Card{} +func getAllCards() []Card { + //przez zapytanie bardziej optymalne i tak karza robic + // resp, err := http.Get("http://localhost:5984/golang_cards/_all_docs?include_docs=true") if err != nil { log.Fatal(err) @@ -105,7 +104,7 @@ func getAllDoc() { keys := reflect.ValueOf(generic).MapKeys() fmt.Println("KEYS: ", keys) - // allCards := []Card{} + allCards := []Card{} for k, v := range generic { if k == "rows" { @@ -117,25 +116,26 @@ func getAllDoc() { mResult := v.(map[string]interface{}) mResult2 := mResult["doc"].(map[string]interface{}) - fmt.Println(mResult2["Text"]) - fmt.Println(reflect.TypeOf(mResult2["Text"])) + // fmt.Println(mResult2["Text"]) + // fmt.Println(reflect.TypeOf(mResult2["Text"])) tmpCard.Text = mResult2["Text"].(string) - fmt.Println(mResult2["Timestamp"]) + // fmt.Println(mResult2["Timestamp"]) tmpCard.Timestamp = mResult2["Timestamp"].(float64) - fmt.Println(mResult2["_id"]) + // fmt.Println(mResult2["_id"]) tmpCard.Id = mResult2["_id"].(string) - fmt.Println(mResult2["blank"]) + // fmt.Println(mResult2["blank"]) tmpCard.Blank = int(mResult2["blank"].(float64)) - fmt.Println(mResult2["isquestion"]) + // fmt.Println(mResult2["isquestion"]) tmpCard.IsQuestion = mResult2["isquestion"].(bool) + allCards = append(allCards, tmpCard) } } } } - // fmt.Println("Zmienna: ", zmiena) + return allCards } diff --git a/backend/main.go b/backend/main.go index 0bd6f96..c71ac17 100644 --- a/backend/main.go +++ b/backend/main.go @@ -61,7 +61,7 @@ func main() { api.POST("/getAllLoggedUsersView", getAllLoggedUsersView) // [mysql] pobieranie listy zalogowanych uzytkownikow api.POST("/updateLoggedUserView", updateLoggedUserView) //aktualizacja ze uzytkownik zalogowany api.POST("/updateLogoutUserView", updateLogoutUserView) //aktualizacja stanu jak uzytkownik sie wyloguje - api.POST("/getAllDocView", getAllDocView) //pobieranie wszystkich kart z couchd + api.POST("/getAllCardsView", getAllCardsView) //pobieranie wszystkich kart z couchd // Start and run the server router.Run(":3000") diff --git a/backend/views.go b/backend/views.go index 6f4a5c3..a7f4fbe 100644 --- a/backend/views.go +++ b/backend/views.go @@ -256,7 +256,24 @@ func getGentelman(c *gin.Context) { //zwraca login aktualnego gentelamana } -func getAllDocView(c *gin.Context) { - fmt.Println("DLA couchdb") - getAllDoc() +func getAllCardsView(c *gin.Context) { + fmt.Println("Wszystkie karty z couchdb") + var cardList []map[string]interface{} + + allCards := getAllCards() + for _, arg := range allCards { + tmp := make(map[string]interface{}) + tmp["Text"] = arg.Text + tmp["Timestamp"] = arg.Timestamp + tmp["IsQuestion"] = arg.IsQuestion + tmp["Id"] = arg.Id + tmp["Blank"] = arg.Blank + cardList = append(cardList, tmp) + } + + c.JSON(http.StatusOK, gin.H{ + "code": http.StatusOK, + "allCards": cardList, // cast it to string before showing + }) + } diff --git a/frontend/app/src/components/Navbar.vue b/frontend/app/src/components/Navbar.vue index 5d48a34..53b796f 100644 --- a/frontend/app/src/components/Navbar.vue +++ b/frontend/app/src/components/Navbar.vue @@ -136,7 +136,7 @@ export default { if (GoReturn){ resolve(GoReturn) }else{ - reject(GoReturn) + reject("Wylogowanie Go błąd ") } }) @@ -145,8 +145,9 @@ export default { myVue.isLogged = false }).catch(function(fromReject){ - console.log("No jakis bld przy wylogowaniu") - }) + console.log("No jakis bld przy wylogowaniu", fromReject) + }); + } this.isLogged = false this.$router.push('/')