[allUsers] golang zwraca uzytkownikow
This commit is contained in:
parent
118c241402
commit
6c5e9d9223
@ -16,7 +16,7 @@ type cardDocument struct {
|
|||||||
IsQuestion bool `json:"isquestion"`
|
IsQuestion bool `json:"isquestion"`
|
||||||
Blank int `json:"blank"`
|
Blank int `json:"blank"`
|
||||||
Text string `json:"text`
|
Text string `json:"text`
|
||||||
Timestamp int64 `json:"timestamp`
|
Timestamp int64 `json:"timestamp` //na froncie jest
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectCouchdb() couchdb.DatabaseService {
|
func connectCouchdb() couchdb.DatabaseService {
|
||||||
@ -68,8 +68,3 @@ func addNewCard(_isQuestion bool, _blank int, _text string) {
|
|||||||
|
|
||||||
fmt.Printf(result.ID)
|
fmt.Printf(result.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
addNewCard(false, 0, "moj_testowy_text")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -72,11 +72,14 @@ func getAllUsers() []User {
|
|||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(user)
|
||||||
allUsers = append(allUsers, user)
|
allUsers = append(allUsers, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
return allUsers
|
// fmt.Println("All users: ", allUsers)
|
||||||
|
// fmt.Println(reflect.TypeOf(allUsers))
|
||||||
|
|
||||||
|
return allUsers
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkLoginExists(_login string) bool {
|
func checkLoginExists(_login string) bool {
|
||||||
@ -132,20 +135,20 @@ func loginUser(_login string, _password string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
// func main() {
|
||||||
fmt.Println("Go Mysql Tutorial")
|
// fmt.Println("Go Mysql Tutorial")
|
||||||
// db, err := connectMysql()
|
// // db, err := connectMysql()
|
||||||
|
|
||||||
// // db, err := sql.Open("mysql", "root:password@tcp(127.0.0.1:3306)/golang_user")
|
// // // db, err := sql.Open("mysql", "root:password@tcp(127.0.0.1:3306)/golang_user")
|
||||||
// fmt.Println(reflect.TypeOf(db))
|
// // fmt.Println(reflect.TypeOf(db))
|
||||||
// fmt.Println(reflect.TypeOf(err))
|
// // fmt.Println(reflect.TypeOf(err))
|
||||||
|
|
||||||
// addUser("login10", "password", "userDescription", 123)
|
// // addUser("login10", "password", "userDescription", 123)
|
||||||
// allUsers := getAllUsers()
|
// // allUsers := getAllUsers()
|
||||||
// fmt.Println(allUsers)
|
// // fmt.Println(allUsers)
|
||||||
wynik := checkLoginExists("_login")
|
// wynik := checkLoginExists("_login")
|
||||||
fmt.Printf("%v", wynik)
|
// fmt.Printf("%v", wynik)
|
||||||
wynik = loginUser("_login", "_password3")
|
// wynik = loginUser("_login", "_password3")
|
||||||
fmt.Printf("%v", wynik)
|
// fmt.Printf("%v", wynik)
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
@ -6,7 +6,9 @@ package main
|
|||||||
// go get "github.com/gin-gonic/gin"
|
// go get "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/contrib/static"
|
"github.com/gin-gonic/contrib/static"
|
||||||
@ -55,8 +57,9 @@ func main() {
|
|||||||
// /jokes/like/:jokeID - which will capture likes sent to a particular joke
|
// /jokes/like/:jokeID - which will capture likes sent to a particular joke
|
||||||
api.GET("/jokes", JokeHandler)
|
api.GET("/jokes", JokeHandler)
|
||||||
api.POST("/jokes/like/:jokeID", LikeJoke)
|
api.POST("/jokes/like/:jokeID", LikeJoke)
|
||||||
api.POST("/cards", getAllCards)
|
api.GET("/getUsersView", getUsersView) //widok pobrania wszystkich użytkowników
|
||||||
api.GET("/getAllCards", getAllCards)
|
|
||||||
|
// addUser(_login string, _password string, _userDescription string, _points int)
|
||||||
|
|
||||||
// Start and run the server
|
// Start and run the server
|
||||||
router.Run(":3000")
|
router.Run(":3000")
|
||||||
@ -65,6 +68,8 @@ func main() {
|
|||||||
// JokeHandler retrieves a list of available jokes
|
// JokeHandler retrieves a list of available jokes
|
||||||
func JokeHandler(c *gin.Context) {
|
func JokeHandler(c *gin.Context) {
|
||||||
c.Header("Content-Type", "application/json")
|
c.Header("Content-Type", "application/json")
|
||||||
|
fmt.Println(reflect.TypeOf(jokes))
|
||||||
|
|
||||||
c.JSON(http.StatusOK, jokes)
|
c.JSON(http.StatusOK, jokes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,19 +7,39 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getAllCards(c *gin.Context) {
|
// func JokeHandler(c *gin.Context) {
|
||||||
c.Header("Content-Type", "application/json")
|
// c.Header("Content-Type", "application/json")
|
||||||
c.JSON(http.StatusOK, cards)
|
// 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")
|
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")
|
fmt.Println("Rejestracja nowego użytkownika")
|
||||||
}
|
}
|
||||||
|
|
||||||
func loginUser() {
|
func loginUserView() {
|
||||||
|
//logowanie - czy jest w bazie
|
||||||
fmt.Println("Logowanie użytkownika")
|
fmt.Println("Logowanie użytkownika")
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
// import axios from 'axios'
|
||||||
import PouchDB from 'pouchdb'
|
import PouchDB from 'pouchdb'
|
||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
@ -106,7 +106,7 @@ export default {
|
|||||||
//tylko sprawdza liczbe wierszy, bez pobierania dokuemnto - ktore sa prototype tye
|
//tylko sprawdza liczbe wierszy, bez pobierania dokuemnto - ktore sa prototype tye
|
||||||
var promiseRows = new Promise(function(resolve, reject) {
|
var promiseRows = new Promise(function(resolve, reject) {
|
||||||
//tu sie dzieje magia promisow
|
//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;
|
return res.total_rows;
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -127,10 +127,9 @@ export default {
|
|||||||
console.log("Nowe dane")
|
console.log("Nowe dane")
|
||||||
}
|
}
|
||||||
}).catch(function(fromReject){
|
}).catch(function(fromReject){
|
||||||
return "Proszę nie :<"
|
console.log(fromReject)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
Loading…
Reference in New Issue
Block a user