2018-11-20 00:32:55 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2019-01-09 02:29:12 +01:00
|
|
|
func getUsersView(c *gin.Context) {
|
|
|
|
// dodanie nowej karty do bzy
|
2018-11-20 00:32:55 +01:00
|
|
|
fmt.Println("Dodanie do couchDB nowej karty pytania lub odowiedzi")
|
2019-01-09 02:29:12 +01:00
|
|
|
|
|
|
|
var userList []map[string]interface{}
|
|
|
|
|
|
|
|
allUsers := getAllUsers()
|
|
|
|
for _, arg := range allUsers {
|
|
|
|
tmp := make(map[string]interface{})
|
2019-01-09 03:55:36 +01:00
|
|
|
tmp["login"] = arg.Login
|
|
|
|
tmp["userDescription"] = arg.UserDescription
|
|
|
|
tmp["points"] = arg.Points
|
2019-01-09 02:29:12 +01:00
|
|
|
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
|
|
|
|
})
|
2018-11-20 00:32:55 +01:00
|
|
|
}
|
|
|
|
|
2019-01-09 03:55:36 +01:00
|
|
|
func addNewUserView(c *gin.Context) {
|
|
|
|
// Read the Body content
|
|
|
|
var newUser User
|
|
|
|
c.Bind(&newUser)
|
|
|
|
|
|
|
|
fmt.Println(newUser.Login)
|
|
|
|
_login := newUser.Login
|
|
|
|
_password := newUser.Password
|
|
|
|
_userDescription := newUser.UserDescription
|
|
|
|
_points := newUser.Points
|
|
|
|
|
|
|
|
addUser(_login, _password, _userDescription, _points)
|
|
|
|
|
|
|
|
fmt.Println("PUSTE BODY : <")
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, "ala")
|
2018-11-20 00:32:55 +01:00
|
|
|
}
|
|
|
|
|
2019-01-09 02:29:12 +01:00
|
|
|
func loginUserView() {
|
|
|
|
//logowanie - czy jest w bazie
|
2018-11-20 00:32:55 +01:00
|
|
|
fmt.Println("Logowanie użytkownika")
|
|
|
|
}
|