added more stuff
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"acooldomain.co/backend/auth"
|
||||
"acooldomain.co/backend/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
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 []models.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.Use(auth.AuthorizedTo(0)).GET("/", connection.GetUsers)
|
||||
}
|
||||
package users
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"acooldomain.co/backend/auth"
|
||||
"acooldomain.co/backend/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
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 []models.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.Use(auth.AuthorizedTo(0)).GET("/", connection.GetUsers)
|
||||
}
|
||||
|
Reference in New Issue
Block a user