45 lines
664 B
Go
45 lines
664 B
Go
package controllers
|
|
|
|
import (
|
|
"api/globals"
|
|
"api/models"
|
|
"api/services"
|
|
"fmt"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func GetUsers(c *fiber.Ctx) error {
|
|
var users []models.SystemUser
|
|
|
|
globals.DB.Find(&users)
|
|
|
|
return c.JSON(users)
|
|
}
|
|
|
|
func GetGroups(c *fiber.Ctx) error {
|
|
var groups []models.SystemGroup
|
|
|
|
globals.DB.Find(&groups)
|
|
|
|
return c.JSON(groups)
|
|
}
|
|
|
|
func CreateUser(c *fiber.Ctx) error {
|
|
var body map[string]interface{}
|
|
|
|
if err := c.BodyParser(&body); err != nil {
|
|
return fiber.ErrBadRequest
|
|
}
|
|
|
|
email := body["email"].(string)
|
|
|
|
user := services.GetUserByEmail(email)
|
|
|
|
if user.ID == 0 {
|
|
fmt.Println("inexistent user")
|
|
}
|
|
|
|
return c.JSON(user)
|
|
}
|