Pobieranie danych z couchdb wszystkich kart

This commit is contained in:
pawlaczyk 2019-01-13 06:40:16 +01:00
parent 53ec7d5178
commit 8162c48273
4 changed files with 37 additions and 19 deletions

View File

@ -86,11 +86,10 @@ func getJson(url string, target interface{}) error {
return json.NewDecoder(r.Body).Decode(target) return json.NewDecoder(r.Body).Decode(target)
} }
func getAllDoc() { func getAllCards() []Card {
// db := connectCouchdb()
// zmiena := db.AllDocs()
// allCards := []Card{}
//przez zapytanie bardziej optymalne i tak karza robic
//
resp, err := http.Get("http://localhost:5984/golang_cards/_all_docs?include_docs=true") resp, err := http.Get("http://localhost:5984/golang_cards/_all_docs?include_docs=true")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -105,7 +104,7 @@ func getAllDoc() {
keys := reflect.ValueOf(generic).MapKeys() keys := reflect.ValueOf(generic).MapKeys()
fmt.Println("KEYS: ", keys) fmt.Println("KEYS: ", keys)
// allCards := []Card{} allCards := []Card{}
for k, v := range generic { for k, v := range generic {
if k == "rows" { if k == "rows" {
@ -117,25 +116,26 @@ func getAllDoc() {
mResult := v.(map[string]interface{}) mResult := v.(map[string]interface{})
mResult2 := mResult["doc"].(map[string]interface{}) mResult2 := mResult["doc"].(map[string]interface{})
fmt.Println(mResult2["Text"]) // fmt.Println(mResult2["Text"])
fmt.Println(reflect.TypeOf(mResult2["Text"])) // fmt.Println(reflect.TypeOf(mResult2["Text"]))
tmpCard.Text = mResult2["Text"].(string) tmpCard.Text = mResult2["Text"].(string)
fmt.Println(mResult2["Timestamp"]) // fmt.Println(mResult2["Timestamp"])
tmpCard.Timestamp = mResult2["Timestamp"].(float64) tmpCard.Timestamp = mResult2["Timestamp"].(float64)
fmt.Println(mResult2["_id"]) // fmt.Println(mResult2["_id"])
tmpCard.Id = mResult2["_id"].(string) tmpCard.Id = mResult2["_id"].(string)
fmt.Println(mResult2["blank"]) // fmt.Println(mResult2["blank"])
tmpCard.Blank = int(mResult2["blank"].(float64)) tmpCard.Blank = int(mResult2["blank"].(float64))
fmt.Println(mResult2["isquestion"]) // fmt.Println(mResult2["isquestion"])
tmpCard.IsQuestion = mResult2["isquestion"].(bool) tmpCard.IsQuestion = mResult2["isquestion"].(bool)
allCards = append(allCards, tmpCard)
} }
} }
} }
} }
// fmt.Println("Zmienna: ", zmiena) return allCards
} }

View File

@ -61,7 +61,7 @@ func main() {
api.POST("/getAllLoggedUsersView", getAllLoggedUsersView) // [mysql] pobieranie listy zalogowanych uzytkownikow api.POST("/getAllLoggedUsersView", getAllLoggedUsersView) // [mysql] pobieranie listy zalogowanych uzytkownikow
api.POST("/updateLoggedUserView", updateLoggedUserView) //aktualizacja ze uzytkownik zalogowany api.POST("/updateLoggedUserView", updateLoggedUserView) //aktualizacja ze uzytkownik zalogowany
api.POST("/updateLogoutUserView", updateLogoutUserView) //aktualizacja stanu jak uzytkownik sie wyloguje 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 // Start and run the server
router.Run(":3000") router.Run(":3000")

View File

@ -256,7 +256,24 @@ func getGentelman(c *gin.Context) {
//zwraca login aktualnego gentelamana //zwraca login aktualnego gentelamana
} }
func getAllDocView(c *gin.Context) { func getAllCardsView(c *gin.Context) {
fmt.Println("DLA couchdb") fmt.Println("Wszystkie karty z couchdb")
getAllDoc() 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
})
} }

View File

@ -136,7 +136,7 @@ export default {
if (GoReturn){ if (GoReturn){
resolve(GoReturn) resolve(GoReturn)
}else{ }else{
reject(GoReturn) reject("Wylogowanie Go błąd ")
} }
}) })
@ -145,8 +145,9 @@ export default {
myVue.isLogged = false myVue.isLogged = false
}).catch(function(fromReject){ }).catch(function(fromReject){
console.log("No jakis bld przy wylogowaniu") console.log("No jakis bld przy wylogowaniu", fromReject)
}) });
} }
this.isLogged = false this.isLogged = false
this.$router.push('/') this.$router.push('/')