From 6c5e9d9223b6273d1632dac09ffef870801999b1 Mon Sep 17 00:00:00 2001 From: pawlaczyk Date: Wed, 9 Jan 2019 02:29:12 +0100 Subject: [PATCH] [allUsers] golang zwraca uzytkownikow --- backend/connector_couchdb.go | 7 +------ backend/connector_mysql.go | 33 +++++++++++++++++-------------- backend/main.go | 9 +++++++-- backend/views.go | 34 +++++++++++++++++++++++++------- frontend/app/src/views/Cards.vue | 7 +++---- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/backend/connector_couchdb.go b/backend/connector_couchdb.go index a6205c2..6ba66e9 100644 --- a/backend/connector_couchdb.go +++ b/backend/connector_couchdb.go @@ -16,7 +16,7 @@ type cardDocument struct { IsQuestion bool `json:"isquestion"` Blank int `json:"blank"` Text string `json:"text` - Timestamp int64 `json:"timestamp` + Timestamp int64 `json:"timestamp` //na froncie jest } func connectCouchdb() couchdb.DatabaseService { @@ -68,8 +68,3 @@ func addNewCard(_isQuestion bool, _blank int, _text string) { fmt.Printf(result.ID) } - -func main() { - addNewCard(false, 0, "moj_testowy_text") - -} diff --git a/backend/connector_mysql.go b/backend/connector_mysql.go index 148bc0d..0288dd2 100644 --- a/backend/connector_mysql.go +++ b/backend/connector_mysql.go @@ -72,11 +72,14 @@ func getAllUsers() []User { panic(err.Error()) } + fmt.Println(user) allUsers = append(allUsers, user) } - return allUsers + // fmt.Println("All users: ", allUsers) + // fmt.Println(reflect.TypeOf(allUsers)) + return allUsers } func checkLoginExists(_login string) bool { @@ -132,20 +135,20 @@ func loginUser(_login string, _password string) bool { return false } -func main() { - fmt.Println("Go Mysql Tutorial") - // db, err := connectMysql() +// func main() { +// fmt.Println("Go Mysql Tutorial") +// // db, err := connectMysql() - // // db, err := sql.Open("mysql", "root:password@tcp(127.0.0.1:3306)/golang_user") - // fmt.Println(reflect.TypeOf(db)) - // fmt.Println(reflect.TypeOf(err)) +// // // db, err := sql.Open("mysql", "root:password@tcp(127.0.0.1:3306)/golang_user") +// // fmt.Println(reflect.TypeOf(db)) +// // fmt.Println(reflect.TypeOf(err)) - // addUser("login10", "password", "userDescription", 123) - // allUsers := getAllUsers() - // fmt.Println(allUsers) - wynik := checkLoginExists("_login") - fmt.Printf("%v", wynik) - wynik = loginUser("_login", "_password3") - fmt.Printf("%v", wynik) +// // addUser("login10", "password", "userDescription", 123) +// // allUsers := getAllUsers() +// // fmt.Println(allUsers) +// wynik := checkLoginExists("_login") +// fmt.Printf("%v", wynik) +// wynik = loginUser("_login", "_password3") +// fmt.Printf("%v", wynik) -} +// } diff --git a/backend/main.go b/backend/main.go index ea3aef2..ae0c60d 100644 --- a/backend/main.go +++ b/backend/main.go @@ -6,7 +6,9 @@ package main // go get "github.com/gin-gonic/gin" import ( + "fmt" "net/http" + "reflect" "strconv" "github.com/gin-gonic/contrib/static" @@ -55,8 +57,9 @@ func main() { // /jokes/like/:jokeID - which will capture likes sent to a particular joke api.GET("/jokes", JokeHandler) api.POST("/jokes/like/:jokeID", LikeJoke) - api.POST("/cards", getAllCards) - api.GET("/getAllCards", getAllCards) + api.GET("/getUsersView", getUsersView) //widok pobrania wszystkich użytkowników + + // addUser(_login string, _password string, _userDescription string, _points int) // Start and run the server router.Run(":3000") @@ -65,6 +68,8 @@ func main() { // JokeHandler retrieves a list of available jokes func JokeHandler(c *gin.Context) { c.Header("Content-Type", "application/json") + fmt.Println(reflect.TypeOf(jokes)) + c.JSON(http.StatusOK, jokes) } diff --git a/backend/views.go b/backend/views.go index 2b2c86b..dcecef0 100644 --- a/backend/views.go +++ b/backend/views.go @@ -7,19 +7,39 @@ import ( "github.com/gin-gonic/gin" ) -func getAllCards(c *gin.Context) { - c.Header("Content-Type", "application/json") - c.JSON(http.StatusOK, cards) -} +// func JokeHandler(c *gin.Context) { +// c.Header("Content-Type", "application/json") +// c.JSON(http.StatusOK, jokes) +// } -func addNewCard() { +func getUsersView(c *gin.Context) { + // dodanie nowej karty do bzy fmt.Println("Dodanie do couchDB nowej karty pytania lub odowiedzi") + + var userList []map[string]interface{} + + allUsers := getAllUsers() + for _, arg := range allUsers { + tmp := make(map[string]interface{}) + tmp["login"] = arg.login + tmp["userDescription"] = arg.userDescription + tmp["points"] = arg.points + userList = append(userList, tmp) + } + + c.Header("Content-Type", "application/json") + c.JSON(http.StatusOK, gin.H{ + "code": http.StatusOK, + "allUsers": userList, // cast it to string before showing + }) } -func addNewUser() { +func addNewUserView() { + // dodanie nowego użytkownika fmt.Println("Rejestracja nowego użytkownika") } -func loginUser() { +func loginUserView() { + //logowanie - czy jest w bazie fmt.Println("Logowanie użytkownika") } diff --git a/frontend/app/src/views/Cards.vue b/frontend/app/src/views/Cards.vue index ab8ca70..4d19e26 100644 --- a/frontend/app/src/views/Cards.vue +++ b/frontend/app/src/views/Cards.vue @@ -54,7 +54,7 @@