[allUsers] golang zwraca uzytkownikow

This commit is contained in:
pawlaczyk 2019-01-09 02:29:12 +01:00
parent 118c241402
commit 6c5e9d9223
5 changed files with 56 additions and 34 deletions

View File

@ -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")
}

View File

@ -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)
}
// }

View File

@ -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)
}

View File

@ -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)
}
func addNewUser() {
c.Header("Content-Type", "application/json")
c.JSON(http.StatusOK, gin.H{
"code": http.StatusOK,
"allUsers": userList, // cast it to string before showing
})
}
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")
}

View File

@ -54,7 +54,7 @@
</template>
<script>
import axios from 'axios';
// import axios from 'axios'
import PouchDB from 'pouchdb'
export default {
data(){
@ -106,7 +106,7 @@ export default {
//tylko sprawdza liczbe wierszy, bez pobierania dokuemnto - ktore sa prototype tye
var promiseRows = new Promise(function(resolve, reject) {
//tu sie dzieje magia promisow
var rowsCount = db.allDocs({include_docs : true}).then(function (res){
var rowsCount = db.allDocs().then(function (res){
return res.total_rows;
})
@ -127,10 +127,9 @@ export default {
console.log("Nowe dane")
}
}).catch(function(fromReject){
return "Proszę nie :<"
console.log(fromReject)
})
}
},
mounted() {