55 lines
1002 B
Go
55 lines
1002 B
Go
package users
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type Permission int
|
|
|
|
const (
|
|
Start Permission = 1 << iota
|
|
Stop
|
|
Browse
|
|
Create
|
|
Delete
|
|
RunCommand
|
|
Admin
|
|
)
|
|
|
|
type User struct {
|
|
Username string `json:"username"`
|
|
Email string `json:"email"`
|
|
MaxOwnedServers int `json:"maxed_owned_servers"`
|
|
Permissions []string `json:"permissions"`
|
|
}
|
|
|
|
type Connection struct {
|
|
connection *mongo.Client
|
|
}
|
|
|
|
func (con Connection) GetUsers(c *gin.Context) {
|
|
users, err := con.connection.Database("Backend").Collection("Users").Find(context.TODO(), bson.D{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var response []User
|
|
|
|
err = users.All(context.TODO(), &response)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
c.IndentedJSON(http.StatusOK, response)
|
|
}
|
|
|
|
func LoadGroup(group *gin.RouterGroup, client *mongo.Client) {
|
|
connection := Connection{connection: client}
|
|
group.GET("/", connection.GetUsers)
|
|
}
|