PracowniaProgramowania/backend/views.go

54 lines
1.1 KiB
Go

package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
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 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")
}
func loginUserView() {
//logowanie - czy jest w bazie
fmt.Println("Logowanie użytkownika")
}